Author Topic: I would like to have the IMPERIAL/METRIC switch in my VWS script  (Read 1052 times)

0 Members and 1 Guest are viewing this topic.

Offline mexbound

  • Senior Member
  • **
  • Posts: 66
First off, I am very new to all of this Saratoga templates, etc.  I did implement the Saratoga World template using the VWS addon. Everything is working great. Because I am now in Mexico I would like to use the IMPERIAL/METRIC switch usually shown near the top of the index page. I have seen some scripts with the "WD" using this but I was wondering if anyone has done this with VWS.  Can someone point me in the right direction to maybe let me implement the option in my Saratoga World base template?

Thanks so much for any help.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9288
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: I would like to have the IMPERIAL/METRIC switch in my VWS script
« Reply #1 on: April 06, 2021, 12:19:00 AM »
Alas, currently the alternative-dashboard (with the Imperial/Metric tabs) only works with WD testtags.php -- VWS doesn't produce enough weather tags to make that work.  I do know that WeeWX has an extension that creates WD-style testtags.php, so it could be used with the alt-dashboard.

But.. I've not heard about a alt-dashboard that works with any other weather software than the two above.  Sorry.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline mexbound

  • Senior Member
  • **
  • Posts: 66
Re: I would like to have the IMPERIAL/METRIC switch in my VWS script
« Reply #2 on: April 06, 2021, 03:20:35 PM »
Thank you very much for the response.  I may take a look at Weather-Display software to see how it works.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9288
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: I would like to have the IMPERIAL/METRIC switch in my VWS script
« Reply #3 on: April 06, 2021, 05:31:55 PM »
If you wait a bit, in less than one week, there will be a WeeWX plugin to the template that fully supports the alternative dashboard for Imperial/Metric
We're putting the finishing touches on it right now.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline mexbound

  • Senior Member
  • **
  • Posts: 66
Re: I would like to have the IMPERIAL/METRIC switch in my VWS script
« Reply #4 on: April 06, 2021, 05:46:36 PM »
So I am a "Windows guy" and really do not know Linux, nor do I have a computer to run Linux on.  Will  WeeWX run on Windows?

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9288
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: I would like to have the IMPERIAL/METRIC switch in my VWS script
« Reply #5 on: April 06, 2021, 07:04:23 PM »
Some intrepid souls have run WeeWX on Windows, but it's really for the *nix platform.  It can run on a Raspberry Pi quite easily (I run one Pi with it now).  If you want to stick with Windows, then the Windows version of Weather-Display will fit the bill and let you run the alternative dashboard in the Saratoga template for Imperial/Metric display)
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline mexbound

  • Senior Member
  • **
  • Posts: 66
Re: I would like to have the IMPERIAL/METRIC switch in my VWS script
« Reply #6 on: April 06, 2021, 07:16:02 PM »
I might be willing to try getting an R-Pi and give it a go. I'm retired and have lots of time.  Is there somewhere you can point me to what R-Pi I should buy and instructions to install WeeWX on it?  Just confirming it will connect to a Davis Weather logger to get the data?

Offline gwwilk

  • Southeast Lincoln Weather
  • Forecaster
  • *****
  • Posts: 2578
    • SouthEast Lincoln, NE Weather
Re: I would like to have the IMPERIAL/METRIC switch in my VWS script
« Reply #7 on: April 07, 2021, 05:34:41 AM »
As if you didn't already have enough to do, Ken, there is one flaw in the Alt-Dashboard Imperial/Metric switching scheme that I couldn't fix:  The temperatures associated with the NWS forecast.  These come from advforecast2.php and while I have been able to modify this script's display to my taste I didn't see how this script could be incorporated into the Imperial/Metric switching scheme.  Crucial to any switching scheme is the appropriate modification of ajaxWDwx.js, or ajaxXXwx.js, along with the dashboard.  My last mods there dealt with making firedangerWD.php a real-time graphic on my alt-dashboard.

