Welcome to the Cumulus Support forum.

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

Cumulus MX V4 beta test release 4.0.0 (build 4017) - 17 March 2024

Legacy Cumulus 1 release v1.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

Annual Data Summary - Coloured Values

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

Moderator: daj

captzero
Posts: 363
Joined: Wed 03 Mar 2010 10:20 am
Weather Station: Vantage Pro2 w/ daytime FARS
Operating System: Windows 10
Location: Brisbane, Australia
Contact:

Annual Data Summary - Coloured Values

Post by captzero »

With David's help in another topic I was able to colour the data in my Annual Data Summary page as seen here . It works well and you can easily see seasonal trends and extremes in the data at a glance.
My javascript file has been modified somewhat from the original provided by David (added wind run, deleted avg temps and min/max, changed colours etc) but I have posted the info so you can see how easily it can be done. This is how I modified the javascript version....

(make back ups of your original datasummary.css file and readDayfile.js files before starting... just in case)

First I created a 'colour scale' in the datasummary.css file by adding the following code just below
#table_container .zerovalue { color: #555555;}

Code: Select all

#table_container .extremehigh { color: #800080;}
#table_container .veryhigh { color: #F71B08;}
#table_container .higher{ color: #EC550E;}
#table_container .high{ color: #EEC900;}
#table_container .low { color: #40DA40;}
#table_container .lower{ color: #4078DA;}
#table_container .verylow { color: #00FFFF;}
#table_container .extremelow { color: #FFFFFF;}
#table_container .grey { color: #292727;}
Then right after this line in the readDayfile.js file,
if ((parseFloat(wd_data[dayfilecol].split(',').join('.')) == 0) && (dayfilecol ==14 || dayfilecol ==1)) { $(data_cell).addClass('zerovalue'); }
I added the following code:

