Page 5 of 9

Re: a PHP import script for DayFile and Monthly log files

Posted: Sat 06 Feb 2010 10:34 am
by nitrx
Indeed well I did'nt change the avg temp not yet back anyway stylesheets are not my hobby :mrgreen: I've another question too concerning the text of the winddirections ESE andso-on maybe this is affected to cumulus too so Steve could be involved 8-) Is this changeble in the php script to ONO (Dutch) or do these 'values' depend on Cumulus ?

Re: a PHP import script for DayFile and Monthly log files

Posted: Sat 06 Feb 2010 10:38 am
by daj
anyway stylesheets are not my hobby
i can see that! :o Makes your site difficult to maintain


Cumulus stores the bearing as a figure. I have a formula in the script to change this to cardinal points. You can change these to suit. Look in the line

Code: Select all

$compassp=array('N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW');

Re: a PHP import script for DayFile and Monthly log files

Posted: Sat 06 Feb 2010 10:43 am
by nitrx
daj wrote:Cumulus stores the bearing as a figure. I have a formula in the script to change this to cardinal points. You can change these to suit. Look in the line

Code: Select all

$compassp=array('N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW');
Indeed I see the dayfile.txt doesn't has this text thanks I wil change this to my local language thanks and yes I really have to study the css 15 years ago when I did the most html it wasn't very common to use stylesheets

Re: a PHP import script for DayFile and Monthly log files

Posted: Sat 06 Feb 2010 10:45 am
by daj
The order of these is VERY important so do not change that - just the description of each

Re: a PHP import script for DayFile and Monthly log files

Posted: Sat 06 Feb 2010 10:48 am
by nitrx
daj wrote:The order of these is VERY important so do not change that - just the description of each
I'm aware of that thanks for the warning , anyway it could be fun to use from ABOVE, LEFT :lol:

Re: a PHP import script for DayFile and Monthly log files

Posted: Sat 06 Feb 2010 10:57 am
by nitrx
Text is correctly changed for wind so everybody can chnge this in their local language

Re: a PHP import script for DayFile and Monthly log files

Posted: Sat 06 Feb 2010 12:06 pm
by nitrx
Concernig the wrong values I mentioned before I did find 'the error' I made a mistake by not updating the script in mytoolbox it was pointing to an old scriptfile that was the reaon why wrong values where inserted , going to drink a strong coffee now

Re: a PHP import script for DayFile and Monthly log files

Posted: Tue 09 Feb 2010 5:52 pm
by mcrossley
David

I have modified my script to perform an 'INSERT IGNORE' rather than a 'REPLACE' for the data rows. This just adds any new rows to the table and any that already exist will silently fail. It just seems a more efficent method than reloading the whole table each day.

Any particular reason you used REPLACE?

Mark

Re: a PHP import script for DayFile and Monthly log files

Posted: Tue 09 Feb 2010 6:21 pm
by daj
Hi Mark

I specifically used REPLACE to accommodate potential modifications to the file you are importing. Example, if your edit your dayfile.txt and adjust an error in the rain counter, when you next import it the changed values will appear in the table.

Using INSERT IGNORE means that SQL sees there is already a row with the primary key (date) so just ignores the INSERT command therefore the change in the dayfile will not appear in the database.

Same idea for the Monthly logs. If you change 50 entries in the Monthly log to adjust a rain error (the most common issue!) then you want this applied to your SQL table too and not ignored.


Rather than explaining the need to edit the SQL table as well as your day file I thought this was simpler. I could do other things to handle changes but want to keep the code simple.

Re: a PHP import script for DayFile and Monthly log files

Posted: Tue 09 Feb 2010 7:02 pm
by mcrossley
Fair enough, I thought you'd have a good reason. ;) The phpMyAdmin interface gives me a nice GUI for manipulating the data in the tables and deleting if necessary, I understand that many users may be doing this 'by the numbers' though and the simple approach is probably best.
Mark

Re: a PHP import script for DayFile and Monthly log files

Posted: Sat 13 Feb 2010 3:56 pm
by Hillbilly
This is in and running, thanks very much for producing it David.

Re: a PHP import script for DayFile and Monthly log files

Posted: Thu 11 Mar 2010 12:14 pm
by Rampe
Hi everyone. I've been trying to import dayfile.txt to MySQL, but I seem to have some strange problems. I'm not a total newbie with MySQL and/or PHP, but can't figure this one out (or rather, fix it).
The problem is that all dates in MySQL are 0000-00-00. I have changed the delimeters to match my dayfile.txt but still nothing. I get one line inserted to Dayfile -table, (since logdate is primary, nothing else gets inserted). All the other values are correct.

Here's some lines from the files in question:

importcumulusfile.php:
$field_delimiter=";";
$date_delimiter=".";
$decimal_separator=",";

dayfile.txt:
08.03.10;7,8;225;10:37;-6,6;00:00;3,0;13:28;1031,3;18:52;1044,9;00:03;0,0;00:00;0,0;-1,9;181,7
09.03.10;5,8;315;14:10;-11,7;07:12;4,2;12:47;1033,6;00:01;1037,2;08:45;0,0;00:00;0,0;-2,8;91,4
10.03.10;7,5;315;10:34;-2,5;00:07;7,4;11:55;1028,9;09:56;1033,9;00:00;3,6;10:36;0,3;2,6;153,0

I'm quite sure it has something to do with the dots in date, but I don't know what to modify in .php, since there's already some sort of "comma to dot, and vice versa" -conversions.

Re: a PHP import script for DayFile and Monthly log files

Posted: Thu 11 Mar 2010 12:45 pm
by daj
Hi there

The section you are most interested in within the PHP is

Code: Select all

$datearr = split($date_delimiter,$buf_arr['0']);
$dtimestamp = $datearr[2] ."-" . $datearr[1] . "-" . $datearr[0];
This is splitting up the date it has taken from the file to build the SQL date

It assumes DD/MM/YY in the text file, but you have told it earlier that the delimiter is dot, so DD.MM.YY

It then builds this as an SQL date in the form YY-MM-DD

I assume your MYSQL is therefore expecting the date in a different format. Is it maybe a regional thin on your SQL Server?

Out of curiosity, what country are you in?

Re: a PHP import script for DayFile and Monthly log files

Posted: Thu 11 Mar 2010 1:06 pm
by Rampe
Ah, I almost managed to add it to my profile. I'm from Finland.

The default value in MySQL for LogDate is 0000-00-00. I can manually insert date 2010-03-11, but inserting 10-03-11 works aswell, it just gets automagically reformatted to 2010-03-11.

edit: Also, I found "date format: %Y-%m-%d" from MySQL server variables.
edit2: If I echo the $dtimestamp variable right after the $dtimestamp = $datearr[2] ."-" . $datearr[1] . "-" . $datearr[0]; I get only ---------------------------- done.

Re: a PHP import script for DayFile and Monthly log files

Posted: Thu 11 Mar 2010 2:17 pm
by daj
The good news(!) is that I can replicate the problem -- so now I can hopefully find a fix