Author Topic: Anyone played with an HTML version of If/then type statements?  (Read 5514 times)

Steve

  • Global Moderator
  • Storm
  • *****
  • Posts: 1333
    • DW8454
    • KOHAVON11
    • Avon Weather
  • Station Details: Davis Wireless VP2 Plus w/24 hr FARS, Leaf & Soil Station, 2017 27" iMac 3.8 GHz i5, 40GB RAM, Mac OS 10.14, WeatherCat 3
Anyone played with an HTML version of If/then type statements?
« on: October 12, 2012, 04:25:54 AM »
I haven't looked yet to see if such a critter exists, but I thought I'd ask instead of reinventing the wheel. I picked up a Davis UV sensor this week, and I want to fiddle with doing an image swapping scheme on my web page.

I'd like to have several copies the UV Index scale with an arrow pointing at different numbers on each. Then have some sort of If/Then type statement substitute the appropriate image for the current UV index reading.

I'll spend some time tomorrow looking at this, but thought someone may already have done something similar, so I thought I'd ask.

Thanks,
Steve
Steve - Avon, Ohio, USA


CWOP: DW8454 • WU: KOHAVON11 • AWEKAS • CoCoRaHS • Skywarn •  UK Met Office
MWWN •PWSweather • WeatherBug • WeatherCloud • Twitter • Facebook

HairyMcLeary

  • Strong Breeze
  • ***
  • Posts: 164
    • DW5912
    • INORTHOT6
  • Station Details: LaCrosse WS2355, iMac 2.66 Ghz Core 2 Duo, 8 GB RAM, Mountain Lion
Re: Anyone played with an HTML version of If/then type statements?
« Reply #1 on: October 12, 2012, 11:41:56 AM »
How does WC report UV in its web tags? if it is an integer it would be a simple matter of having an image for each result.

I used to do this for a current condition icon. CC being the current condition, I simply put CC.jpg in my HTML  template and images named with all of the various permutations that the Current conditions could be. When WC updated the webtags it replaced CC in the image name. There were less than 10 so it wasn't too much of a task.

If the UV is reported in integers  then it shouldn't be difficult to use this method

This could  also be done using PHP if your server allows it.
The Saratoga template uses similar kinds of arguments to substitute images for conditions, UV etc. You may be able to modify this to suit your needs.

An AppleScript could be used to convert he UV result to integers if WC doesn't report them in this way.

Tony

Steve

  • Global Moderator
  • Storm
  • *****
  • Posts: 1333
    • DW8454
    • KOHAVON11
    • Avon Weather
  • Station Details: Davis Wireless VP2 Plus w/24 hr FARS, Leaf & Soil Station, 2017 27" iMac 3.8 GHz i5, 40GB RAM, Mac OS 10.14, WeatherCat 3
Re: Anyone played with an HTML version of If/then type statements?
« Reply #2 on: October 12, 2012, 01:47:37 PM »
Interesting idea, Tony!

WeatherCat reports UV Index with one decimal point, s oI'd have to do some rounding somehow. I've asked Stu if he could add an option for UV as an integer.

So, you're suggesting something like this?

Template: <IMG SRC="uvtag_UV$.gif">

Populated Template: <IMG SRC="uvtag_4.gif">

Web Page:

If that works, it would be very simple! Now to get it to an integer.

Thanks,
Steve
Steve - Avon, Ohio, USA


CWOP: DW8454 • WU: KOHAVON11 • AWEKAS • CoCoRaHS • Skywarn •  UK Met Office
MWWN •PWSweather • WeatherBug • WeatherCloud • Twitter • Facebook

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 5295
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
JavaScript and PHP should do this. (Re: of If/then type statements?)
« Reply #3 on: October 12, 2012, 05:55:34 PM »
Hi Steve, Tony and WeatherCat fans,

WeatherCat reports UV Index with one decimal point, s oI'd have to do some rounding somehow. I've asked Stu if he could add an option for UV as an integer.

I'm sure you could incorporate a snippet of JavaScript to do the conversion to an integer.  That way it would run on virtually any website and browser. If you are using Tigers web templates, then PHP most certainly has an integer conversion.  That way Stu wouldn't have to create another tag.

Sorry, I'm struggling with a family mishap so I can't do any digging for you, but some quickie web surfing should give you some examples to go by.

Cheers, Edouard  [cheers1]

HairyMcLeary

  • Strong Breeze
  • ***
  • Posts: 164
    • DW5912
    • INORTHOT6
  • Station Details: LaCrosse WS2355, iMac 2.66 Ghz Core 2 Duo, 8 GB RAM, Mountain Lion
Re: Anyone played with an HTML version of If/then type statements?
« Reply #4 on: October 12, 2012, 09:57:11 PM »
Interesting idea, Tony!

WeatherCat reports UV Index with one decimal point, s oI'd have to do some rounding somehow. I've asked Stu if he could add an option for UV as an integer.

So, you're suggesting something like this?

Template: <IMG SRC="uvtag_UV$.gif">

Populated Template: <IMG SRC="uvtag_4.gif">

Web Page:

If that works, it would be very simple! Now to get it to an integer.

