Welcome to the Cumulus Support forum.

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Cumulus MX V4 beta test release 4.0.0 (build 4018) - 28 March 2024

Legacy Cumulus 1 release v1.9.4 (build 1099) - 28 November 2014 (a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

a PHP import script for DayFile and Monthly log files

Discussion and support for 3rd-party (non-Sandaysoft) tools for Cumulus
Post Reply
User avatar
nitrx
Posts: 1297
Joined: Sun 13 Dec 2009 1:21 pm
Weather Station: WH1080
Operating System: Windows 10
Location: Apeldoorn The Netherlands
Contact:

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

Post 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 ?
User avatar
daj
Posts: 2041
Joined: Tue 29 Jul 2008 8:00 pm
Weather Station: WH1081
Operating System: Pi & MX
Location: SW Scotland
Contact:

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

Post 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');
David
kippfordweather.uk
Cumulus MX & Raspberry Pi
User avatar
nitrx
Posts: 1297
Joined: Sun 13 Dec 2009 1:21 pm
Weather Station: WH1080
Operating System: Windows 10
Location: Apeldoorn The Netherlands
Contact:

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

Post 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
Last edited by nitrx on Sat 06 Feb 2010 10:45 am, edited 1 time in total.
User avatar
daj
Posts: 2041
Joined: Tue 29 Jul 2008 8:00 pm
Weather Station: WH1081
Operating System: Pi & MX
Location: SW Scotland
Contact:

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

Post by daj »

The order of these is VERY important so do not change that - just the description of each
David
kippfordweather.uk
Cumulus MX & Raspberry Pi
User avatar
nitrx
Posts: 1297
Joined: Sun 13 Dec 2009 1:21 pm
Weather Station: WH1080
Operating System: Windows 10
Location: Apeldoorn The Netherlands
Contact:

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

Post 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:
User avatar
nitrx
Posts: 1297
Joined: Sun 13 Dec 2009 1:21 pm
Weather Station: WH1080
Operating System: Windows 10
Location: Apeldoorn The Netherlands
Contact:

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

Post by nitrx »

Text is correctly changed for wind so everybody can chnge this in their local language
User avatar
nitrx
Posts: 1297
Joined: Sun 13 Dec 2009 1:21 pm
Weather Station: WH1080
Operating System: Windows 10
Location: Apeldoorn The Netherlands
Contact:

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

Post 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
User avatar
mcrossley
Posts: 12694
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

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

Post 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
User avatar
daj
Posts: 2041
Joined: Tue 29 Jul 2008 8:00 pm
Weather Station: WH1081
Operating System: Pi & MX
Location: SW Scotland
Contact:

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

Post 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.
David
kippfordweather.uk
Cumulus MX & Raspberry Pi
User avatar
mcrossley
Posts: 12694
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

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

Post 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
Hillbilly
Posts: 112
Joined: Tue 26 Jan 2010 8:54 am
Weather Station: Davis Vantage Pro2 Plus
Operating System: Vista Home Premium SP2
Location: Mayenne, Pays De La Loire, France
Contact:

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

Post by Hillbilly »

This is in and running, thanks very much for producing it David.
Many thanks
Helen

La Locherie Weather
Rampe
Posts: 16
Joined: Sun 21 Feb 2010 9:53 am
Weather Station: WH1080
Operating System: W7 x64
Location: Finland

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

Post 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.
User avatar
daj
Posts: 2041
Joined: Tue 29 Jul 2008 8:00 pm
Weather Station: WH1081
Operating System: Pi & MX
Location: SW Scotland
Contact:

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

Post 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?
David
kippfordweather.uk
Cumulus MX & Raspberry Pi
Rampe
Posts: 16
Joined: Sun 21 Feb 2010 9:53 am
Weather Station: WH1080
Operating System: W7 x64
Location: Finland

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

Post 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.
User avatar
daj
Posts: 2041
Joined: Tue 29 Jul 2008 8:00 pm
Weather Station: WH1081
Operating System: Pi & MX
Location: SW Scotland
Contact:

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

Post by daj »

The good news(!) is that I can replicate the problem -- so now I can hopefully find a fix
David
kippfordweather.uk
Cumulus MX & Raspberry Pi
Post Reply