Wednesday 19 December 2012

Sometimes, the Bug's in the Data
2012-12-19

I have a strict ritual, first thing every morning.  After making a coffee, I plunk down at the computer, visit Environment Harper Canada, and note the previous day's weather stats into a spreadsheet, for safekeeping.  Then I check the news and get on with my day.  I've been doing that for years, originally for comparative figures while hand-tracking local readings.  Since automating the setup, I've found the data handy in checking on my weather system's accuracy.  And, in the past year or so, it's been invaluable, as EnviroCan has actually lost data from their newfangled setup and may never recover all of it.  If they need help, I have a copy of their data...

Fast-forward to this morning.  I fire up my web browser.  It defaults to a portal page of my own design, complete with summary weather information.  The page is updated and timestamped by the weather system, every five minutes.

This morning, the time read 23:59.  No updates since midnight.

Uh oh.  I log into the server and check on things.  Yes, the weather program's running.  I send it a stop command.  Nothing happens; it's hung.  I kill the process.  A quick check shows nothing overtly wrong with the data folders.  Okay, start it up again, and turn on some debug logging.  It starts up, but disk activity stops after initialization.  I check the input folders for each of the locations tracked by the system; they're brimming with data files from overnight.  So... the system's starting up okay, but it must be choking on input data.  The debug log quickly confirms that it's choking on a particular input file; the second one it tries to process.

I open the file in my text editor.  Nothing out of place here; it even includes the local-sky condition inserted by my recently-mentioned webcam analyzer.  I look at the first file, which had been successfully processed.  The only difference here is that the sky condition hasn't been inserted.  This is expected behaviour when the weather system stops taking inputs.

Okay; could there be something wrong with the sky-condition text?  I take another look at the problem file.

The sky condition includes a timestamp.  I had added that a couple of days ago, as a check to make sure the analyzer was continuing to function.

A little bell went off in the back of my head.  The weather system keeps an indexed list of unique sky conditions it's encountered; these are pointed to in the data records, saving significant storage space.

There's a maximum of 255 entries.  Each timestamped sky condition will be treated as unique.

I fire up the text editor again and take a look at the list for the 'home' location (where the problem is occurring).  Sure enough, it's packed with 254 entries, the last 249 of which are timestamped.

I do a little cleanup on the file and quickly scrub the timestamps from the remaining input files.  It's only the home location that receives input from the webcam analyzer.

Next, I figure up Lazarus and pull up the webcam-analyzer project.  A tiny tweak to the source code has it once again outputting just 'Cloudy' instead of '2012-12-19 @ 09:37: Cloudy'.

I fire up the weather system, and it chugs away for a surprisingly few seconds.  Moments later, everything's up-to-date, and the system's ticking along.

Gremlin smacked; job done.  Back to earning some money.


No comments:

Post a Comment