Working out when to send or not send alerts is quite complex and still being tweaked. It isn't perfect yet.
The Buerau of Meteorology publishes the current height on their website. The only way I have access to the data is to scrape it from their page - that is I automatically download the page, search for the string "Data as Plot" (at the bottom of the table) and then work backwards a certain number of characters to grab the time and the height. This done every 5 minutes and is stored in the database.
Every 3 minutes the FloodWatch page refreshes and looks at the last 5 height reading to get an average height. If the average is lower than the current height the creek is rising, if higher, it is falling. Good so far?
Also stored in the database are some important values to make a decision on how to treat the most recent reading: the height at which to send out alerts (1.00 - this is hopefully before it actually floods), the height at which it is clear (1.40), the maximum height this event and whether and alert has been sent and was it rising or falling.
Here's the logic:
If the creek is rising and reaches the warning level, alerts are sent out and that fact is saved. As the creek continues to rise the system checks "has an alert been sent yet?" if so, it does nothing except update the maximum height for this flood event, if it has increased. It also compares the height to the record height and if it is a new record it updates the height, date and time
Eventually the creek starts to fall. Every time an alert goes out about 150 SMS messages are sent. Since I pay for them I don't want that to happen too often if not needed. So the system first checks "did the level pass the initial alert height? If so, has water gone over the road?" If not, a falling alert isn't sent as the road didn't actually flood.
If it is fallin and has covered the road, the next thing to check is whether a falling alert has been sent. If not, alerts are sent and it stores that fact so they don't go again.
When the whole thing is over, everything is reset to wait for next time.
There are a couple of things I wish I could fix, but need to nut it out.
Picture this: the height passes the alert level but it doesn't cover the road and then falls below the alert level, then it rises again passing the alert level. A 'rising' alert goes out each time without any falling alert (because it didn't cover the road), this can be a bit confusing. Not sure of a way around this...toss me a logic solution if you think you have one.