Code: Select all

				// Max Temp
				if((parseFloat(wd_data[dayfilecol])>=37.0)&&(dayfilecol==6)){$(data_cell).addClass('extremehigh');}
				if((parseFloat(wd_data[dayfilecol])<=36.9)&&(dayfilecol==6)){$(data_cell).addClass('veryhigh');}
				if((parseFloat(wd_data[dayfilecol])<=33.0)&&(dayfilecol==6)){$(data_cell).addClass('higher');}
				if((parseFloat(wd_data[dayfilecol])<=30.0)&&(dayfilecol==6)){$(data_cell).addClass('high');}
				if((parseFloat(wd_data[dayfilecol])<=25.0)&&(dayfilecol==6)){$(data_cell).addClass('low');}
				if((parseFloat(wd_data[dayfilecol])<=20.0)&&(dayfilecol==6)){$(data_cell).addClass('lower');}
				if((parseFloat(wd_data[dayfilecol])<=10.0)&&(dayfilecol==6)){$(data_cell).addClass('verylow');}
				if((parseFloat(wd_data[dayfilecol])<=6.0)&&(dayfilecol==6)){$(data_cell).addClass('extremelow');}
				// Min Temp
				if((parseFloat(wd_data[dayfilecol])>=37.0)&&(dayfilecol==4)){$(data_cell).addClass('extremehigh');}
				if((parseFloat(wd_data[dayfilecol])<=36.0)&&(dayfilecol==4)){$(data_cell).addClass('veryhigh');}
				if((parseFloat(wd_data[dayfilecol])<=33.0)&&(dayfilecol==4)){$(data_cell).addClass('higher');}
				if((parseFloat(wd_data[dayfilecol])<=29.0)&&(dayfilecol==4)){$(data_cell).addClass('high');}
				if((parseFloat(wd_data[dayfilecol])<=25.0)&&(dayfilecol==4)){$(data_cell).addClass('low');}
				if((parseFloat(wd_data[dayfilecol])<=20.0)&&(dayfilecol==4)){$(data_cell).addClass('lower');}
				if((parseFloat(wd_data[dayfilecol])<=10.0)&&(dayfilecol==4)){$(data_cell).addClass('verylow');}
				if((parseFloat(wd_data[dayfilecol])<=6.0)&&(dayfilecol==4)){$(data_cell).addClass('extremelow');}				
				// Total Rainfall
				if((parseFloat(wd_data[dayfilecol])>=200.0)&&(dayfilecol==14)){$(data_cell).addClass('extremehigh');}
				if((parseFloat(wd_data[dayfilecol])<=199.9)&&(dayfilecol==14)){$(data_cell).addClass('veryhigh');}				
				if((parseFloat(wd_data[dayfilecol])<=150.0)&&(dayfilecol==14)){$(data_cell).addClass('veryhigh');}
				if((parseFloat(wd_data[dayfilecol])<=100.0)&&(dayfilecol==14)){$(data_cell).addClass('higher');}
				if((parseFloat(wd_data[dayfilecol])<=75.0)&&(dayfilecol==14)){$(data_cell).addClass('high');}
				if((parseFloat(wd_data[dayfilecol])<=50.0)&&(dayfilecol==14)){$(data_cell).addClass('low');}
				if((parseFloat(wd_data[dayfilecol])<=20.0)&&(dayfilecol==14)){$(data_cell).addClass('lower');}
				if((parseFloat(wd_data[dayfilecol])<=10.0)&&(dayfilecol==14)){$(data_cell).addClass('verylow');}
				if((parseFloat(wd_data[dayfilecol])<=2.0)&&(dayfilecol==14)){$(data_cell).addClass('extremelow');}				
				if((parseFloat(wd_data[dayfilecol])==0.0)&&(dayfilecol==14)){$(data_cell).addClass('grey');}
				// Rain Rate
				if((parseFloat(wd_data[dayfilecol])>=200.0)&&(dayfilecol==12)){$(data_cell).addClass('extremehigh');}
				if((parseFloat(wd_data[dayfilecol])<=199.9)&&(dayfilecol==12)){$(data_cell).addClass('veryhigh');}				
				if((parseFloat(wd_data[dayfilecol])<=179.9)&&(dayfilecol==12)){$(data_cell).addClass('veryhigh');}
				if((parseFloat(wd_data[dayfilecol])<=99.9)&&(dayfilecol==12)){$(data_cell).addClass('higher');}
				if((parseFloat(wd_data[dayfilecol])<=74.9)&&(dayfilecol==12)){$(data_cell).addClass('high');}
				if((parseFloat(wd_data[dayfilecol])<=49.9)&&(dayfilecol==12)){$(data_cell).addClass('low');}
				if((parseFloat(wd_data[dayfilecol])<=19.9)&&(dayfilecol==12)){$(data_cell).addClass('lower');}
				if((parseFloat(wd_data[dayfilecol])<=9.9)&&(dayfilecol==12)){$(data_cell).addClass('verylow');}
				if((parseFloat(wd_data[dayfilecol])<=1.9)&&(dayfilecol==12)){$(data_cell).addClass('extremelow');}				
				if((parseFloat(wd_data[dayfilecol])==0.0)&&(dayfilecol==12)){$(data_cell).addClass('grey');}
				// High Pressure
				if((parseFloat(wd_data[dayfilecol])>=1030.00)&&(dayfilecol==10)){$(data_cell).addClass('extremehigh');}
				if((parseFloat(wd_data[dayfilecol])<=1029.99)&&(dayfilecol==10)){$(data_cell).addClass('high');}
				if((parseFloat(wd_data[dayfilecol])<=1019.99)&&(dayfilecol==10)){$(data_cell).addClass('low');}
				if((parseFloat(wd_data[dayfilecol])<=1009.99)&&(dayfilecol==10)){$(data_cell).addClass('verylow');}
				if((parseFloat(wd_data[dayfilecol])<=999.99)&&(dayfilecol==10)){$(data_cell).addClass('extremelow');}				
				// Low Pressure
				if((parseFloat(wd_data[dayfilecol])>=1030.00)&&(dayfilecol==8)){$(data_cell).addClass('extremehigh');}
				if((parseFloat(wd_data[dayfilecol])<=1029.99)&&(dayfilecol==8)){$(data_cell).addClass('high');}
				if((parseFloat(wd_data[dayfilecol])<=1019.99)&&(dayfilecol==8)){$(data_cell).addClass('low');}
				if((parseFloat(wd_data[dayfilecol])<=1009.99)&&(dayfilecol==8)){$(data_cell).addClass('verylow');}
				if((parseFloat(wd_data[dayfilecol])<=999.99)&&(dayfilecol==8)){$(data_cell).addClass('extremelow');}				
				// Wind Speed
				if((parseFloat(wd_data[dayfilecol])>=45.0)&&(dayfilecol==17)){$(data_cell).addClass('extremehigh');}
				if((parseFloat(wd_data[dayfilecol])<=44.9)&&(dayfilecol==17)){$(data_cell).addClass('veryhigh');}				
				if((parseFloat(wd_data[dayfilecol])<=29.9)&&(dayfilecol==17)){$(data_cell).addClass('veryhigh');}
				if((parseFloat(wd_data[dayfilecol])<=19.9)&&(dayfilecol==17)){$(data_cell).addClass('higher');}
				if((parseFloat(wd_data[dayfilecol])<=14.9)&&(dayfilecol==17)){$(data_cell).addClass('high');}
				if((parseFloat(wd_data[dayfilecol])<=9.9)&&(dayfilecol==17)){$(data_cell).addClass('low');}
				if((parseFloat(wd_data[dayfilecol])<=4.9)&&(dayfilecol==17)){$(data_cell).addClass('lower');}
				// Wind Gust
				if((parseFloat(wd_data[dayfilecol])>=50.0)&&(dayfilecol==1)){$(data_cell).addClass('extremehigh');}
				if((parseFloat(wd_data[dayfilecol])<=49.9)&&(dayfilecol==1)){$(data_cell).addClass('veryhigh');}
				if((parseFloat(wd_data[dayfilecol])<=39.9)&&(dayfilecol==1)){$(data_cell).addClass('veryhigh');}
				if((parseFloat(wd_data[dayfilecol])<=29.9)&&(dayfilecol==1)){$(data_cell).addClass('high');}
				if((parseFloat(wd_data[dayfilecol])<=19.9)&&(dayfilecol==1)){$(data_cell).addClass('low');}
				if((parseFloat(wd_data[dayfilecol])<=9.9)&&(dayfilecol==1)){$(data_cell).addClass('lower');}
				if((parseFloat(wd_data[dayfilecol])<=4.9)&&(dayfilecol==1)){$(data_cell).addClass('verylow');}				
				// Wind Run
				if((parseFloat(wd_data[dayfilecol])>=200.0)&&(dayfilecol==16)){$(data_cell).addClass('extremehigh');}
				if((parseFloat(wd_data[dayfilecol])<=199.9)&&(dayfilecol==16)){$(data_cell).addClass('veryhigh');}
				if((parseFloat(wd_data[dayfilecol])<=174.9)&&(dayfilecol==16)){$(data_cell).addClass('veryhigh');}
				if((parseFloat(wd_data[dayfilecol])<=149.9)&&(dayfilecol==16)){$(data_cell).addClass('higher');}
				if((parseFloat(wd_data[dayfilecol])<=124.9)&&(dayfilecol==16)){$(data_cell).addClass('high');}
				if((parseFloat(wd_data[dayfilecol])<=99.9)&&(dayfilecol==16)){$(data_cell).addClass('low');}
				if((parseFloat(wd_data[dayfilecol])<=49.9)&&(dayfilecol==16)){$(data_cell).addClass('lower');}
				if((parseFloat(wd_data[dayfilecol])<=24.9)&&(dayfilecol==16)){$(data_cell).addClass('verylow');}
				if((parseFloat(wd_data[dayfilecol])<=9.9)&&(dayfilecol==16)){$(data_cell).addClass('extremelow');}
