5,838
edits
m (→DAILY SUMMARY) |
No edit summary |
||
== Displaying daily statistics from a database table ==
=== Schema ===
# The retrieval script needs to have the following defined for it to use (it is suggested that these variables are defined in a separate PHP script that is in a directory that the PHP parser can access, but is not in the part of the web server that is visible to a client):
#* The server host name, or w.x.y.z format Internet Protocol (=IP) address, running your MySQL database
#* The user name used to log-in to your database server
#* The password used to log-in to your database server
#** (It is good practice to have separate authentication for read only access, and for read and update access, alternatively use an additional key variable as David does in his update script described below)
#* The name of the (MySQL or whatever) database with the table
#* The name for the daily summary table
# The retrieval script needs to know the names of the columns it is to read from the database.
#* Database designers talk about the ''schema'' meaning the specification that describes the design of the table.
#* A schema lists the column names together with what type and size of variables they hold.
#* For the daily summary database table, the columns can copy the fields in the [[dayfile.txt|daily summary log file]], and this is what David Jamieson does in his approach [http://sandaysoft.com/forum/viewtopic.php?f=18&t=2367 a PHP script to read the contents of the dayfile.txt] where the columns are generated in the same order as the corresponding fields in the log file, so David's script uses the field numbers to identify the columns by Position (rather than by Column Name).
#* Remember that while the fields in the log appear in the order that statistic was added during Cumulus 1 development, in theory the columns can appear in any order (if all your scripts identify the columns by name rather than position) so columns associated with rain (these are separated in dayfile.txt fields 12, 13, 14, 31, and 32) can appear together, as can those for wind (these are dispersed in dayfile.txt fields 1, 2, 3, 16, 17, 18, and 39).
=== Loading and Updating the database table ===
Obviously if you are using a script that reads statistics from a table, you also need to be running a script that ensures the table is updated at the end of each day, and therefore always up to date.
* Functionality is included in Cumulus MX to do this update, it uses the schema devised by Mark Crossley by default, but Cumulus MX can also handle your own schema; for full details of the functionality see [http://sandaysoft.com/forum/viewtopic.php?f=27&t=12908&start=15#p107639 Cumulus MX Announcements - PLEASE READ THESE!].
* Cumulus 1 users need to use a script to create a database table, populate and update it from the daily summary log file. The most widely used script is an update by Mark Crossley of the script mentioned above by David Jamieson; and it is described in [[ImportCumulusFile|this Wiki article]].
** It is however worth also reading [http://sandaysoft.com/forum/viewtopic.php?f=18&t=2367 a PHP script to read the contents of the dayfile.txt] as that explains the date delimiter, how a Comma Separated Variable file may use other punctuation to separate the fields, how to specify the location of your dayfile.txt log to the script and the reason the key variable is used.
=== Some example Scripts ===
|
edits