Author Topic: UV Index levels in plain english  (Read 3224 times)

0 Members and 1 Guest are viewing this topic.

Offline wello

  • Welloweather
  • Senior Contributor
  • ****
  • Posts: 150
  • Welloweather
    • Welloweather
UV Index levels in plain english
« on: October 25, 2008, 09:46:09 PM »
Does anyone know a way for VWS to display a plain language warning such as "Medium" or "High" alongside the numerical value in respect of UV level? I'm thinking something like the "plain english" rising, falling etc that displays alongside pressure levels. Maybe a bit of Java script?

Peter
Peter
www.welloweather.info
OS WMR-200 with V14.01 P22 on Windows Vista

Offline racenet

  • Moderator
  • Forecaster
  • *****
  • Posts: 1306
    • NH Weather Data
Re: UV Index levels in plain english
« Reply #1 on: October 25, 2008, 11:01:18 PM »
Or simply create a scale like was created here: http://saratoga-weather.org/uv-index.php
and place it on the same page as your UV readings.

Very nice page for an example!  =D>



Bob
www.theamericanflagstore.com - The American Flag Store



www.nhweatherdata.com - NH Weather Data

Offline wello

  • Welloweather
  • Senior Contributor
  • ****
  • Posts: 150
  • Welloweather
    • Welloweather
Re: UV Index levels in plain english
« Reply #2 on: October 25, 2008, 11:53:59 PM »
I did have a simpler version of that table but decided to banish it to the linked graphs page for a simpler look on the Homepage. All I am looking for now is a simple one word statement following the level. If that's not possible, Plan B is to restore the table....I guess.
Peter
www.welloweather.info
OS WMR-200 with V14.01 P22 on Windows Vista

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9014
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: UV Index levels in plain english
« Reply #3 on: October 26, 2008, 01:38:49 AM »
Here's two different methods to do the 'decode' of the UV numbers into words.

PHP:
Code: [Select]
//=========================================================================
//  decode UV to word+color for display

function get_UVrange ( $uv ) {
// figure out a text value and color for UV exposure text
//  0 to 2  Low
//  3 to 5 Moderate
//  6 to 7 High
//  8 to 10 Very High
//  11+ Extreme
   switch (TRUE) {
     case ($uv == 0):
       $uv = 'None';
     break;
     case (($uv > 0) and ($uv < 3)):
       $uv = '<span style="border: solid 1px; background-color: #A4CE6a;">&nbsp;Low&nbsp;</span>';
     break;
     case (($uv >= 3) and ($uv < 6)):
       $uv = '<span style="border: solid 1px;background-color: #FBEE09;">&nbsp;Medium&nbsp;</span>';
     break;
     case (($uv >=6 ) and ($uv < 8)):
       $uv = '<span style="border: solid 1px; background-color: #FD9125;">&nbsp;High&nbsp;</span>';
     break;
     case (($uv >=8 ) and ($uv < 11)):
       $uv = '<span style="border: solid 1px; color: #FFFFFF; background-color: #F63F37;">&nbsp;Very&nbsp;High&nbsp;</span>';
     break;
     case (($uv > 11) ):
       $uv = '<span style="border: solid 1px; color: #FFFF00; background-color: #807780;">&nbsp;Extreme&nbsp;</span>';
     break;
   } // end switch
   return $uv;
} // end get_UVrange

which you can invoke with
Code: [Select]
<?php echo get_UVrange($UVvalue); ?> where $UVvalue is set from ^vxv017^ tag.

You can also use JavaScript similarly .. I have an example at
http://saratoga-weather.org/scripts-VWS-AJAX.php#VWSajaxwf
which has the Ambient templates marked up for AJAX updates using WeatherFlash data.

Hope this helps...
Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline wello

  • Welloweather
  • Senior Contributor
  • ****
  • Posts: 150
  • Welloweather
    • Welloweather
Re: UV Index levels in plain english
« Reply #4 on: October 26, 2008, 09:07:02 PM »
Ken,

This looks to be exactly what I'm looking for but sadly my understanding of code is rather lacking. I inserted your PHP code but can't even move past the problem where the actual code shows on the page. This can be seen on my test site at www.welloweather.info/index2.htm.
It's currently dumped under Yesterdays Extremes for no particular reason other than I can find it easily  :?
Do you have any idea where I'm going wrong?
Peter
www.welloweather.info
OS WMR-200 with V14.01 P22 on Windows Vista

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9014
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: UV Index levels in plain english
« Reply #5 on: October 27, 2008, 01:51:58 PM »
Peter,
PHP code will only be run by the webserver if the extension on the page is .php.  It won't run if the page extension is .htm or .html .. try renaming your page to index2.php and see if that works for you.

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline wello

  • Welloweather
  • Senior Contributor
  • ****
  • Posts: 150
  • Welloweather
    • Welloweather
Re: UV Index levels in plain english
« Reply #6 on: October 28, 2008, 08:34:46 AM »
Ken,

Did as you said. I  placed the code at the bottom of the page code so I could easily find it. Now get the error message:

Fatal error: Call to undefined function get_UVrange() in /home/wellowea/public_html/index2.php on line 534

Wasn't sure what to do with the line:
<?php echo get_UVrange($UVvalue); ?>
so just placed it at the start of the PHP Code

Feeling totally lost here.  :?
Are you able to see what I've done wrong? It's at www.welloweather.info/index2.php

Thanks,
Peter
Peter
www.welloweather.info
OS WMR-200 with V14.01 P22 on Windows Vista

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9014
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: UV Index levels in plain english
« Reply #7 on: October 28, 2008, 03:10:26 PM »
Peter,

You should put
Code: [Select]
<?php echo get_UVrange('^vxv017^'); ?> on your page where you want the UV 'words' to appear.

Then at the end of the page, put
Code: [Select]
<?php
//=========================================================================
//  decode UV to word+color for display

function get_UVrange $uv ) {
// figure out a text value and color for UV exposure text
//  0 to 2  Low
//  3 to 5  Moderate
//  6 to 7  High
//  8 to 10 Very High
//  11+  Extreme
   
switch (TRUE) {
     case (
$uv == 0):
       
$uv 'None';
     break;
     case ((
$uv 0) and ($uv 3)):
       
$uv '<span style="border: solid 1px; background-color: #A4CE6a;">&nbsp;Low&nbsp;</span>';
     break;
     case ((
$uv >= 3) and ($uv 6)):
       
$uv '<span style="border: solid 1px;background-color: #FBEE09;">&nbsp;Medium&nbsp;</span>';
     break;
     case ((
$uv >=) and ($uv 8)):
       
$uv '<span style="border: solid 1px; background-color: #FD9125;">&nbsp;High&nbsp;</span>';
     break;
     case ((
$uv >=) and ($uv 11)):
       
$uv '<span style="border: solid 1px; color: #FFFFFF; background-color: #F63F37;">&nbsp;Very&nbsp;High&nbsp;</span>';
     break;
     case ((
$uv 11) ):
       
$uv '<span style="border: solid 1px; color: #FFFF00; background-color: #807780;">&nbsp;Extreme&nbsp;</span>';
     break;
   } 
// end switch
   
return $uv;
// end get_UVrange
?>

PHP is kinda funny .. it needs a '<?php' at the start of the PHP code, and a '?>' at the end of the code to mark where the PHP interpreter is to read/parse/execute the PHP code.  Stuff outside the <?php .... ?> is treated a plain HTML and not parsed nor executed by PHP.  Also.. in PHP, cASe is important in the names of variables and functions so
get_UVrange is not the same as get_uvrange nor GeT_UVRange .. make sure the function name (in this case get_UVrange) matches in the calling sequence '<?php echo get_UVrange('^vxv017^'); ?>' and in the function definition 'function get_UVrange'

I'm assuming you're uploading index2.htx through VWS as index2.php in this example ..  otherwise the ^vxv017^ in the PHP script won't be replaced by VWS with the current UV index, and the script won't work correctly.

Hope this helps...
Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline wello

  • Welloweather
  • Senior Contributor
  • ****
  • Posts: 150
  • Welloweather
    • Welloweather
Re: UV Index levels in plain english
« Reply #8 on: October 29, 2008, 08:59:38 AM »
It sure did Ken....its working a treat now.  =D&gt;
I'm just tweaking a few areas before taking it "live" with a page redirect. Things such a s a coloured rectangle (white) around None (or Nil as I now call it) and changing the Extreme colour to purple.

I did, however, find one small error with the code.
The line that shows
Code: [Select]
case (($uv > 11) ):should read
Code: [Select]
case (($uv >=11) ):Without the = sign, UV levels of 11 result in 11 being displayed (with no surrounding box) rather than the word Extreme.

Do you have any idea what to use for best results for the page redirect? I'm thinking an index.htm file with the following code
Code: [Select]
<META HTTP-EQUIV="Refresh" CONTENT="0; URL=http://www.welloweather.info/index2.php">
Would that be OK or is there a better way?

Really appreciate you supplying and troubleshooting the code.   :grin:
Thanks again,

Peter
Peter
www.welloweather.info
OS WMR-200 with V14.01 P22 on Windows Vista

Offline wello

  • Welloweather
  • Senior Contributor
  • ****
  • Posts: 150
  • Welloweather
    • Welloweather
Re: UV Index levels in plain english
« Reply #9 on: October 30, 2008, 06:29:33 AM »
Whoops....silly me.  :oops:
Just discovered it doesn't need a page redirect as index.php works the same as index.htm. Learning all the time.
Peter
www.welloweather.info
OS WMR-200 with V14.01 P22 on Windows Vista

Offline timbo6186

  • Member
  • *
  • Posts: 1
Re: UV Index levels in plain english
« Reply #10 on: October 30, 2008, 01:32:44 PM »
Hi Everyone:

                     I am looking for the same type help but I want my display to be a specific graphic.This could be based on the virtual weather station UV tag?

Please help!!!

    Thanks
                     Timbo