Upload both files to your server and ... Taadaaaaah!

Expirement with the scales values / colours etc as you weather data will most definately be different from mine. There are probably more elegant and friendlier ways of doing this but it was a fun exercise.
Enjoy.
Dan

http://www.brisbaneliveweather.com




A man with a thermometer always knows the temperature. A man with two thermometers, not so sure.
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: Annual Data Summary - Coloured Values

Post by beteljuice »

The beteljuice is unhappy with the logic order - there seems to be a lot of unecessary work being done !

I haven't looked at any of the original code, but am assuming:
  • This code is already in a loop where each 'line' of data is being processed
    Each line has already been split into 'col' components - wd_data[x] - where x = dayfilecol

You wish to make a decision based on content type - dayfilecol value - (eg. 4 = Min temp)
but the first 'enquiry' is the value of the data regardless of type (ie. EVERY record entry), this would sort of be OK for a single type check, but is escalating because of all the multiple type checks.

The original code snippet was not incorrect because it was looking for any zero value of data.

So this:

Code: Select all

// Max Temp
if((parseFloat(wd_data[dayfilecol])>=37.0)&&(dayfilecol==6)) {$(data_cell).addClass('extremehigh');}
Would be better as:

Code: Select all

// Max Temp
if((dayfilecol==6) && (parseFloat(wd_data[dayfilecol])>=37.0)){$(data_cell).addClass('extremehigh');}
Also, in the case of temp, your colour decisions are identical for Max / Min, so no need to duplicate the code just:

Code: Select all

// Min / Max Temp
if((dayfilecol==4 || dayfilecol==6) && (parseFloat(wd_data[dayfilecol])>=37.0)){$(data_cell).addClass('extremehigh');}
and so on ... having just ONE block of code

Perhaps daj could please cast an eye and either confirm or delete the musings of the beteljuice ...
Image
......................Imagine, what you will KNOW tomorrow !
captzero
Posts: 363
Joined: Wed 03 Mar 2010 10:20 am
Weather Station: Vantage Pro2 w/ daytime FARS
Operating System: Windows 10
Location: Brisbane, Australia
Contact:

Re: Annual Data Summary - Coloured Values

Post by captzero »

I see what you mean. I did say... there are probably more elegant and friendlier ways of doing this.... My knowledge of javascript is pretty limited. Anything to minimise the amount of code is always welcome.
Dan

http://www.brisbaneliveweather.com




A man with a thermometer always knows the temperature. A man with two thermometers, not so sure.
User avatar
daj
Posts: 2041
Joined: Tue 29 Jul 2008 8:00 pm
Weather Station: WH1081
Operating System: Pi & MX
Location: SW Scotland
Contact:

Re: Annual Data Summary - Coloured Values

Post by daj »

As already hinted at, there are better ways to write more complicated logic statements. In this case you might write it as...

Code: Select all

if (dayfilecol==6)
    {
     if (parseFloat(wd_data[dayfilecol])>=37.0) {$(data_cell).addClass('extremehigh');}
     if (parseFloat(wd_data[dayfilecol])<=36.9) {$(data_cell).addClass('veryhigh');}
     if (parseFloat(wd_data[dayfilecol])<=33.0) {$(data_cell).addClass('higher');}
     if (parseFloat(wd_data[dayfilecol])<=30.0) {$(data_cell).addClass('high');}
     if (parseFloat(wd_data[dayfilecol])<=25.0) {$(data_cell).addClass('low');}
     if (parseFloat(wd_data[dayfilecol])<=20.0) {$(data_cell).addClass('lower');}
     if (parseFloat(wd_data[dayfilecol])<=10.0) {$(data_cell).addClass('verylow');}
     if (parseFloat(wd_data[dayfilecol])<=6.0)  {$(data_cell).addClass('extremelow');}
}
This avoids over-zealous logic as it will only do the sub-logic if dayfilecol=6. If not, it would skip to the next block of code -- in theory saving cricual milli-seconds of processing ;)
David
kippfordweather.uk
Cumulus MX & Raspberry Pi
User avatar
mcrossley
Posts: 12689
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Annual Data Summary - Coloured Values

Post by mcrossley »

Indeed, you could even add a few 'break' commands in there to stop the processing once the condition had been found - or make them all 'else if's, or...
User avatar
daj
Posts: 2041
Joined: Tue 29 Jul 2008 8:00 pm
Weather Station: WH1081
Operating System: Pi & MX
Location: SW Scotland
Contact:

Re: Annual Data Summary - Coloured Values

Post by daj »

aye, it can be refined further. trade off between readability and good, economic code I guess.

The worst thing is the PHP 'switch' statement -- I hate repetition and using all those 'breaks' pains me! :lol:
David
kippfordweather.uk
Cumulus MX & Raspberry Pi
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: Annual Data Summary - Coloured Values

Post by beteljuice »

:lol: OK, let's put it all together (One way at least) ;)

Even by putting the dayfilecol check first, In the worst case scenario (temp less than 6)
  • ParseFloat() was being invoked 8 times
    $(data_cell) was being 'decoded' 8 times
    addClass() was being invoked 8 times
So, one way to stop doing all that extra processing..

Code: Select all