BTW, thanks for the revised wxnwsradar script set, Ken.  It works great!
Regards, Jerry Wilkins
gwwilk@gmail.com

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9288
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: I would like to have the IMPERIAL/METRIC switch in my VWS script
« Reply #8 on: April 07, 2021, 03:05:27 PM »
I might be willing to try getting an R-Pi and give it a go. I'm retired and have lots of time.  Is there somewhere you can point me to what R-Pi I should buy and instructions to install WeeWX on it?  Just confirming it will connect to a Davis Weather logger to get the data?
Yes, WeeWX will connect to a Davis logger (serial, USB or IP).  I'd suggest buying a 'kit' of Raspberry Pi.  A RPi3+ would do nicely, and Amazon has a variety of kits .. pick one with a case, power supply, HDMI cable, and 8 to 32Gb SD card.  You'll need a USB keyboard, and a HDMI display.  Install the 'lite' version of the operating system .. you'll just use command line entries (like Windows DOS/CMD commands) to install/configure the operating system, and WeeWX. 
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9288
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: I would like to have the IMPERIAL/METRIC switch in my VWS script
« Reply #9 on: April 07, 2021, 03:11:29 PM »
As if you didn't already have enough to do, Ken, there is one flaw in the Alt-Dashboard Imperial/Metric switching scheme that I couldn't fix:  The temperatures associated with the NWS forecast.  These come from advforecast2.php and while I have been able to modify this script's display to my taste I didn't see how this script could be incorporated into the Imperial/Metric switching scheme.  Crucial to any switching scheme is the appropriate modification of ajaxWDwx.js, or ajaxXXwx.js, along with the dashboard.  My last mods there dealt with making firedangerWD.php a real-time graphic on my alt-dashboard.
Ahh.. challenge accepted :)

I'm readying an update to ajax-dashboard6.php V6.92d with support for WeeWX, so I thought I'd mess about with some Imperial/Metric foibles.
Fixed a bunch, and added support for all the Saratoga forecast scripts, and--enabled Imperial/Metric switching on the forecast temperatures.

See a sample at https://saratoga-weather.org/weewx/wxindex.php   (and you can kick the tires on the work in progress at https://saratoga-weather.org/weewx/ajax-dashboard6.php?sce=view)
Quote
BTW, thanks for the revised wxnwsradar script set, Ken.  It works great!
Glad it works.. thanks for letting me mangle your original script to function with the new images.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline gwwilk

  • Southeast Lincoln Weather
  • Forecaster
  • *****
  • Posts: 2578
    • SouthEast Lincoln, NE Weather
Re: I would like to have the IMPERIAL/METRIC switch in my VWS script
« Reply #10 on: April 07, 2021, 03:33:57 PM »
You never cease to amaze me, Ken!  =D> Your mods to display the forecasted temps as Imperial/Metric are working just fine on your WeeWx testing dashboard.  The function reformat_forecast_temp($intemp) is apparently the key, but everything appears to be commented out there. :?:

I'm eager to see the finished product.  [tup]
Regards, Jerry Wilkins
gwwilk@gmail.com

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9288
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: I would like to have the IMPERIAL/METRIC switch in my VWS script
« Reply #11 on: April 07, 2021, 06:05:48 PM »
Actually, the reformat_forecast_temp() function has a lot of comments (showing the values from various forecast programs), but does have the 'meat' code of
Code: [Select]
<?php
  
function reformat_forecast_temp($intemp) {
// change 
// NWS: 'Hi <span style="color: #FF0000;">66 &deg;F &darr;</span>' to
// to   'Hi <span style="color: #FF0000;"><span class="convTemp>66 &deg;F</span> &darr;</span>'

// WXSIM '<span style="color: blue">Low: 43&deg;</span>'
// to    '<span style="color: blue">Low: <span class="convTemp">43&deg;F</span></span>'

// WCFcst '<span style="color: #ff0000;">66&deg;F</span>'
// to     '<span style="color: #ff0000;"><span class="convTemp">66&deg;F</span></span>'

// AWfcst '<span style="color: #ff0000;">18.9&deg;C</span>'
// to     '<span style="color: #ff0000;"><span class="convTemp">18.9&deg;C</span></span>'

// DSfcst '<span style="color: #ff0000;">18&deg;C</span><br/><span style="color: #0000ff;">6&deg;C</span>'
// to     '<span style="color: #ff0000;"><span class="convTemp">18&deg;C</span></span><br/><span style="color: #0000ff;"><span class="convTemp">6&deg;C</span></span>'

    
global $uomTemp;
    
$t str_replace('&deg;<',$uomTemp.'<',$intemp); // handle WXSIM w/no uom

    
$t preg_replace_callback('!([\d]+)\s*&deg;(F|C)!Us',
  function ($M) {
return '<span class="convTemp">'.$M[1].'&deg;'.$M[2].'</span>';
},
$t);
    print 
"<!-- reformat_forecast\n in='$intemp'\nout='$t' -->\n";
return $t;
}
?>

