Page 2 of 2
Re: UV colour depending on the number ie None Low Medium High Very High
Posted: Tue 07 Jun 2022 3:03 pm
by dazza1223
HansR wrote: ↑Tue 07 Jun 2022 2:16 pm
mcrossley wrote: ↑Tue 07 Jun 2022 2:11 pm
freddie wrote: ↑Tue 07 Jun 2022 2:03 pm
Do you need to declare uvword before the first if statement? Sorry, I'm not very au fait with javascript.
Yes it would be best to do that...
Code: Select all
var uv = rawdata[45];
var uvword;
if (uv=="0"){ uvword="None";} else
if (uv=="3"){ uvword="<span ...
All true but I don't think it is the cause of failing.
Maybe @dazza could elaborate on what exactly fails? Does it show anything in the UVone element or does it show erroneous something?
As you compare strings is that truly the content of the rawdata or is it e.g. "0 " with as result the if statements all fail and you get an empty string in the html element. If uncertain add a console.log statement after each if-clause to see something.
Or go to stackoverflow.
Sorry ive just just upload a test page to my site as i was doing all off line....
so if you can take a look you can see now ? and for the output nope nothing and the rawdata is the realtime.txt line 44 but it 45 as it count from 1
https://www.davisworthing.co.uk/test.php
Re: UV colour depending on the number ie None Low Medium High Very High
Posted: Tue 07 Jun 2022 3:05 pm
by mcrossley
or JavaScript is fun and fluid and lets you get away with all sorts of stuff. TypeScript - boo!

Re: UV colour depending on the number ie None Low Medium High Very High
Posted: Tue 07 Jun 2022 3:09 pm
by mcrossley
Dazza, I do not see any content on your test page, but wow! That is some refresh rate - every 20 milliseconds!
You problem now is the UV value you are comparing against seems to be the UVI * 100. The value currently is 160, so that falls through to your last clause where uvword=""
Re: UV colour depending on the number ie None Low Medium High Very High
Posted: Tue 07 Jun 2022 3:24 pm
by HansR
mcrossley wrote: ↑Tue 07 Jun 2022 3:05 pm
or JavaScript is fun and fluid and lets you get away with all sorts of stuff. TypeScript - boo!

That's why it is so popular. I am a fan!
Re: UV colour depending on the number ie None Low Medium High Very High
Posted: Tue 07 Jun 2022 3:26 pm
by dazza1223
mcrossley wrote: ↑Tue 07 Jun 2022 3:09 pm
Dazza, I do not see any content on your test page, but wow! That is some refresh rate - every 20 milliseconds!
You problem now is the UV value you are comparing against seems to be the UVI * 100. The value currently is 160, so that falls through to your last clause where uvword=""
woops yh just spotted that 20 milliseconds
and the UV in the realtime.txt reads like 1.5
so maybe like this
if (uv=="1.5"){ uvword="<span style=\"border: solid 1px; color: black; background-color: #A4CE6a;\"> Low </span>";} else
Re: UV colour depending on the number ie None Low Medium High Very High
Posted: Tue 07 Jun 2022 3:31 pm
by HansR
freddie wrote: ↑Tue 07 Jun 2022 2:32 pm

that's why I only touch it when necessary
To the point image
Re: UV colour depending on the number ie None Low Medium High Very High
Posted: Tue 07 Jun 2022 3:55 pm
by mcrossley
Your script is reading field 45 for the UV, that is the Solar Rad value, UV is in field 43.
Re: UV colour depending on the number ie None Low Medium High Very High
Posted: Tue 07 Jun 2022 4:04 pm
by dazza1223
im going bye this
https://cumuluswiki.org/a/Realtime.txt
44 13 UV Index <#UV>
but ive have tried 43/44 but it doesn't seem to work
Re: UV colour depending on the number ie None Low Medium High Very High
Posted: Tue 07 Jun 2022 4:54 pm
by mcrossley
The Wiki uses 1 relative field field numbers, your code uses 0 relative, it should be 43.
You next problem is you if statements, they are doing compares against specific values. I think what you intended was to use >= rather than ==
I'd also drop the use of strings in your compares and use exact numeric comparisons rather than relying on JS laxness that Freddie loves!
Maybe another day for that.
Re: UV colour depending on the number ie None Low Medium High Very High
Posted: Tue 07 Jun 2022 4:54 pm
by mcrossley
mcrossley wrote: ↑Tue 07 Jun 2022 4:54 pm
The Wiki uses 1 relative field field numbers, your code uses 0 relative, it should be 43.
You next problem is you if statements, they are doing compares against specific values. I think what you intended was to use <= rather than ==
I'd also drop the use of strings in your compares and use exact numeric comparisons rather than relying on JS laxness that Freddie loves!
Maybe another day for that.
Re: UV colour depending on the number ie None Low Medium High Very High
Posted: Tue 07 Jun 2022 5:02 pm
by freddie
mcrossley wrote: ↑Tue 07 Jun 2022 4:54 pm rather than relying on JS laxness that Freddie loves!

Re: UV colour depending on the number ie None Low Medium High Very High
Posted: Tue 07 Jun 2022 5:15 pm
by mcrossley
Oh go on I'll do it, just to close the thread!
Code: Select all
var uv = rawdata[43] * 1;
var uvword;
if (uv<=0){ uvword="None";} else
if (uv<=3){ uvword="<span style=\"border: solid 1px; color: black; background-color: #A4CE6a;\"> Low </span>";} else
if (uv<=6){ uvword="<span style=\"border: solid 1px; color: black; background-color: #FBEE09;\"> Medium </span>";} else
if (uv<=8){ uvword="<span style=\"border: solid 1px; color: black; background-color: #FD9125;\"> High </span>";} else
if (uv<=11){var uvword="<span style=\"border: solid 1px; color: #FFFFFF; background-color: #F63F37;\"> Very High </span>";} else
{ uvword="eek!";}
$("#UVone").html(uvword);
Re: UV colour depending on the number ie None Low Medium High Very High
Posted: Tue 07 Jun 2022 8:55 pm
by dazza1223
sorry mark but i got busy with things so i dint see your last post..... but thank you so much i knew what you meant by it but thank you for doing it for me