// Allocate T_min / T_max colour class
fiddle = false;
if (dayfilecol==4 || dayfilecol==6)
    {
    fiddle = true; // a fiddle so we don't need to do range checks and can use break
    temp_class ='extremelow'; // default value
    temp_check = parseFloat(wd_data[dayfilecol]);
    if (temp_check >=37.0) {temp_class ='extremehigh'; break;}
    if (temp_check >=33.1) {temp_class ='veryhigh'; break;}
    if (temp_check >=30.1) {temp_class ='higher'; break;}
    if (temp_check >=25.1) {temp_class ='high'; break;}
    if (temp_check >=20.1) {temp_class ='low'; break;}
    if (temp_check >=10.1) {temp_class ='lower'; break;}
    if (temp_check >=6.1) {temp_class ='verylow';}
}
if(fiddle) { $(data_cell).addClass(temp_class);}
// END Allocate T_min / T_max colour class
Notice the subtle change in the temp_check logic and values, this is so we can use break as soon as possible.
Image
......................Imagine, what you will KNOW tomorrow !
bigmac
Posts: 159
Joined: Wed 13 May 2009 9:35 am
Weather Station: Davis Vantage Pro 2 Wireless
Operating System: Raspbian wheezy
Location: Nr Ilkley, West Yorks, UK
Contact:

Re: Annual Data Summary - Coloured Values

Post by bigmac »

I've spent the best part of two days trying to get colours to work in the Min/Max Temp option in the PHP script.

I have no knowledge of PHP ( :lol: ), but have read a lot on here and looked at other examples and have actually learnt quite a bit!
So, before I go mad, can one of you genii(?) point me in the right direction?

I know it is something to do with this:

// if we have two sets of data (i.e. Min & Max)
if ($dayfilecol2 >0) {
$tablelayout .= '<td class="datacell smallfont">';
$tablelayout .= $data_arr[1];
$tablelayout .='</td>';
}

but everything I have tried doesn't quite work. It either throws out the columns, affects other tables or tells me to get lost...... :bash:

I know it will be easy to you master coders, but just give me a clue somebody, please? Anybody?

Thanks in anticipation :clap:
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: Annual Data Summary - Coloured Values

Post by beteljuice »

I know it is something to do with this:
Err ........ no - that's simply saying if there are two lots of data in the 'cell' use a small font ;)

Keep looking .. :lol:
Image
......................Imagine, what you will KNOW tomorrow !
bigmac
Posts: 159
Joined: Wed 13 May 2009 9:35 am
Weather Station: Davis Vantage Pro 2 Wireless
Operating System: Raspbian wheezy
Location: Nr Ilkley, West Yorks, UK
Contact:

Re: Annual Data Summary - Coloured Values

Post by bigmac »

Err ........ no - that's simply saying if there are two lots of data in the 'cell' use a small font
Yeah, but that's the thing, I've tried every where else in the code, it don't f'ing work, but if I play around with this bit, it nearly works.

Please Beteljuice, just one more crumb of a clue :twisted:
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: Annual Data Summary - Coloured Values

Post by beteljuice »

Weeeell ..........

First of all you need to have created the colour 'classes' in the css file.

Then you need to convert the JavaScript logic and variable names to the php logic and variable names.

In the js a class was been added, but in the php you are 'building' the cell <td class= > content </td> as you go.

So once you have done your range checks for a particular data type, instead of the js
$(data_cell).addClass(temp_class);

you would have something like:

$tablelayout .= '<td class="datacell ' .$temp_class. ' ">';
$tablelayout .= $data_arr[x];
$tablelayout .='</td>';

Someone has done all this already somewhere I would have thought, once their hangovers cleared hopefully they'll post the code ;)
Image
......................Imagine, what you will KNOW tomorrow !
bigmac
Posts: 159
Joined: Wed 13 May 2009 9:35 am
Weather Station: Davis Vantage Pro 2 Wireless
Operating System: Raspbian wheezy
Location: Nr Ilkley, West Yorks, UK
Contact:

Re: Annual Data Summary - Coloured Values

Post by bigmac »

Thanks Beteljuice.
Surprisingly, I had already figured something like that was what I needed and had tried this:

Code: Select all

if (($dayfilecol2 >0) && (floatval(str_replace(',','.',$data_arr[1])) >= 30.0))
						{ 
						$tablelayout .= '<td class="datacell smallfontextremehigh">';
						$tablelayout .= $data_arr[1];
						$tablelayout .='</td>';
					}
				 
			
				
					if (($dayfilecol2 >0) && (floatval(str_replace(',','.',$data_arr[1])) <= 29.9))
						{ 
						$tablelayout .= '<td class="datacell smallfontveryhigh">';
						$tablelayout .= $data_arr[1];
						$tablelayout .='</td>';
					}
				
				
				
					if (($dayfilecol2 >0) && (floatval(str_replace(',','.',$data_arr[1])) <= 25.0))
						{ 
						$tablelayout .= '<td class="datacell smallfonthigher">';
						$tablelayout .= $data_arr[1];
						$tablelayout .='</td>';
					}