Thanks,
Steve
That's the idea, as Edouard has mentioned, you can use java to do the conversion to integer.

I used java script to determine the time of day so that my page would display either day or night time icons. There are heaps of examples and tutorials out there for this kind of thing.

Tony

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 5295
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
If that works, it would be very simple! Now to get it to an integer.

Actually what you are trying to do is very similar to what is on my website to make the barometric trend pointer work.  I just did this "by hand" but this little JavaScript function:

Code: [Select]
function ChooseUVIcon(FilenamePrefix,UVvalue) {
    var UVinteger;
    UVinteger=Math.round(UVvalue);
    document.writeln("<img style=\" width: 30px; height: 30px;\" src=\"", FilenamePrefix, UVinteger, ".gif\">");
}

Can be used to create the text that is equivalent to your HTML: <IMG SRC="uvtag_UV$.gif">.

At the place where you want the image to be inserted, you need to instead call the JavaScript function like this:

<script type="text/javascript">ChooseUVIcon("uvtag_","UV$")</script>

When you call the function, it will create the HTML tag to load the image.  This isn't the most convenient, but I've never managed to get JavaScript to return a value that can be inserted into the HTML source-code.  Perhaps, my weak JavaScript knowledge is letting me down.  I left some image tweaking style settings in my function example so that you would see how to add that stuff for your particular needs.  Also, I just gave you the raw JavaScript function.  If you have a file of JavaScript functions already, you can tack it to the end of that.  Otherwise you can either keep it in a separate file and include it with a JavaScript command like this:

<script type="text/javascript" src="dynamic_content.js">

Of you can use the same HTML wrappers: <script type="text/javascript"> . . . . </script> and declare the function in your HTML file itself.

Let me know if that helps!

Cheers, Edouadr  [cheers1]

Steve

  • Global Moderator
  • Storm
  • *****
  • Posts: 1333
    • DW8454
    • KOHAVON11
    • Avon Weather
  • Station Details: Davis Wireless VP2 Plus w/24 hr FARS, Leaf & Soil Station, 2017 27" iMac 3.8 GHz i5, 40GB RAM, Mac OS 10.14, WeatherCat 3
Re: Anyone played with an HTML version of If/then type statements?
« Reply #6 on: October 13, 2012, 12:47:53 AM »
Thanks so much, guys! I haven't had time to check into this yet, but I do appreciate the ideas. I'll get on this over the next few days.

I've been planting my two extra soil moisture sensors and soil temperature probes today, and modifying my soil web page. I've been in conversation with a local Cleveland meteorologist that's looking for soil data at 2" and 4" to help with early snow accumulation predictions. I had these ready to install in the spring, so I might as well put them to use now!

Edouard, I hope whatever family mishap occurred isn't serious. Certainly take care of personal stuff before hanging out here with us!

Thanks!
Steve
Steve - Avon, Ohio, USA


CWOP: DW8454 • WU: KOHAVON11 • AWEKAS • CoCoRaHS • Skywarn •  UK Met Office
MWWN •PWSweather • WeatherBug • WeatherCloud • Twitter • Facebook

Steve

  • Global Moderator
  • Storm
  • *****
  • Posts: 1333
    • DW8454
    • KOHAVON11
    • Avon Weather
  • Station Details: Davis Wireless VP2 Plus w/24 hr FARS, Leaf & Soil Station, 2017 27" iMac 3.8 GHz i5, 40GB RAM, Mac OS 10.14, WeatherCat 3
Re: Anyone played with an HTML version of If/then type statements?
« Reply #7 on: October 20, 2012, 11:16:55 PM »
Got it! I tried some combinations of you guys' suggestions, as well as what I was finding on various javascript tutorials, but couldn't get any of them to work. I could get the rounding combined with the tag, and the IMG HTML tag working with the UV images, but I couldn't combine them. I found what I needed thanks to a couple of the programming guys over at Stack Overflow.

Code: [Select]
<img id="uv_index" />
<script type="text/javascript">
    var imgSrc = "images/UV/UV_" + Math.round(STAT$UV:CURRENT$) + ".gif";
    document.getElementById("uv_index").setAttribute('src', imgSrc);
</script>

That's pretty similar to what you included, Edouard, but without the function call. Some of them were saying document.write is to be avoided now, although not completely deprecated. I've got it working on a test page. Now I just need to decide where to put it on my web site, and then link it to a UV Index reference site.

Thanks for the help!
Steve
Steve - Avon, Ohio, USA


CWOP: DW8454 • WU: KOHAVON11 • AWEKAS • CoCoRaHS • Skywarn •  UK Met Office
MWWN •PWSweather • WeatherBug • WeatherCloud • Twitter • Facebook

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 5295
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Glad you've got it working! (Re: HTML version of If/then type statements?)
« Reply #8 on: October 20, 2012, 11:36:03 PM »
Howdy Steve and WeatherCat tinkerers,

Got it! I tried some combinations of you guys' suggestions, as well as what I was finding on various javascript tutorials, but couldn't get any of them to work. I could get the rounding combined with the tag, and the IMG HTML tag working with the UV images, but I couldn't combine them. I found what I needed thanks to a couple of the programming guys over at Stack Overflow.

