Weather Diary: Difference between revisions

From Cumulus Wiki
Jump to navigationJump to search
4,324 bytes added ,  10:17, 10 August 2020
m
(5 intermediate revisions by the same user not shown)
Line 14: Line 14:


This file can be opened as a text file, but there are database file readers that can open this sort of file and display them in a spreadsheet like format (or even convert them to formats like CSV).  It is possible to upload this file, or a transformed version of it, onto your webspace and write coding to display the contents, see [https://cumulus.hosiene.co.uk/viewtopic.php?p=83883#p83883 Cumulus Weather Diary].
This file can be opened as a text file, but there are database file readers that can open this sort of file and display them in a spreadsheet like format (or even convert them to formats like CSV).  It is possible to upload this file, or a transformed version of it, onto your webspace and write coding to display the contents, see [https://cumulus.hosiene.co.uk/viewtopic.php?p=83883#p83883 Cumulus Weather Diary].
==How to view the contents on a web page==
The php script included in [[File:Cumulus 1 Weather Diary PHP reader.zip]] will read the Cumulus 1 weather diary and output it to a web page.  Although that script is not in English, it is possible to translate the text, and it is possible to modify the script in various ways. For example, in one modification I made it combine the multiple entries possible for one day into a single "worst case" output and in another modification I supply it with a date and it only outputs records for that date as shown below:
<pre>$fh = fopen($snowDiary, 'r');
if ($fh == FALSE)
{
echo 'ERROR - cannot access weather diary';
}else{
if($debug) echo 'Success, database ' . $snowDiary . ' is open' . PHP_EOL;
$data = fread($fh, filesize($snowDiary));
fclose($fh);
$converted = iconv("Windows-1250", "UTF-8//IGNORE", $data);
$xml = simplexml_load_string($converted);
$dayArray = array();
$oldKey = '';
foreach ($xml->xpath('//ROW') as $item)
{
$key = substr($item['EntryDate'],0,4) . '-' . substr($item['EntryDate'],4,2) . '-' . substr($item['EntryDate'],6,2);
if($key > $rowMetDayStamp) break;
$falling = $item['SnowFalling'] == 'TRUE' ? 1 : 0;
$lying = $item['SnowLying'] == 'TRUE' ? 1 : 0;
$depth = $item['SnowDepth'];
if($key == $oldKey)  // update to another record for same day, retain worse boolean for falling and lying
{
$falling = $oldFalling == 1 ? 1 : $falling;
$lying = $oldLying == 1 ? 1 : $lying;
$depth = ($depth - $oldDepth) > 0 ? $depth  : $oldDepth;
}
$Entry = $item['Entry'];
// novel to SPAWS
$oldFalling = $falling;
$oldLying = $lying;
$oldDepth = $depth;
$oldKey = $key;
} // end of loop through XML records
if($key == $rowMetDayStamp)
{
$snowKnown = true;
if ($debug)
{
echo ' ----- Found entry in weather diary for ' . $englishProcessingDate . $lf;
}
goto snowDone;
}
if($debug) echo ' ----- NO entry in Cumulus 1 weather diary for ' . $englishProcessingDate . $lf . '============================' . $lf;
$snowKnown = false;
$Entry = Null; // Other variables were previously set to values appropriate for the lowest temperature
goto snowDone;
}// end snow diary file processing</pre>


==How to edit the contents==
==How to edit the contents==
Line 34: Line 84:
For any more information you need to read the [[Log.xml|Log.xml file]] and process that as indicated on referenced page.
For any more information you need to read the [[Log.xml|Log.xml file]] and process that as indicated on referenced page.


= Cumulus MX implementation =
= Cumulus 1 and MX diary differences =


There are a number of differences between the Cumulus 1 and MX implemenations. Please read more at [https://cumulus.hosiene.co.uk/viewtopic.php?f=36&t=17919&p=139854&hilit=weather+diary#p139854 Weather Diary (C1 and MX Differences)]
There are a number of differences between the Cumulus 1 and MX implemenations. Please read more at [https://cumulus.hosiene.co.uk/viewtopic.php?f=36&t=17919&p=139854&hilit=weather+diary#p139854 Weather Diary (C1 and MX Differences)]
=MX weather diary =
The MX weather diary is stored in a table called '''DiaryData''' in a SQLite3 database in a file called [[diary.db]].


== How to edit the MX Weather Diary ==
== How to edit the MX Weather Diary ==
=== Using the admin interface ===


#Under the '''Edit''' tab, select '''Weather Diary''' and a calendar based selector appears.
#Under the '''Edit''' tab, select '''Weather Diary''' and a calendar based selector appears.
#Click on required date, enter any Comment, tick the boxes for falling, and lying.
#Click on required date, enter any Comment (stored as "Entry" in the database), tick the boxes for falling, and lying.
#Use the spin selector or type in a snow depth. This field takes decimals (it is labelled as "cm", although you could select a different unit and ignore units shown!).
#Use the spin selector or type in a snow depth. This field takes decimals (it is labelled as "cm", although you could select a different unit and ignore units shown!).
=== Accessing outside MX ===
The weather diary is stored in [[diary.db|a sqLite database]] and that can be easily accessed by any ODBC software e.g. Libre Office. It can also be accessed using PDO instructions in PHP Hypertext Preprocessor.
Here is an example in a PHP 7.3 (there are changes for PHP 7.4) script (modification of script available in [[File:Snow diary.zip]]) of accessing any one day ($rowMetDayStamp in yyyy-mm-dd format):
<pre>$diary = 'sqlite:' . $snowDiary; // Parameter to identify a SQLite database puts a prefix in front of file path
$dbhandle = new PDO($diary);  // connect to db
if($dbhandle === false)
{
$liteError = sqlite_last_error ($dbhandle );
echo ' Error: ' . sqlite_error_string ($liteError);
}else{
if($debug) echo $lf . '============================' . $lf . 'Success, database ' . $diary . ' is open' . $lf;
$queryRead =  "SELECT ALL *  FROM " . "'DiaryData'";
$statement = $dbhandle -> query($queryRead);
if($statement === false)
{
$liteError = sqlite_last_error ($dbhandle );
echo ' Error: ' . sqlite_error_string ($liteError);
}else{
$jump = false;
foreach ($statement as $row)
{
foreach($row as $key => $value )
{
if($key == 'Timestamp')
{
$keyDate = substr($value, 0, 10);
}
if($keyDate != $rowMetDayStamp) break;
if($key == 'snowFalling') $falling = $value;
if($key == 'snowLying') $lying = $value;
if($key == 'snowDepth') $depth = $value;
if($key == 'entry') $Entry = $value;
$jump = true;
        }
        if($jump)
{
$snowKnown = true;
goto snowDone;
}
}
}
}
</pre>


== Web tags available for your web site ==
== Web tags available for your web site ==
Line 73: Line 175:
==Displaying on a customised web page==
==Displaying on a customised web page==


If you understand HTML table syntax, the [[Webtag]] ''<#snowdepth>'' can be inserted on a ( for example the ''todayT.htm'') web template (see [[Customised templates]]) to display the snow depth (updating at time set in [[Cumulus.ini]] as explained above. If you understand JavaScript and HTML, you can arrange to upload a background with a scale on which the script can use ''<#snowdepth>'' to overlay the correct depth as a white blanket for example.  The script would have similarities to the current part of the script provided with Cumulus that plots rainfall as a bar chart.
If you understand HTML table syntax, the [[Webtag]] ''<#snowdepth>'' can be inserted on a ( for example the ''todayT.htm'') web template (see [[Customised templates]]) to display the snow depth (updating at time set in [[Cumulus.ini]] as explained above. If you understand JavaScript and HTML, you can arrange to upload a background with a scale on which the script can use ''<#snowdepth>'' to overlay the correct depth as a white blanket for example.  The script would have similarities to the current part of the script provided with Cumulus that plots rainfall as a bar chart.  If you are using MX some other web tags can be used too.


Some sites use the ''current conditions'' feature (optional box on main screen, plus ability to create a file that is deleted on use - see Cumulus help) to display further snow information.
Some sites use the ''current conditions'' feature in Cumulus 1 (optional box on main screen, plus ability to create a file that is deleted on use - see Cumulus help) to display further snow information.


Some sites using Cumulus and updating databases as input for creating pages using PHP do manage to display other information from the diary on their web sites (search the support forum for mentions of snow).
Some sites using Cumulus and updating databases as input for creating pages using PHP do manage to display other information from the diary on their web sites (search the support forum for mentions of snow).
[[Category: Terminology]]
[[Category: Terminology]]
[[Category:Log Files]]
5,838

edits

Navigation menu