ImportCumulusFile: Difference between revisions

From Cumulus Wiki
Jump to navigationJump to search
1,369 bytes added ,  10:43, 14 January 2022
m
→‎Monthly table (2.0): Minor clarification
m (→‎Monthly table (2.0): Minor clarification)
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{AddOnBanner|name=ImportCumulusFile|type=PHP|author=David A Jamieson / Mark Crossley|contact='DAJ' / 'mcrossley' via the forum|updated=05 May 2020|version=4.1}}
{{AddOnBanner|name=ImportCumulusFile|type=PHP|author=David A Jamieson / Mark Crossley|contact='DAJ' / 'mcrossley' via the forum|updated=01 September2020|version=4.3}}


This is a PHP script designed to run on your web server and will import Cumulus log files into a MySQL database table on your server.   
This is a PHP script designed to run on your web server and will import Cumulus log files into a MySQL database table on your server.   
Line 6: Line 6:
This script was originally written for Cumulus 1, and all versions (except 4.x and later) will work with Cumulus 1. Please only use the latest version (currently 4.x) of the script with Cumulus MX.  
This script was originally written for Cumulus 1, and all versions (except 4.x and later) will work with Cumulus 1. Please only use the latest version (currently 4.x) of the script with Cumulus MX.  


Please be aware that for Cumulus MX the daily and monthly tables in the database can also be updated with rows for past dates by using ExportMySQL.exe. For information on how Cumulus MX updates the database tables ''without using the script on this page'' please [[Cumulus_MX#MySQL_settings|see here]].
Please be aware that '''for Cumulus MX the daily and monthly tables in the database can also be updated with rows for past dates by using ExportMySQL.exe'''. For information on how Cumulus MX updates the database tables using that instead of ''the script on this page'' please see [[MX_Administrative_Interface#MySQL_settings|the admin interface article]].


=Requirements=
=Requirements=
Line 81: Line 81:
'HighUV',        'decimal(3,1)'
'HighUV',        'decimal(3,1)'
'THighUV',        'varchar(5)'
'THighUV',        'varchar(5)'
'HWindGBearSym',  'varchar(3)'
'DomWindDirSym',  'varchar(3)'
'MaxFeelsLike',  'decimal(4,1)'  /* New in v4.0 */
'MaxFeelsLike',  'decimal(4,1)'  /* New in v4.0 */
'TMaxFeelsLike',  'varchar(5)'    /* New in v4.0 */
'TMaxFeelsLike',  'varchar(5)'    /* New in v4.0 */
'MinFeelsLike',  'decimal(4,1)'  /* New in v4.0 */
'MinFeelsLike',  'decimal(4,1)'  /* New in v4.0 */
'TMinFeelsLike',  'varchar(5)'    /* New in v4.0 */
'TMinFeelsLike',  'varchar(5)'    /* New in v4.0 */
'MaxHumidex',    'decimal(5,1)'  /* New in v4.2 */
'TMaxHumidex',    'varchar(5)'    /* New in v4.2 */
'HWindGBearSym',  'varchar(3)'
'DomWindDirSym',  'varchar(3)'
</pre>
</pre>


Line 120: Line 122:
'RG11rain',          'decimal(4,1)'
'RG11rain',          'decimal(4,1)'
'RainSinceMidnight',  'decimal(4,1)'
'RainSinceMidnight',  'decimal(4,1)'
'FeelsLike',          'decimal(4,1)'  /* New in 4.0 */
'Humidex',            'decimal(4,1)'  /* New in 4.2 */
'WindbearingSym',    'varchar(3)'
'WindbearingSym',    'varchar(3)'
'CurrWindBearingSym', 'varchar(3)'
'CurrWindBearingSym', 'varchar(3)'
'FeelsLike',          'decimal(4,1)'  /* New in 4.0 */
</pre>
</pre>


Line 188: Line 191:




=IMPORTANT NOTE FOR VERSION 2.0+=
= IMPORTANT NOTE FOR VERSION 2.x and 3.x =


Designed for Cumulus 1.
Designed for Cumulus 1.
Line 256: Line 259:
</pre>
</pre>


== Monthly table (old) ==
== Monthly table (2.0 version) ==
For versions below 2.0, the first column as shown below did not exist, instead there was one column for date and one column for time.
For versions below 2.0, the first combined column as shown with both date and time did not exist, instead there was one column for date and one column for time.


As for the MX version as pointed out by Water01 in the support forum, the RG-11 field in the code and in the schema below is wrong, it should have 2 decimal places for those using inches like the other rainfall fields.
As pointed out by Water01 in the support forum, the RG-11 field in the code and in the schema below is wrong, it should have 2 decimal places for those using inches like the other rainfall fields.


<pre>
<pre>
Line 355: Line 358:
=Installation=
=Installation=


*Download the PHP script ... [https://cumuluswiki.org/files/ImportCumulusFile_v4-1.txt (right click, Save as)] and then rename the .txt to .php
*Download the PHP script ... there are download links beside each version in the version history below.
*Save the file and edit it using a text editor --  there are five entries to be edited
*Edit the downloaded file using a text editor --  there are five entries to be edited
:servername, username, password, database and security key
:servername, username, password, database and security key
:these are documented in the file at the top.
:these are documented in the file at the top.
Line 363: Line 366:
:if your decimal separator is a comma this also needs to be changed in the file using the $decimal_separator variable
:if your decimal separator is a comma this also needs to be changed in the file using the $decimal_separator variable


*save the file as ImportCumulusFile.<b>php</b> or whatever name you prefer and upload it to your webserver.
*save the file as ImportCumulusFile.<b>php</b> (or whatever name you prefer) and upload it to your web server which is where it should be run.
*you will also need to upload any files it reads to your web server.


=Using the script=
=Using the script=
Line 408: Line 412:
   php importcumulusfilev2-0.php file=realtime.txt type=realtime key=secretKey retainVal=7 retainUnit=day
   php importcumulusfilev2-0.php file=realtime.txt type=realtime key=secretKey retainVal=7 retainUnit=day
This allows you to run the script as cron job on a Linux server, or as a scheduled task on a Windows server.
This allows you to run the script as cron job on a Linux server, or as a scheduled task on a Windows server.
Version 4.3 of the script allows you to automate the generation of the monthly log file name rather than passing it as a variable.
You need to edit the following entries to enable this feature...
  $auto_month = false;            // True: generate from date, false: read from params
  $month_file_dir= './data/';  // Directory where monthly log file is stored


= Version Control =
= Version Control =
*4.1 - 5 May 2020 [[https://cumuluswiki.org/files/ImportCumulusFile_v4-1.txt Download]]
Latest MX download:
*4.3 - 1 September 2020 [https://cumuluswiki.org/files/ImportCumulusFile_v4-3.txt Download]
** Steinar Utne: If monthly and $auto_month=true then construct filename from date (i.e. <dir>MonYYlog.txt) rather than read from parameters
 
Earlier MX Downloads:
*4.2 - 18 August 2020 [https://cumuluswiki.org/files/ImportCumulusFile_v4-2.txt Download]
** Steinar Utne: Added Humidex in dayfile and monthly
*4.1 - 5 May 2020   [https://cumuluswiki.org/files/ImportCumulusFile_v4-1.txt (Download, right click, Save as)]
**Fix for files that do not have the required number of fields
**Fix for files that do not have the required number of fields
*4.0 - 4 May 2020  Download removed
*4.0 - 4 May 2020  Download removed
Line 423: Line 439:
**SQL injection protection improved - requires the table names to be defined in this script
**SQL injection protection improved - requires the table names to be defined in this script
*2.8 - 27 April 2015 [[https://cumuluswiki.org/files/ImportCumulusFile_v2-8.txt Download]]
*2.8 - 27 April 2015 [[https://cumuluswiki.org/files/ImportCumulusFile_v2-8.txt Download]]
**Added addtional configuration parameter $rainUnit, default is 'mm'
**Added additional configuration parameter $rainUnit, default is 'mm'
**Added 'rain since midnight' to the monthly log file table
**Added 'rain since midnight' to the monthly log file table
**This version is REQUIRED to support CumulusMX direct inserts
**This version is REQUIRED to support CumulusMX direct inserts
Line 429: Line 445:
**To updated existing monthly tables use the following SQL command [if you use 'mm' for rain change (4,2) to (4,1)]:
**To updated existing monthly tables use the following SQL command [if you use 'mm' for rain change (4,2) to (4,1)]:
***ALTER TABLE <<YOUR_MONTHLY_TABLENAME>> ADD COLUMN RainSinceMidnight DECIMAL(4,2) NULL AFTER RG11rain;
***ALTER TABLE <<YOUR_MONTHLY_TABLENAME>> ADD COLUMN RainSinceMidnight DECIMAL(4,2) NULL AFTER RG11rain;
Legacy Cumulus 1 downloads:
*2.7 - 23 February 2015 [[https://cumuluswiki.org/files/ImportCumulusFile_v2-7.txt Download]]
*2.7 - 23 February 2015 [[https://cumuluswiki.org/files/ImportCumulusFile_v2-7.txt Download]]
**Fixed realtime/monthly/day tables creates, to make rainfall 2dp to allow for inches
**Fixed real-time/monthly/day tables creates, to make rainfall 2dp to allow for inches
**Fixed monthly table create, to make evapotrans 2 dp
**Fixed monthly table create, to make evapotrans 2 dp as it uses same units as rainfall
**Converted from depreciated mysql to mysqli
**Converted from depreciated mysql to mysqli
*2.6 - 02 April 2014, Mark Crossley [[https://cumuluswiki.org/files/ImportCumulusFile_v2-6.txt Download]]
*2.6 - 02 April 2014, Mark Crossley [[https://cumuluswiki.org/files/ImportCumulusFile_v2-6.txt Download]]
Line 439: Line 457:
***To alter an existing table...
***To alter an existing table...
***ALTER TABLE `dayfile` CHANGE `HighSolarRad` `HighSolarRad` DECIMAL(5,1) NULL DEFAULT NULL
***ALTER TABLE `dayfile` CHANGE `HighSolarRad` `HighSolarRad` DECIMAL(5,1) NULL DEFAULT NULL
*2.4 - 23 October 2013, Mark crossley [[https://cumuluswiki.org/files/ImportCumulusFile_v2-4.txt Download]]
*2.4 - 23 October 2013, Mark Crossley [[https://cumuluswiki.org/files/ImportCumulusFile_v2-4.txt Download]]
**Changed day file humidity fields from varchar(3) to decimal(4,1)
**Changed day file humidity fields from varchar(3) to decimal(4,1)
*2.3 - 05 June 2013, Mark Crossley [[https://cumuluswiki.org/files/ImportCumulusFile_v2-3.txt Download]]
*2.3 - 05 June 2013, Mark Crossley [[https://cumuluswiki.org/files/ImportCumulusFile_v2-3.txt Download]]
Line 449: Line 467:
*2.0 - 13 March 2013, Mark Crossley [[https://cumuluswiki.org/files/ImportCumulusFile_v2-0.txt Download]]
*2.0 - 13 March 2013, Mark Crossley [[https://cumuluswiki.org/files/ImportCumulusFile_v2-0.txt Download]]
**Change monthly and realtime tables to use combined date/time columns rather than separate
**Change monthly and realtime tables to use combined date/time columns rather than separate
**Added optional retention time for realtime table. Records older than the specified age will be deleted. retainVal=NNN retainUnit=XXXX
**Added optional retention time for realtime table. Records older than the specified age will be deleted. The query-string parameters are '''retainVal=NNN retainUnit=XXXX'''
**Added checking to allow running of the script from a command line as well as via http
**Added checking to allow running of the script from a command line as well as via http
**Added 'extra' columns to record wind directions as compass points where they are only provided as bearings:
**Added 'extra' columns to record wind directions as compass points where they are only provided as bearings:
Line 460: Line 478:
*1.3 - 27 Nov 2012, Mark Crossley, updated for Cumulus b1050 [[https://cumuluswiki.org/files/ImportCumulusFile_v1-3.txt Download]]
*1.3 - 27 Nov 2012, Mark Crossley, updated for Cumulus b1050 [[https://cumuluswiki.org/files/ImportCumulusFile_v1-3.txt Download]]
*1.2 - 6 May 2011, Mark Crossley, updated for Cumulus 1.9.1  
*1.2 - 6 May 2011, Mark Crossley, updated for Cumulus 1.9.1  
*1.1c Small modification to code to handle date delimiter with a dot [[http://wiki.sandsoft.com/files/ImportCumulusFile_v1-1c.txt Download]]
*1.1c - 11 Mar 2010,David A Jamieson, Small modification to code to handle date delimiter with a dot [[http://wiki.sandsoft.com/files/ImportCumulusFile_v1-1c.txt Download]]
*1.1b Added a variable to consider decimal separator  
*1.1b - 04 Feb 2010, David A Jamieson, Added a variable to consider decimal separator  
*1.1a Added date delimiter  
*1.1a - David A Jamieson, Added date delimiter  
*1.1 Added the facility to identify the delimiter used on the import file  
*1.1 - David A Jamieson, Added the facility to identify the delimiter used on the import file  
*1.0 First Release
*1.0 - David A Jamieson, First Release, see top of page for details


[[Category:WebTools]] [[Category:User Contributions]]
[[Category:WebTools]] [[Category:User Contributions]]
5,838

edits

Navigation menu