Glad you got it working!  JavaScript is most definitely not my cup of tea.

That's pretty similar to what you included, Edouard, but without the function call. Some of them were saying document.write is to be avoided now, although not completely deprecated. I've got it working on a test page. Now I just need to decide where to put it on my web site, and then link it to a UV Index reference site.

Thanks for the tip.  I hope not to write much JavaScript anyway, but if I do that's one more thing to keep in mind.

Cheers, Edouard  [cheers1]

Steve

  • Global Moderator
  • Storm
  • *****
  • Posts: 1333
    • DW8454
    • KOHAVON11
    • Avon Weather
  • Station Details: Davis Wireless VP2 Plus w/24 hr FARS, Leaf & Soil Station, 2017 27" iMac 3.8 GHz i5, 40GB RAM, Mac OS 10.14, WeatherCat 3
Re: Anyone played with an HTML version of If/then type statements?
« Reply #9 on: October 22, 2012, 03:00:48 AM »
I've added the UV graphic to my web page now. I originally had a blank image for zero UV when all I had was the graphic. (If you can't see it, there must not be any UV.) But I added a link to an explanation of the UV Index, so decided to make an ugly zero one as well.

While I was at it, I decided to redo my menu bar. You may recall I had it arranged so that whatever page you click, the "Home" button was under your mouse once the new page loaded. This was fine when there were only three or four, but I decided I didn't like having to look for the other tabs in different places each time. So I now have all of them the same on all pages. The only oddity is that you can only get "to" the glossary from the text link on the front page, but it has the normal menu scheme to get to any other page.

I also finally added a link to the Soil Station data page. It is still a jumbled work in progress, but I figured I'd make it easier for the local meteorologist to get there when he needed the information.

So, take a peek at Avon-Weather.com and see what you think! (I could use the clicks. I've dropped out of the top 100. ;) ) Not now, though. It's dark and you'll see my ugly 0 UV graphic.

Thanks again for all the help!
Steve
Steve - Avon, Ohio, USA


CWOP: DW8454 • WU: KOHAVON11 • AWEKAS • CoCoRaHS • Skywarn •  UK Met Office
MWWN •PWSweather • WeatherBug • WeatherCloud • Twitter • Facebook

Jace

  • Storm
  • *****
  • Posts: 811
    • DW9675
    • ISuffolk62
    • Yoxford weather site.
  • Station Details: Davis Vantage Pro2, with Mac USB Data Logger. 2.4 GHz Intel Core 2 Duo MacBook, with 8 GB 1033 MHz DDR3 Memory, running Mac OSX Version 10.10.1 (Yosimite).
Re: Anyone played with an HTML version of If/then type statements?
« Reply #10 on: October 22, 2012, 10:43:44 AM »

So, take a peek at Avon-Weather.com and see what you think! (I could use the clicks. I've dropped out of the top 100. ;) ) Not now, though. It's dark and you'll see my ugly 0 UV graphic.

Strange the link to your site does not work Steve, but I can access ok with my saved bookmark.  [tup] The soil data page looks good !  :)


JC

Steve

  • Global Moderator
  • Storm
  • *****
  • Posts: 1333
    • DW8454
    • KOHAVON11
    • Avon Weather
  • Station Details: Davis Wireless VP2 Plus w/24 hr FARS, Leaf & Soil Station, 2017 27" iMac 3.8 GHz i5, 40GB RAM, Mac OS 10.14, WeatherCat 3
Re: Anyone played with an HTML version of If/then type statements?
« Reply #11 on: October 22, 2012, 01:50:26 PM »

Strange the link to your site does not work Steve

Oops, I had two sets of http:// in the link. Thanks for pointing out my error.

The soil page is still a hodge-podge of graphs. I need to better define the centibar readings and what "normal" ranges are. It probably isn't useful to anyone without some knowledge of weather/soil nomenclature.

Thanks for looking,
Steve
Steve - Avon, Ohio, USA


CWOP: DW8454 • WU: KOHAVON11 • AWEKAS • CoCoRaHS • Skywarn •  UK Met Office
MWWN •PWSweather • WeatherBug • WeatherCloud • Twitter • Facebook

elagache

  • Global Moderator
  • Storm
  • *****
  • Posts: 5295
    • DW3835
    • KCAORIND10
    • Canebas Weather
  • Station Details: Davis Vantage Pro-2, Mac mini (2018), macOS 10.14.3, WeatherCat 3
Looking good Steve! (Re: HTML version of If/then type statements?)
« Reply #12 on: October 22, 2012, 09:12:36 PM »
Howdy Steve, JC, and WeatherCat fans,  [cat]

So, take a peek at Avon-Weather.com and see what you think!

Just made a quick cruise through the various links and it still looks neat and professional looking.  I saw that you put a disclaimer tell visitors that you are not a professional and they should consult "weather professionals" should they need reliable information.  Your website looks good enough that a casual viewer could well be fooled!! 

Great job Steve!  [tup]

Cheers, Edouard  [cheers1]