Temperature module - centre circle gradient

I’ve been looking at the code that creates the gradient for the temperature circle. This is driven by an array of 80 different colours from a cold pink, through purples, blues, greens, yellows, oranges and ending in full red.
I have seen the code which selects the two grad colours from day_max to day_min in celcius.

# ----------------- color range
 $in_C   = temp_in_c ($max_temp);
 $n      = 32 + $in_C;
 if ($n < 0) {$n=0;}
 if ($n > $maxTemp)      
      {  $color1 = $temp_colors[$maxTemp];}
 else {  $color1 = $temp_colors[$n];}
 $in_C_l = $in_C =temp_in_c ($min_temp);
 $n      = 32 + $in_C;
 if ($n < 0) {$n=0;}
 if ($n > $maxTemp)      
      {  $color2 = $temp_colors[$maxTemp];}
 else {  $color2 = $temp_colors[$n];}
#

Can anyone please explain, in an array of 80 colours, what the

$n = 32 + $in_C;

is doing?

I’m no expert, but I think these two 6-line chunks of code select the gradient end colours to use with max and min temps ranging from about -32°C to 48°C - a range of 80 deg C to go with 80 colours.

I think I agree. There are 80 colours and a -32C with the +32 offset would pick colour #1 and as you say allow up to 48C.

I do think the code has a bug as the variable for min_temp is $in_C_l which is not used elsewhere in the code. I think it should be as follows:

$in_C_l = temp_in_c ($min_temp);
$n      = 32 + $in_C_l;
if ($n < 0) {$n=0;}
if ($n > $maxTemp)      
     {  $color2 = $temp_colors[$maxTemp];}
else {  $color2 = $temp_colors[$n];}

[quote=“jasonmfarrow, post:3, topic:71640”]
I do think the code has a bug as the variable for min_temp is $in_C_l which is not used elsewhere in the code. [/quote]

Well you are the first user which is clairvoyant.
The result of your changes: generate exactly the same value.
So what is the bug?

Your current version of the scripts does not use “temp in Celsius used in the left column” anymore.
But the same script (albeit with a lower version number) is still used in older versions.

Do you really dare to say that an “unused” variable name is a “bug” ?
And that using “unused” variable solves anything such as an error?

@ ALL
Luckily in this case a future updated version of temp_c_block.php will not fail as there is no changed value.

BUT if you are changing code add timestamps to the code.
And at least, change the version number in the first line of the script.
→ PWS_updates will warn you to move your local changes to the new version
-----> You can find them with the dates you added.

Wim

1 Like

Hi Pwsdashboard,

Not trying to cause offence, just trying to understand the code (this template is new to me) and make some subtle personal customisations. Admittedly the code does do the same thing. Apologies.

Thank you for the heads-up about how future changes & upgrades will be handled. I’ll retro-fit my timestamps.

1 Like