Diary.db: Difference between revisions

From Cumulus Wiki
Jump to navigationJump to search
m (Remove duplicated text)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
'''This is the file where MX stores its [[Weather Diary]]'''
'''This is the file where MX stores its [[Weather Diary]]'''
[[Category:Log Files]]


=Introduction =
=Introduction =
Line 47: Line 46:
foreach($row as $key => $value )
foreach($row as $key => $value )
{
{
[[Setting_up_Raspberry_Pi#Editing_the_Weather_Diary]] if($key == 'Timestamp')
[[MX_on_Linux#Editing_the_Weather_Diary]] if($key == 'Timestamp')
{
{
$keyDate = substr($value, 0, 10);
$keyDate = substr($value, 0, 10);
Line 70: Line 69:
==Editing==
==Editing==


Please see [[Setting_up_Raspberry_Pi#Editing_the_Weather_Diary]], although that applies to Linux devices a similar approach can be taken using Microsoft Windows.
Please see [[MX_on_Linux#Editing_the_Weather_Diary]], although that applies to Linux devices a similar approach can be taken using Microsoft Windows.






[[Category:Log Files]]
[[Category:Cumulus Files]]
[[Category:Cumulus MX]]
[[Category:Cumulus MX]]

Latest revision as of 10:01, 11 June 2021

This is the file where MX stores its Weather Diary

Introduction

The weather diary is created specifically to record any snowfall, but as you can store a comment with any content, a number of Cumulus users are using it to record other entries that can be specific to a day (e.g. hailstorms), or indeed anything that might be recorded in a diary.

Format

The database uses SQLite format and a script to read this can be found in Weather Diary article.

Content

Each record has the following content:

  • Date
  • Time
    • (In early releases, Mark set this to 00:00:00)
    • In later releases, this is set to 01:00:00, to minimise time zone issues.
  • Snow Falling (boolean)
  • Snow Lying (boolean)
  • Snow depth (unsigned decimal number)
  • Entry (a text field for storing comments)

Accessing MX diary outside MX

The weather diary is stored in a sqLite database and that can be easily accessed by any ODBC software (e.g. Libre Office Base) and many other well known database software. It can also be accessed using PDO instructions in PHP Hypertext Preprocessor.

Here is an example in a PHP 7.3 (please note, this script will not work without changes for PHP 7.4, and PHP 8.x) script (modification of script available in File:Snow diary.zip) of accessing any one day ($rowMetDayStamp in yyyy-mm-dd format):

$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 )
			{
		[[MX_on_Linux#Editing_the_Weather_Diary]]		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;
			}
		}
	}
}

Editing

Please see MX_on_Linux#Editing_the_Weather_Diary, although that applies to Linux devices a similar approach can be taken using Microsoft Windows.