etc..
..but that results in repetition of the high value as it agrees with each statement, and also completely screws the formatting resulting in this mess:
historic.PNG
Not knowing how to correctly break out once a condition is satisfied is my problem I believe. I assume I use the "break" word, but I don't know the correct syntax for it in this scenario :oops: When I tried "break;" in various places, it just resulted in no data being posted.

A little knowledge is a dangerous thing as they say......
You do not have the required permissions to view the files attached to this post.
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: Annual Data Summary - Coloured Values

Post by beteljuice »

Yup your code allows several results, each of which generates a table cell :lol:

Pseudo PHP code:

Code: Select all

if( .. datatype..){ // eg. reasoning for temperature values
   $temp_check = floatval(str_replace(',','.',$data_arr[1]));  // get a 'real' numeric value
// do range checks for value
    if ($temp_check >=37.0) {
        $temp_class ='extremehigh';
    } elseif ($temp_check >=33.1) {
        $temp_class ='veryhigh';
    } elseif ($temp_check >=30.1) {
        $temp_class ='higher';
    } elseif ($temp_check >=25.1) {
        $temp_class ='high';
    } elseif ($temp_check >=20.1) {
        $temp_class ='low';
    } elseif ($temp_check >=10.1) {
        $temp_class ='lower';
    } elseif ($temp_check >=6.1) {
        $temp_class ='verylow';
    } else {
        $temp_class = 'extremelow';
    }  // END range check
// construct table cell
   $tablelayout .= '<td class="datacell ' .$temp_class. '">';
   $tablelayout .= $data_arr[1];
   $tablelayout .='</td>';
} // END data type
EDIT: corrected as per post below :oops:
Last edited by beteljuice on Mon 02 Jan 2012 7:16 pm, edited 2 times in total.
Image
......................Imagine, what you will KNOW tomorrow !
bigmac
Posts: 159
Joined: Wed 13 May 2009 9:35 am
Weather Station: Davis Vantage Pro 2 Wireless
Operating System: Raspbian wheezy
Location: Nr Ilkley, West Yorks, UK
Contact:

Re: Annual Data Summary - Coloured Values

Post by bigmac »

Beteljuice, as ever, you have provided the answer :clap: for which I thank you!

And certainly not wishing to nit pick (after all I failed miserably at it!), but there was a bracket missed out after $data_arr[1]) ) ; on the 2nd line which had me scratching my head for a bit as it returned an error about an unexpected ";". So, just for the sake of clarity for anyone else reading, the ever so slightly corrected code:

Code: Select all

if( .. datatype..){ // eg. reasoning for temperature values
   $temp_check = floatval(str_replace(',','.',$data_arr[1]));  // get a 'real' numeric value
// do range checks for value
    if ($temp_check >=37.0) {
        $temp_class ='extremehigh';
    } elseif ($temp_check >=33.1) {
        $temp_class ='veryhigh';
    } elseif ($temp_check >=30.1) {
        $temp_class ='higher';
    } elseif ($temp_check >=25.1) {
        $temp_class ='high';
    } elseif ($temp_check >=20.1) {
        $temp_class ='low';
    } elseif ($temp_check >=10.1) {
        $temp_class ='lower';
    } elseif ($temp_check >=6.1) {
        $temp_class ='verylow';
    } else {
        $temp_class = 'extremelow';
    }  // END range check
// construct table cell
   $tablelayout .= '<td class="datacell ' .$temp_class. '">';
   $tablelayout .= $data_arr[1];
   $tablelayout .='</td>';
} // END data type
Thank you again.
User avatar
mcrossley
Posts: 12689
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: Annual Data Summary - Coloured Values

Post by mcrossley »

An old thread, but I finally decided to add some colour coding to my temperatures. Rather than go with fixed colours I implemented a colour gradient. It is the PHP version and is only set-up for °C - oh and I took to opportunity to convert it all to HTML5 and get rid of all the custom attributes on the table cells.

Main caveat, it is probably based on a very old version of DAJ's original scripts - I don't think I kept up with the updates. But if you can decode it and make use of it please do.

http://weather.wilmslowastro.com/readDa ... p?view=sce

My implementation is here:
http://weather.wilmslowastro.com/datasummary.php
Post Reply