WXforum.net
May 22, 2013, 11:19:38 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
Members: 6617  •  Posts: 178617  •  Topics: 18128
Please welcome TheMOX, our newest member.
Welcome to the the new hosting for WXforum.net.
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: UV Index levels in plain english  (Read 1867 times)
0 Members and 1 Guest are viewing this topic.
wello
Welloweather
Senior Contributor
****
Offline Offline

Posts: 150


Welloweather


WWW
« 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
Logged

Peter
www.welloweather.info
OS WMR-200 with V14.01 P22 on Windows Vista
racenet
Moderator
Forecaster
*****
Offline Offline

Posts: 1271



WWW
« 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!  Applause



Bob
Logged

www.theamericanflagstore.com - The American Flag Store



www.nhweatherdata.com - NH Weather Data
wello
Welloweather
Senior Contributor
****
Offline Offline

Posts: 150


Welloweather


WWW
« 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.
Logged

Peter
www.welloweather.info
OS WMR-200 with V14.01 P22 on Windows Vista
saratogaWX
Administrator
Forecaster
*****
Offline Offline

Posts: 3732


Saratoga, CA, USA Weather - free PHP scripts


WWW
« 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:
//=========================================================================
//  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:
<?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
Logged

Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis Vantage Pro Plus - FARS, Boltek-PCI/NexStorm, GRLevel3, WD, WL, VWS, Cumulus, Meteohub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP
wello
Welloweather
Senior Contributor
****
Offline Offline

Posts: 150


Welloweather


WWW
« 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  Confused
Do you have any idea where I'm going wrong?
Logged

Peter
www.welloweather.info
OS WMR-200 with V14.01 P22 on Windows Vista
saratogaWX
Administrator
Forecaster
*****
Offline Offline

Posts: 3732


Saratoga, CA, USA Weather - free PHP scripts


WWW
« 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
Logged

Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis Vantage Pro Plus - FARS, Boltek-PCI/NexStorm, GRLevel3, WD, WL, VWS, Cumulus, Meteohub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP
wello
Welloweather
Senior Contributor
****
Offline Offline

Posts: 150


Welloweather


WWW
« 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.  Confused
Are you able to see what I've done wrong? It's at www.welloweather.info/index2.php

Thanks,
Peter
Logged

Peter
www.welloweather.info
OS WMR-200 with V14.01 P22 on Windows Vista
saratogaWX
Administrator
Forecaster
*****
Offline Offline

Posts: 3732


Saratoga, CA, USA Weather - free PHP scripts


WWW
« Reply #7 on: October 28, 2008, 03:10:26 PM »

Peter,

You should put
Code:
<?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:
<?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
Logged

Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis Vantage Pro Plus - FARS, Boltek-PCI/NexStorm, GRLevel3, WD, WL, VWS, Cumulus, Meteohub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP
wello
Welloweather
Senior Contributor
****
Offline Offline

Posts: 150


Welloweather


WWW
« Reply #8 on: October 29, 2008, 08:59:38 AM »

It sure did Ken....its working a treat now.  Applause
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:
case (($uv > 11) ):
should read
Code:
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:
<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.   Very Happy
Thanks again,

Peter
Logged

Peter
www.welloweather.info
OS WMR-200 with V14.01 P22 on Windows Vista
wello
Welloweather
Senior Contributor
****
Offline Offline

Posts: 150


Welloweather


WWW
« Reply #9 on: October 30, 2008, 06:29:33 AM »

Whoops....silly me.  Embarassed
Just discovered it doesn't need a page redirect as index.php works the same as index.htm. Learning all the time.
Logged

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

Posts: 1



« 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
 
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.115 seconds with 20 queries.