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 4019) - 03 April 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

UV reading from number to word

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

Moderator: daj

User avatar
mcrossley
Posts: 12756
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: UV reading from number to word

Post by mcrossley »

Almost there, this should do it...

Code: Select all

<script type="text/javascript">
if (<#UV> >= 11) {
document.write('Extreme');
} else if (<#UV> >= 8) {
document.write('Very High');
} else if (<#UV> >= 6) {
document.write('High');
} else if (<#UV> >= 3) {
document.write('Moderate');
} else if (<#UV> >=  1) {
document.write('Low');
} else if (<#UV> === 0) {
document.write('No Reading');
} else {
document.write('Invalid');
}
</script>
My alternative would be...

Code: Select all

<script type="text/javascript">
var lookupVal = [0,1,1,2,2,2,3,3,4,4,4,5,5,5,5,5,5],
    lookupTxt = ['No reading','Low','Moderate','High','Very high','Extreme'];
document.write(lookupTxt[lookupVal[<#UV>]] || 'Invalid');
</script>
User avatar
William Grimsley
Posts: 833
Joined: Thu 22 Sep 2011 5:22 pm
Weather Station: Davis Vantage Vue
Operating System: Windows 7 Home Premium 64-bit
Location: Latitude: 50.70189285 Longitude: -3.30849957
Contact:

Re: UV reading from number to word

Post by William Grimsley »

Hi MarystownWeather2012,

I would go with the top piece of code in Mark's last post! :D

I'm glad that I could help,

William
MarystownWeather2012
Posts: 17
Joined: Tue 20 Mar 2012 9:23 pm
Weather Station: WRM200A
Operating System: Windows 7
Location: Canada

Re: UV reading from number to word

Post by MarystownWeather2012 »

Thanks all I appreciate all your help on this.
User avatar
mcrossley
Posts: 12756
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: UV reading from number to word

Post by mcrossley »

William Grimsley wrote:I would go with the top piece of code in Mark's last post! :D
Coward! :lol:
User avatar
William Grimsley
Posts: 833
Joined: Thu 22 Sep 2011 5:22 pm
Weather Station: Davis Vantage Vue
Operating System: Windows 7 Home Premium 64-bit
Location: Latitude: 50.70189285 Longitude: -3.30849957
Contact:

Re: UV reading from number to word

Post by William Grimsley »

mcrossley wrote:
William Grimsley wrote:I would go with the top piece of code in Mark's last post! :D
Coward! :lol:
Ok, I don't find that funny, at all. I'm not a coward... :cry:
User avatar
mcrossley
Posts: 12756
Joined: Thu 07 Jan 2010 9:44 pm
Weather Station: Davis VP2/WLL
Operating System: Bullseye Lite rPi
Location: Wilmslow, Cheshire, UK
Contact:

Re: UV reading from number to word

Post by mcrossley »

OK, conservative then ;) - go with the lower code and work out what it is doing. Two lookups instead of up to six compares sounds much more efficient to me.
User avatar
William Grimsley
Posts: 833
Joined: Thu 22 Sep 2011 5:22 pm
Weather Station: Davis Vantage Vue
Operating System: Windows 7 Home Premium 64-bit
Location: Latitude: 50.70189285 Longitude: -3.30849957
Contact:

Re: UV reading from number to word

Post by William Grimsley »

mcrossley wrote:OK, conservative then ;) - go with the lower code and work out what it is doing. Two lookups instead of up to six compares sounds much more efficient to me.
Hi Mark,

Yes, I am conservative! :lol:

Ok, I understand what that code is doing. Yes, I do think two lookups instead of six sounds much more efficient, too! Sorry, to make you think I was a coward! But, at first I didn't realize I was coward, until now! :lol:

Thanks,

William
MarystownWeather2012
Posts: 17
Joined: Tue 20 Mar 2012 9:23 pm
Weather Station: WRM200A
Operating System: Windows 7
Location: Canada

Re: UV reading from number to word

Post by MarystownWeather2012 »

Maybe you both can team up and help me with this.

I am trying to add line "Watches/Warnings/Other" with webtag <#currcond> to my iCumulus page under the Current forecast line.

Any help would be appreciated.

Below is photo.
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: UV reading from number to word

Post by beteljuice »

That should be under another topic.

When your head clears try this for your UV ;)

Code: Select all

<td>UV Index</td>

<td>
<script type="text/javascript">

var lookupVal = [0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,4,4],
	lookupCol = ["#00FF00", "#FFFF00", "#FFA500", "#FF0000", "#FF66FF"],
	lookupTxt = ['Low','Medium','High','VERY HIGH','EXTREMELY HIGH'];
	if(lookupVal[<#UV>] >= 0){
		document.write("<span style='background-color: " +lookupCol[lookupVal[<#UV>]]+ ";'>&nbsp;<#UV>/16&nbsp;" +lookupTxt[lookupVal[<#UV>]]+ "&nbsp;</span>");
	}else{
		document.write('unknown');
	}
</script>
</td>
@ william ..... Don't even think about it :twisted:
Last edited by beteljuice on Tue 26 Feb 2013 12:40 pm, edited 1 time in total.
Image
......................Imagine, what you will KNOW tomorrow !
ayde_bury
Posts: 33
Joined: Thu 07 Jun 2012 5:37 pm
Weather Station: Davis VPro2 plus 24hr FARS
Operating System: Windows 2008 Server / Mac OSX
Location: Suffolk, United Kingdom
Contact:

Re: UV reading from number to word

Post by ayde_bury »

I'm using a Davis station with UV reporting to 1 decimal place - the UK in winter gets little sun so every tenth of a unit counts :)

The original JS code didn't like this at all, so I've tweaked it using the Math.round() function use a full figure for calculations to determine the text and colour, but still reports the UV as a decimal.

Code: Select all

<script type="text/javascript">
var UV = 12;
var lookupVal = [0,0,0,1,1,1,2,2,2,3,3,3,4,4,4,4,4],
   lookupCol = ["#00FF00", "#FFFF00", "#FFA500", "#FF0000", "#FF66FF"],
   lookupTxt = ['Low','Medium','High','VERY HIGH','EXTREMELY HIGH'];
   if(lookupVal[Math.round(<#UV>)] >= 0){
      document.write("<span style='background-color: " +lookupCol[lookupVal[Math.round(<#UV>)]]+ 

";'>&nbsp;<#UV>/16&nbsp;" +lookupTxt[lookupVal[Math.round(<#UV>)]]+ "&nbsp;</span>");
   }else{
      document.write('unknown');
   }
</script>
</td>
Great thread guys.
Weather Spares - your one stop shop for complete stations and spare parts.
http://www.weatherspares.co.uk/
Post Reply