the preg_replace_callback() function does the 'heavy lifting' by surrounding the actual temperature values (with units) in a
<span class="convTemp"></span> which ajaxWDwx3.js then handles the temperature conversion as needed.  Only WXSIM temperatures (that have no units) needed a bit of special handling to put the $uomTemp unit in the HTML first, before the preg_replace_callback() does the <span> insertion.  Fairly cool.. just two lines of operative code to handle getting it ready for the AJAX script to process as needed.

Then, for every
Code: [Select]
<?php echo $forecasttemp[N]; ?> now becomes
Code: [Select]
<?php echo reformat_forecast_temp($forecasttemp[N]); ?> to make the HTML.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline gwwilk

  • Southeast Lincoln Weather
  • Forecaster
  • *****
  • Posts: 2578
    • SouthEast Lincoln, NE Weather
Re: I would like to have the IMPERIAL/METRIC switch in my VWS script
« Reply #12 on: April 07, 2021, 06:17:10 PM »
I see, said the blind man!  Very clever and parsimonious.  And very ‘Ken’.  =D&gt;
Regards, Jerry Wilkins
gwwilk@gmail.com

Offline gwwilk

  • Southeast Lincoln Weather
  • Forecaster
  • *****
  • Posts: 2578
    • SouthEast Lincoln, NE Weather
Re: I would like to have the IMPERIAL/METRIC switch in my VWS script
« Reply #13 on: April 08, 2021, 08:54:35 AM »
I decided to modify my dashboard by incorporating your clever changes, Ken.

It works!!!  All of the advforecast2-derived temps now switch METRIC<=>Imperial.
Regards, Jerry Wilkins
gwwilk@gmail.com

Offline gwwilk

  • Southeast Lincoln Weather
  • Forecaster
  • *****
  • Posts: 2578
    • SouthEast Lincoln, NE Weather
Re: I would like to have the IMPERIAL/METRIC switch in my VWS script
« Reply #14 on: April 08, 2021, 12:08:31 PM »
I discovered that my 'Daytime Records' and 'Nighttime Records' were hosed using your revised fix_record2() function. So I reverted to my original fix_record2() which fixed the problem.

Maybe due to my insistence on using
Code: [Select]
$timeOnlyFormat = 'g:i A'; // h:mm [AM|PM];
rather than
Code: [Select]
$timeOnlyFormat = 'g:ia';    // h:mm[am|pm];
to format the time?
Regards, Jerry Wilkins
gwwilk@gmail.com

Offline mexbound

  • Senior Member
  • **
  • Posts: 66
Re: I would like to have the IMPERIAL/METRIC switch in my VWS script
« Reply #15 on: April 28, 2021, 11:09:35 AM »
Ok, I have my Raspberry PI setup and running WeeWx. Wasn't to difficult if you follow all the setup directions. In post #9 above you mentioned you were working on an update for the alt dashboard (ajax-dashboard6.php V6.92d with support for WeeWX). Just wondering how it is going.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 9288
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: I would like to have the IMPERIAL/METRIC switch in my VWS script
« Reply #16 on: April 28, 2021, 11:29:14 AM »
Gary and I are still working on the weewx-saratoga plugin for WeeWX and Saratoga templates.
You can try a preliminary copy of the ajax-dashboard6.php V6.92d from here and the updated ajaxWDwx3.js from here and see how it looks here.

When Gary says he's finished with the weewx-saratoga plugin for release, I'll package up the WEEWX-plugin/docs and Alternative dashboard for release.  Should be soon now :)
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

 

anything