Welcome to the Cumulus Support forum.

Latest Cumulus MX V4 release 4.4.2 (build 4085) - 12 March 2025

Latest Cumulus MX V3 release 3.28.6 (build 3283) - 21 March 2024

Legacy Cumulus 1 release 1.9.4 (build 1099) - 28 November 2014
(a patch is available for 1.9.4 build 1099 that extends the date range of drop-down menus to 2030)

Download the Software (Cumulus MX / Cumulus 1 and other related items) from the Wiki

If you are posting a new Topic about an error or if you need help PLEASE read this first viewtopic.php?p=164080#p164080

How do I transfer text to a logical value - with PHP

Other discussion about creating web sites for Cumulus that doesn't have a specific subforum

Moderator: daj

Post Reply
User avatar
beelzebubs
Posts: 62
Joined: Sun 04 Oct 2009 10:18 pm
Weather Station: Davis VP2
Operating System: Windows 7
Location: Sweden
Contact:

How do I transfer text to a logical value - with PHP

Post by beelzebubs »

How do I transfer the text in the tag $temptrendenglish to a logical value?

I want:
Rising to 1
Falling to -1
and Steady to 0

So if the trends says falling I could have 1 in stead.

My idea is to check whats the value of the $temptrendenglish is an then with a new tag have a logical value out instead.

Say if $temptrendenglish is Rising then the tag $loicaltemptrends says it is 1 instead.
I need a logical value in stead of a text.

I think it would bee possible to do this with php but i don't now how and i haven't find any useful on the www.
So if some one will give me a helping hand i would be thankfull.

/Kenneth
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: How do I transfer text to a logical value - with PHP

Post by beteljuice »

Why use $temptrendenglish ?

There a numeric trend value you can apply your logic to and also apply your own ideas of 'steady', and various 'degrees' of rising / falling.
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
beelzebubs
Posts: 62
Joined: Sun 04 Oct 2009 10:18 pm
Weather Station: Davis VP2
Operating System: Windows 7
Location: Sweden
Contact:

Re: How do I transfer text to a logical value - with PHP

Post by beelzebubs »

beteljuice you should never ask why ;)

I no pro, but I do my best.
The numeric trend, these one I haven't seen maybe I was to tired.
But thanks for the tip.

I have came half the way, but I need a little help to reach the goal.
I have done like these:

Code: Select all

<?php
if ($TChangeLastHour  == 0){
	echo "Steady";
}
else if ($TChangeLastHour  >0.01){
	echo "Rising";
}
else {
	echo "Falling ";	
}
?>
Just to see if my idea works, and theoretical it does.
Because if I change the value of TChangeLastHour I can see the right text.
(TChangeLastHour is the same as TempChangeLastHour but with a dot instead of a comma)
But how do I close it all up?

Normally in the script I use

Code: Select all

echo' var cu_rain = '.$RCrfall.';';
so I can use a javascript call/check for the cu_rain but I really don't now how to get this to work with the if/else.

Please explain.
/Kenneth
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: How do I transfer text to a logical value - with PHP

Post by beteljuice »

You are practically there - although ==0 check is far too 'tight' for steady.

Rip this code apart to suit your purposes

Code: Select all

<?php

// lets do some pressure trend and storm stuff - NB: this is all hPa / mb
//   Barometric Trend (3 hour) - NB. cumulus gives an hourly average of last 3 hrs
//   so we need to x3 for our weather decisions

		$weather_trend = $TChangeLastHour * 3;
		if (($weather_trend >= -0.7) && ($weather_trend <= 0.7)) { 
				$pressure_trend_text = "Steady";
				$p_arrow = 0;	// steady
		}
   		if (($weather_trend > 0.7) && ($weather_trend < 2.0 )) {
				$pressure_trend_text = "Rising";
				$p_arrow = 1;	// rising
		}
   		if ($weather_trend >= 2.0) {
				$pressure_trend_text = "Rising"; 
				$p_arrow = 1;	// rising rapidly
		}
   		if (($weather_trend < -0.7) && ($weather_trend > -2.0)) {
				$pressure_trend_text = "Falling"; 
				$p_arrow = -1;	// falling
		}
   		if ($weather_trend <= -2.0) { 
				$pressure_trend_text = "Falling"; 
				$p_arrow = -1;		// falling rapidly
		}

		if($weather_trend <= -7){ // add storm  / End Of The World warning :-)
// do something interesting
		}

// create js variable
                echo' var cu_press_trend = '.$p_arrow.';';

?>
Note this gives you the option to have a greater 'range' of -x / 0 / +x if you wish.

For simple -1 / 0 / +1
You can shorten to something like:

Code: Select all

		$weather_trend = $TChangeLastHour * 3;
		if (($weather_trend >= -0.7) && ($weather_trend <= 0.7)) { 
				$p_arrow = 0;	// steady
		} elseif ($weather_trend > 0) { // already done 'steady' range check - MUST be rising
        			$p_arrow = 1;	// rising
		} else {
        			$p_arrow = -1;	// done other checks - MUST be falling
      }


// create js variable
                echo' var cu_press_trend = '.$p_arrow.';';

?>
Last edited by beteljuice on Fri 24 Feb 2012 4:18 pm, edited 2 times in total.
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
beelzebubs
Posts: 62
Joined: Sun 04 Oct 2009 10:18 pm
Weather Station: Davis VP2
Operating System: Windows 7
Location: Sweden
Contact:

Re: How do I transfer text to a logical value - with PHP

Post by beelzebubs »

Thanks beteljuice :clap:
I will check further into this tonight when things have cool down a little bit.
User avatar
mcrossley
Posts: 14388
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: How do I transfer text to a logical value - with PHP

Post by mcrossley »

Or with just two compares:

Code: Select all

$weather_trend = $TChangeLastHour * 3;
$p_arrow = 0; // steady   
if ($weather_trend >= 0.7) { 
    $p_arrow = 1;   // rising
} else if ($weather_trend <= -0.7){
    $p_arrow = -1;   // falling
}
How many ways to skin a cat? :lol:
User avatar
beteljuice
Posts: 3292
Joined: Tue 09 Dec 2008 1:37 pm
Weather Station: None !
Operating System: W10 - Threadripper 16core, etc
Location: Dudley, West Midlands, UK

Re: How do I transfer text to a logical value - with PHP

Post by beteljuice »

mcrossley wrote:How many ways to skin a cat? :lol:

Code: Select all

$weather_trend = $TChangeLastHour * 3;
// create js variable
echo' var cu_press_trend = ' .($weather_trend >= 0.7 ? 1 : ($weather_trend <= -0.7 ? -1 : 0)). ';';
;)
Last edited by beteljuice on Mon 27 Feb 2012 5:13 am, edited 1 time in total.
Image
......................Imagine, what you will KNOW tomorrow !
User avatar
mcrossley
Posts: 14388
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: How do I transfer text to a logical value - with PHP

Post by mcrossley »

Now you're just showing off :lol:
Post Reply