Log.xml: Difference between revisions

271 bytes removed ,  17:32, 31 May 2020
m
no edit summary
mNo edit summary
mNo edit summary
Line 16: Line 16:
echo 'ERROR - cannot access weather diary';
echo 'ERROR - cannot access weather diary';
}else{
}else{
if($debug) echo 'Success, database ' . $snowDiary . ' is open' . PHP_EOL;
if($debug) echo 'Success, database ' . $snowDiary . ' is open' . PHP_EOL;
$data = fread($fh, filesize($snowDiary));
$data = fread($fh, filesize($snowDiary));
fclose($fh);
fclose($fh); // close diary, now contents in $data
$converted = iconv("Windows-1250", "UTF-8//IGNORE", $data);
$converted = iconv("Windows-1250", "UTF-8//IGNORE", $data); // Convert from windows format that Cumulus uses to UTF-8 to match what most scripts now use
$xml = simplexml_load_string($converted);
$xml = simplexml_load_string($converted);
$dayArray = array();
$dayArray = array();
$oldKey = '';
$oldKey = '';
foreach ($xml->xpath('//ROW') as $item)  
foreach ($xml->xpath('//ROW') as $item)
{
{
$key = substr($item['EntryDate'],0,4) . '-' . substr($item['EntryDate'],4,2) . '-' . substr($item['EntryDate'],6,2);
$key = substr($item['EntryDate'],0,4) . '-' . substr($item['EntryDate'],4,2) . '-' . substr($item['EntryDate'],6,2);
if($key > $rowMetDayStamp) break;
if($key > $rowMetDayStamp) break;
$falling = $item['SnowFalling'] == 'TRUE' ? 1 : 0;
$falling = $item['SnowFalling'] == 'TRUE' ? 1 : 0;
$lying = $item['SnowLying'] == 'TRUE' ? 1 : 0;
$lying = $item['SnowLying'] == 'TRUE' ? 1 : 0;
$depth = $item['SnowDepth'];
$depth = $item['SnowDepth'];
if($key == $oldKey)  // update to another record for same day, retain worse boolean for falling and lying
if($key == $oldKey)  // update to another record for same day, retain worse boolean for falling and lying
{
{
$falling = $oldFalling == 1 ? 1 : $falling;
$falling = $oldFalling == 1 ? 1 : $falling;
$lying = $oldLying == 1 ? 1 : $lying;
$lying = $oldLying == 1 ? 1 : $lying;
$depth = ($depth - $oldDepth) > 0 ? $depth : $oldDepth;
$depth = ($depth - $oldDepth) > 0 ? $depth : $oldDepth;
}
}
$Entry = $item['Entry'];
$Entry = $item['Entry'];
// novel to SPAWS
$oldFalling = $falling;
$oldFalling = $falling;
$oldLying = $lying;
$oldLying = $lying;
$oldDepth = $depth;
$oldDepth = $depth;
$oldKey = $key;
$oldKey = $key;
} // end of loop through XML records
} // end of loop through XML records
if($key == $rowMetDayStamp)
if($key == $rowMetDayStamp)
{  
{  
$snowKnown = true;
$snowKnown = true;
goto snowDone;
if ($debug)
}
{
$snowKnown = false;
echo ' ----- Found entry in weather diary for ' . $englishProcessingDate . $lf;
$Entry = Null; // Other variables were previously set to values appropriate for the lowest temperature
}
goto snowDone;
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;
}
}
snowDone:</pre>
snowDone:</pre>
5,838

edits