Cookie Notice

As far as I know, and as far as I remember, nothing in this page does anything with Cookies.

2009/12/15

A MySQL Bug? A Programmer Bug?



I have been trying to teach myself data analysis. I have been keeping some weather data in a MySQL database so I can take it out, munge it and graph it. The above example is done with the Perl module Chart::Clicker, which I am sure will take a large role in my current job. Especially if it works fast and graphs correctly.

On that topic, take a look at it. The red line represents the day's highs, the green line, the day's lows, and the purlple line the day's average temperature. Here's the code that determines what the numbers should be.

my $sql ;
$sql .= 'SELECT ' .
'cast( avg( temp_f ) as unsigned ) , ' .
'min(temp_f) , ' .
'max(temp_f) , ' .
'DATE(time) ' .
'from weather_data where zip = "47909" ' .
'and DATEDIFF( CURDATE() , DATE(time) ) < 7 ' .
'group by DATE(time)' ;

And here's the schema for this code.

CREATE TABLE weather_data (
id int(10) not null auto_increment primary key ,
time TIMESTAMP not null ,
zip varchar(5) ,
city varchar(255) ,
temp_c varchar(255) ,
temp_f varchar(255) ,
humidity varchar(255) ,
wind varchar(255) ,
conditions varchar(255)
) ;

I'll admit that it's pretty lazy. If the current conditions stretches beyond 20 characters, that's some complex weather. The main problem, I believe, is that temperature data is being saved as a string rather than a signed integer. Why it mostly shows up as error on that one day, I don't know. Here's all the temperature data for that day. (Thank you, Google Weather API.)
timetemp_ftemp_c
2009-12-10 00:00:0228-2
2009-12-10 00:10:0228-2
2009-12-10 00:30:0328-2
2009-12-10 00:40:0228-2
2009-12-10 00:50:0228-2
2009-12-10 01:00:0228-2
2009-12-10 01:10:0228-2
2009-12-10 01:30:0216-9
2009-12-10 01:40:0216-9
2009-12-10 02:00:0316-9
2009-12-10 02:10:0216-9
2009-12-10 02:20:0216-9
2009-12-10 02:40:0214-10
2009-12-10 02:50:0215-9
2009-12-10 03:00:0215-9
2009-12-10 03:10:0215-9
2009-12-10 03:20:0215-9
2009-12-10 03:30:0314-10
2009-12-10 03:40:0114-10
2009-12-10 03:50:0115-9
2009-12-10 04:00:0315-9
2009-12-10 04:10:0214-10
2009-12-10 04:20:0214-10
2009-12-10 04:30:0212-11
2009-12-10 04:40:0212-11
2009-12-10 05:00:0213-11
2009-12-10 05:10:0212-11
2009-12-10 05:20:0212-11
2009-12-10 05:30:0312-11
2009-12-10 05:40:0212-11
2009-12-10 05:50:0212-11
2009-12-10 06:00:0312-11
2009-12-10 06:10:0211-12
2009-12-10 06:20:0211-12
2009-12-10 06:30:0211-12
2009-12-10 06:40:0111-12
2009-12-10 07:00:0311-12
2009-12-10 07:10:0210-12
2009-12-10 07:20:0210-12
2009-12-10 07:30:0210-12
2009-12-10 07:40:0410-12
2009-12-10 07:50:0210-12
2009-12-10 08:00:099-13
2009-12-10 08:10:059-13
2009-12-10 08:20:069-13
2009-12-10 08:30:059-13
2009-12-10 08:40:069-13
2009-12-10 08:50:059-13
2009-12-10 09:00:068-13
2009-12-10 09:10:088-13
2009-12-10 09:20:088-13
2009-12-10 09:30:088-13
2009-12-10 09:40:138-13
2009-12-10 09:50:079-13
2009-12-10 10:00:0710-12
2009-12-10 10:10:0710-12
2009-12-10 10:30:0710-12
2009-12-10 10:40:1010-12
2009-12-10 10:50:0712-11
2009-12-10 11:00:0712-11
2009-12-10 11:10:0512-11
2009-12-10 11:20:0812-11
2009-12-10 11:40:0812-11
2009-12-10 12:00:0914-10
2009-12-10 12:30:0714-10
2009-12-10 12:50:0714-10
2009-12-10 13:00:0914-10
2009-12-10 13:10:0615-9
2009-12-10 13:20:0815-9
2009-12-10 13:30:0615-9
2009-12-10 13:50:0717-8
2009-12-10 14:00:0917-8
2009-12-10 14:10:0717-8
2009-12-10 14:20:0817-8
2009-12-10 14:40:0918-8
2009-12-10 14:50:0817-8
2009-12-10 15:20:0818-8
2009-12-10 15:30:1518-8
2009-12-10 15:40:0818-8
2009-12-10 15:50:1119-7
2009-12-10 16:00:1119-7
2009-12-10 16:10:0819-7
2009-12-10 16:20:0819-7
2009-12-10 16:30:0719-7
2009-12-10 16:40:1019-7
2009-12-10 16:50:0819-7
2009-12-10 17:00:0319-7
2009-12-10 17:10:0319-7
2009-12-10 17:30:0219-7
2009-12-10 17:40:0218-8
2009-12-10 17:50:0218-8
2009-12-10 18:00:0218-8
2009-12-10 18:10:0217-8
2009-12-10 18:20:0217-8
2009-12-10 18:30:0217-8
2009-12-10 18:40:0216-9
2009-12-10 18:50:0116-9
2009-12-10 19:00:0217-8
2009-12-10 19:10:0217-8
2009-12-10 19:20:0217-8
2009-12-10 19:40:0217-8
2009-12-10 19:50:0217-8
2009-12-10 20:00:0217-8
2009-12-10 20:20:0217-8
2009-12-10 20:30:0217-8
2009-12-10 20:40:0217-8
2009-12-10 21:00:0317-8
2009-12-10 21:10:0117-8
2009-12-10 21:20:0218-8
2009-12-10 21:30:0218-8
2009-12-10 21:40:0218-8
2009-12-10 22:00:0217-8
2009-12-10 22:10:0217-8
2009-12-10 22:20:0218-8
2009-12-10 22:30:0218-8
2009-12-10 22:40:0218-8
2009-12-10 22:50:0118-8
2009-12-10 23:00:0218-8
2009-12-10 23:10:0118-8
2009-12-10 23:20:0218-8
2009-12-10 23:30:0218-8
2009-12-10 23:40:0218-8
2009-12-10 23:50:0218-8

I could show you the temp_c graph, but that's just beyond the pale wrong, which makes sense as the temperature has been bouncing between positive and negative the whole time.

Ultimately, I got used to Perl's ability to effortlessly bounce between strings and numbers, and here I'm bitten. I can only use that data in a meaningful way if I pull it all and manipulate it in Perl, which cuts off some labor-saving tools. Let that be a lesson to you, and to me.

No comments:

Post a Comment