Page 2 of 2

Re: PressTrendVal and PHP question

Posted: Tue 04 Feb 2014 2:53 pm
by mcrossley
Actually I don't think any of them are correct!

Using the original logic you get an asymmetry between positive and negative values (example using 1dp)....

Code: Select all

 6.0 ... +999 = Rising Very Rapdily
 3.6 ...  5.9 = Rising Quickly
 1.6 ...  3.5 = Rising
 0.2 ...  1.5 = Rising Slowly
 0.1 ...  0.0 = Steady
-0.1 ... -1.4 = Falling Slowly
-1.5 ... -3.4 = Falling
-3.5 ... -5.9 = Falling Quickly
-6.0 ... -999 = Falling Very Rapidly
I think the most understandable way of writing this logic that would also work with 1dp or more would be (using the definitions I found on the Met Office)*...

Code: Select all

$weather_trend = ret_value("presstrend") * 3;
$pressure_trend_text = ($weather_trend >= 0.1) ? 'Rising' : ($weather_trend <= -0.1) ? 'Falling' : '';
$weather_trend = abs($weather_trend);
if ($weather_trend > 6.0)
	$pressure_trend_text .= ' Very Rapidly';
elseif ($weather_trend > 3.5)
	$pressure_trend_text .= ' Quickly';
elseif ($weather_trend > 1.6)
	// Rising or Falling
elseif ($weather_trend >= 0.1)
	$pressure_trend_text .= ' Slowly';
else
	$pressure_trend_text = 'Steady';


*http://www.metoffice.gov.uk/weather/mar ... ssary.html

Rising (or falling) slowly
- Pressure change of 0.1 to 1.5 hPa in the preceding three hours

Rising (or falling)
- Pressure change of 1.6 to 3.5 hPa in the preceding three hours

Rising (or falling) quickly
- Pressure change of 3.6 to 6.0 hPa in the preceding three hours

Rising (or falling) v. rapidly
- Pressure change of more than 6.0 hPa in the preceding three hours

Which is ambiguous if you use more than 1dp, what is +1.52 'Rising Slowly' or 'Rising'? I have assumed that >n.5 jumps to the next higher category.

Re: PressTrendVal and PHP question

Posted: Tue 04 Feb 2014 3:06 pm
by steve
Yes, I'd realised that there was an asymmetry to the code in Cumulus if the values were exactly on the boundary values. But it's not really a serious issue, particularly as Cumulus is doing floating point comparisons, so the figures are highly unlikely to actually fall exactly on a boundary (internally). It does perhaps look a little odd externally after rounding. It's the kind of thing that you-know-who might start a very long thread about. Or several threads...

Re: PressTrendVal and PHP question

Posted: Tue 04 Feb 2014 4:24 pm
by RayProudfoot
Afternoon chaps. Back home after a walk in Lyme Park. :)

Mark, although the Met Office 'rules' are the official ones I much prefer Steve's as they leave less room for ambiguity and have more stages. Also, there's no point in me coding it differently in PHP unless Steve does the same in Cumulus and I don't think he either wants or needs to.

There should be a symmetry and we have that. As you both said it was just the wording that needed changing in my original to make it match Cumulus.

I hope I haven't opened a can of worms. :( There should be a good chance of the code being tested in the next 96 hours with 2 deep depressions moving in with probable big changes up and down in pressure.

I have changed the code now so it should be easy to spot if it agrees with Cumulus.