Page 2 of 2
Re: UV reading from number to word
Posted: Sat 23 Feb 2013 7:34 pm
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>
Re: UV reading from number to word
Posted: Sat 23 Feb 2013 7:43 pm
by William Grimsley
Hi MarystownWeather2012,
I would go with the top piece of code in Mark's last post!
I'm glad that I could help,
William
Re: UV reading from number to word
Posted: Sat 23 Feb 2013 7:45 pm
by MarystownWeather2012
Thanks all I appreciate all your help on this.
Re: UV reading from number to word
Posted: Sat 23 Feb 2013 8:19 pm
by mcrossley
William Grimsley wrote:I would go with the top piece of code in Mark's last post!
Coward!
Re: UV reading from number to word
Posted: Sat 23 Feb 2013 8:34 pm
by William Grimsley
mcrossley wrote:William Grimsley wrote:I would go with the top piece of code in Mark's last post!
Coward!
Ok, I don't find that funny, at all. I'm not a coward...
Re: UV reading from number to word
Posted: Sat 23 Feb 2013 8:57 pm
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.
Re: UV reading from number to word
Posted: Sat 23 Feb 2013 9:54 pm
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!
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!
Thanks,
William
Re: UV reading from number to word
Posted: Sat 23 Feb 2013 11:02 pm
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.
Re: UV reading from number to word
Posted: Sun 24 Feb 2013 12:02 am
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>]]+ ";'> <#UV>/16 " +lookupTxt[lookupVal[<#UV>]]+ " </span>");
}else{
document.write('unknown');
}
</script>
</td>
@ william ..... Don't even think about it
Re: UV reading from number to word
Posted: Tue 26 Feb 2013 12:22 pm
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>)]]+
";'> <#UV>/16 " +lookupTxt[lookupVal[Math.round(<#UV>)]]+ " </span>");
}else{
document.write('unknown');
}
</script>
</td>
Great thread guys.