Page 1 of 1

Saratoga AJAX/PHP Cumulus template updated (CU-defs.php)

Posted: Sun 25 Mar 2012 1:48 am
by saratogaWX
I've added some code to the CU-defs.php, and a new setting in Settings-weather.php ($SITE['overrideRain']) to control display of current conditions when using a METAR as the source ($SITE['conditionsMETAR']).

The overrideRain setting allows your local station rain to override the METAR rain indication (if any) with icon/text as follows:

"Moderate Drizzle" when rain rate is = 0.0 per hour and <#LastRainTipISO> is < 30 minutes ago.
"Light Rain" when rain rate is > 0.0 and < 2.5 mm (0.098 in) per hour
"Moderate Rain" when rain rate is >= 2.5 mm (0.098 in) and < 7.6 mm (0.30 in) per hour
"Heavy Rain" when rain rate is >= 7.6 mm (0.30 in) per hour and < 50 mm (2.0 in) per hour
"Violent Rain" when rain rate is >= 50 mm (2.0 in) per hour

If $SITE['overrideRain'] setting is ommitted from Settings-weather.php, the default will be assumed as 'true' to enable the function.

If enabled, the rain words from the METAR will be removed, and the above words used based on the current rain rate.

We finally had enough rain around here to test out the additions :)

Use the updates page (24-Mar-2012) to get the changed *-defs files (and also support for WeatherCat software that was released today).

Best regards,
Ken

Re: Saratoga AJAX/PHP Cumulus template updated (CU-defs.php)

Posted: Tue 27 Mar 2012 1:27 pm
by MickinMoulden
Well done :). I guess it's easy enough to chance to your local conditions, as 40% of my rain would be heavy, and 50% violent ;) . Had thought about doing a gauge for rain rate, as for most people that are not into it like we are, would not understand how heavy it's raining if the rainrate was 70+mm/hr calculated over 5 mins. They would be like " :? ????". You need a big sign saying "Raining Cat's and Dogs Man!".

Re: Saratoga AJAX/PHP Cumulus template updated (CU-defs.php)

Posted: Tue 27 Mar 2012 11:20 pm
by GraemeT
Mick,
I use this php function to show a "local lingo" description of rain rate. It can easily be extended for your bucket-sized rain-drops...

Code: Select all

/**
 * showLastRain()
 * Returns the date & time of last rain.
 */
function showLastRain($lastrain, $rrate) {
	$raindate=substr($lastrain,8,2)."/".substr($lastrain,5,2)."/".substr($lastrain,0,4);
	$raintime=substr($lastrain,11,5);
	$lastraindays=dateDiff($lastrain, date("y-m-d h:m"));

	switch ($lastraindays)
	{
	case 0:
		if ($rrate>15) $lastmsg='The ark plans are drawn up, now to start building...';
		elseif ($rrate>10) $lastmsg='It is time to think about building an ark!';
		elseif ($rrate>7.6) $lastmsg='It is raining cats and dogs here!';
		elseif ($rrate>2.5) $lastmsg='It is raining moderately';
		elseif ($rrate>0) $lastmsg='It is raining lightly';
		else $lastmsg='Last Recorded Rain - '.$raintime.' today';
		break;
	case 1:
		$lastmsg='Last Recorded Rain - '.$raintime.' yesterday';
		break;
	default:
		if ($raindate>"00/00/0000")
			$lastmsg='No rain detected for '.$lastraindays.' days ('.$raindate.' '.$raintime.')';
		else $lastmsg='No rain detected since new install';
	}
	return ($lastmsg);
}	// end of showLastRain()

/**
 * dateDiff()
 * Find the difference in days between two calendar dates.
 * Source:  http://php.net/manual/en/function.date.php
 *
 * @param Date $startDate
 * @param Date $endDate
 * @return Int
 */
function dateDiff($startDate, $endDate) {
// Parse dates for conversion
    $startArry=date_parse($startDate);
    $endArry=date_parse($endDate);

    // Convert dates to Julian Days
    $start_date=gregoriantojd($startArry["month"], $startArry["day"], $startArry["year"]);
    $end_date=gregoriantojd($endArry["month"], $endArry["day"], $endArry["year"]);

    // Return difference
    return round(($end_date - $start_date), 0);
}	// end of dateDiff()