Author Topic: USNO having issues.. try beta get-USNO-sunmoon.php V3.00  (Read 461 times)

0 Members and 1 Guest are viewing this topic.

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6283
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
USNO having issues.. try beta get-USNO-sunmoon.php V3.00
« on: August 17, 2017, 11:54:17 AM »
It looks like the USNO api.usno.navy.mil server is having problems again today, and that causes non-Weather-Display template users an extra 5 seconds or so of page load time for home page and wxastronomy.php.

After several months of trying/tweaking, I think I found a good set of calculations to allow replacement of the USNO for moon times/sun times with a set of calculations.

This uses 3 classes with some mods from their originals.  One does phase/illumination, one does rise/set times and one (from Jachym) is used for moon transit times.

Try: https://saratoga-weather.org/wxtemplates/Test/get-USNO-sunmoon.php?sce=view

Put in Settings.php
Code: [Select]
$SITE['useUSNO'] = false;  // =false; use internal calcs, =true; use USNO Moon/Sun data
to activate the calculations instead of the fetch from USNO.

Let me know how it works for you (and if you see any PHP errata from using it).
« Last Edit: August 17, 2017, 11:56:27 AM by saratogaWX »
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline 92merc

  • BismarckWeather.net
  • Forecaster
  • *****
  • Posts: 577
  • BismarckWeather.net
    • BismarckWeather.net
Re: USNO having issues.. try beta get-USNO-sunmoon.php V3.00
« Reply #1 on: August 17, 2017, 12:09:21 PM »
I put the new get file up and the updated Settings.php.  Site is loading much faster now.

My almanac page shows 8:49 as sunset and the main page shows 8:50 pm.  I can live with that.  :-)
http://www.BismarckWeather.net
Davis VP2, Cumulus, Blitzortung, Bloomsky, Saratoga Scripts

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6283
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: USNO having issues.. try beta get-USNO-sunmoon.php V3.00
« Reply #2 on: August 17, 2017, 12:13:30 PM »
Yes, the times for sun/moon rise/set seem to be +/- 1 minute with the calculations.  It happens among the various weather software built-in calculations.  See the attached compare of calcs.

Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6283
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: USNO having issues.. try beta get-USNO-sunmoon.php V3.00
« Reply #3 on: August 17, 2017, 01:45:46 PM »
Finally got the USNO server to answer (with a 30 second timeout set), so here's the comparison with USNO v.s. all the calcs.

« Last Edit: August 17, 2017, 01:49:03 PM by saratogaWX »
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6283
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: USNO having issues.. try beta get-USNO-sunmoon.php V3.00
« Reply #4 on: October 11, 2017, 09:32:18 PM »
After several months of testing/tweaking, the get-USNO-sunmoon.php script has been revised to V3.00.

The major changes are:
1) switch to using curl to access api.usno.navy.mil API (better timeout control) and
2) addition of built-in calculations to supply sun/moon rise/set and moon %illumination and phase (thanks to Jachym and others for sharing the code!)

You can add a new setting to Settings.php where you can optionally switch the script from using the USNO to using the internal calculations.

$SITE['useUSNO'] = true;  // =true; default -- use the USNO api.usno.navy.mil JSON for data

$SITE['useUSNO'] = false; // =false: use the internal calculations and no access to the USNO api.usno.navy.mil server

Note that the internal calculations are within a couple of minutes of the more-accurate USNO data, and likewise the % illumination is within a couple percent.  For best accuracy, continue to use the USNO.  If the USNO server has issues, then switch to using the internal calculations to free your website page load from externally caused delays with the USNO server.

Standalone download  here

Saratoga template: use the update tool (Base-*, Plugin-*, 11-Oct-2017)
  (note that get-metar-conditions-inc.php V1.16 is included in the update, and for USA templates, advforecast2.php V5.04 (JSON) is included)

Best regards,
Ken
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline PaulMy

  • Forecaster
  • *****
  • Posts: 3699
    • KomokaWeather
Re: USNO having issues.. try beta get-USNO-sunmoon.php V3.00
« Reply #5 on: October 11, 2017, 10:56:29 PM »
Hi Ken,
I have updated.
If I add the new Settings as:
Quote
// Added 20171011 update
$SITE['useUSNO'] = false;  // =true; default -- use the USNO api.usno.navy.mil JSON for data
$SITE['useUSNO'] = true; // =false: use the internal calculations and no access to the USNO api.usno.navy.mil server
// End of added
then I get
Quote
Warning:  Invalid argument supplied for foreach() in /home/content/96/5379896/html/komokaweather-ca/get-USNO-sunmoon.php on line 359
 
 Warning:  Invalid argument supplied for foreach() in /home/content/96/5379896/html/komokaweather-ca/get-USNO-sunmoon.php on line 370

If I set the new settings as:
Quote
// Added 20171011 update
$SITE['useUSNO'] = true;  // =true; default -- use the USNO api.usno.navy.mil JSON for data
$SITE['useUSNO'] = false; // =false: use the internal calculations and no access to the USNO api.usno.navy.mil server
// End of added
then no message and looks fine(this is the settings I now have).

www.komokaweather.ca

Paul

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6283
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: USNO having issues.. try beta get-USNO-sunmoon.php V3.00
« Reply #6 on: October 11, 2017, 11:00:52 PM »
Hi Paul,

You only need one of the settings to be active.. the other should be commented out.  The last one (if both are included) will be the one used.

The warning messages you got with $SITE['useUSNO'] = true; as the last entry is likely due to having no JSON returned from the api.usno.navy.mil site .. You should try that again, and do a view-source of the page to see what the HTML comments about the fetch/processing say.
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline PaulMy

  • Forecaster
  • *****
  • Posts: 3699
    • KomokaWeather
Re: USNO having issues.. try beta get-USNO-sunmoon.php V3.00
« Reply #7 on: October 11, 2017, 11:26:56 PM »
Hi again Ken,
Not sure what to look for in the view-source. 
I am now using one of the lines only, and if set as false works ok, if set as true then the message.  I now have it as true and the message appears.

Paul

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6283
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: USNO having issues.. try beta get-USNO-sunmoon.php V3.00
« Reply #8 on: October 11, 2017, 11:36:40 PM »
Hi Paul,
I used view source on http://www.komokaweather.com/komokaweather-ca/wxastronomy.php

The script indicated a cache load and a JSON decode error.  I ran the page with ?cache=refresh and it loaded cleanly
Quote
<!-- get-USNO-sunmoon.php - Version 3.00 - 11-Oct-2017 -->
<!-- refetch seconds=1 -->
<!-- loading ./cache/USNO-moondata.txt from http://api.usno.navy.mil/rstt/oneday?date=10/11/2017&coords=42.9542444,-81.4348861&tz=-4 -->
<!-- curl fetching 'http://api.usno.navy.mil/rstt/oneday?date=10/11/2017&coords=42.9542444,-81.4348861&tz=-4' -->
<!-- HTTP stats:  RC=200 dest=199.211.133.93
      Times: dns=0.004 conn=0.096 pxfer=0.096 get=0.225 total=0.321 secs -->
<!-- loading finished. -->
<!-- processing JSON entries for Moon data -->
<!-- json_decode returns  - No errors -->
<!-- USNOdata
Array
(
    [beginciviltwilight] => 07:06
    [beginciviltwilightdate] => 11/10/2017
    [sunrise] => 07:35
    [sunrisedate] => 11/10/2017
    [suntransit] => 13:12
    [suntransitdate] => 11/10/2017
    [sunset] => 18:49
    [sunsetdate] => 11/10/2017
    [endciviltwilight] => 19:18
    [endciviltwilightdate] => 11/10/2017
    [moontransit] => 06:22
    [moontransitdate] => 11/10/2017
    [moonset] => 13:56
    [moonsetdate] => 11/10/2017
    [moonrise] => 23:47
    [moonrisedate] => 11/10/2017
    [moonriseprior] => 22:49
    [moonrisepriordate] => 10/10/2017
    [moonphase] => Waning Gibbous
    [illumination] => 60%
    [hoursofpossibledaylight] => 11:14
    [databy] => USNO
)
 -->
and cached the result.  Then a subsequent page load (without the ?cache=refresh) worked fine (no errors).

For grins, I tried the view source on the page with ?calc=y  and you can see the results of the calculated values as
Quote
<!-- get-USNO-sunmoon.php - Version 3.00 - 11-Oct-2017 -->
<!-- refetch seconds=3600 -->
<!-- useUSNO=false .. doing computation for values instead of USNO fetch -->
<!-- moonTransit 1507717320 -->
<!-- USNOdata
Array
(
    [illumination] => 54%
    [moonphase] => Last Quarter
    [moonrisedate] => 10/11/2017
    [moonrise] => 23:47
    [moonsetdate] => 10/11/2017
    [moonset] => 13:56
    [beginciviltwilightdate] => 10/11/2017
    [beginciviltwilight] => 07:07
    [sunrisedate] => 10/11/2017
    [sunrise] => 07:35
    [suntransitdate] => 10/11/2017
    [suntransit] => 13:12
    [sunsetdate] => 10/11/2017
    [sunset] => 18:48
    [endciviltwilightdate] => 10/11/2017
    [endciviltwilight] => 19:16
    [hoursofpossibledaylight] => 11:12
    [moontransitdate] => 10/11/2017
    [moontransit] => 06:22
    [databy] => calculated
)
 -->

I've attached a comparison of the USNO to various software sun/moon data (for my location).
« Last Edit: October 11, 2017, 11:42:04 PM by saratogaWX »
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP

Offline PaulMy

  • Forecaster
  • *****
  • Posts: 3699
    • KomokaWeather
Re: USNO having issues.. try beta get-USNO-sunmoon.php V3.00
« Reply #9 on: October 12, 2017, 12:10:18 AM »
Thanks Ken,
Message is gone.

Also tried view-source:http://www.komokaweather.com/komokaweather-ca/wxastronomy.php?calc=y and was able to find similar to what you posted.

Enjoy,
Paul

Offline saratogaWX

  • Administrator
  • Forecaster
  • *****
  • Posts: 6283
  • Saratoga, CA, USA Weather - free PHP scripts
    • Saratoga-Weather.org
Re: USNO having issues.. try beta get-USNO-sunmoon.php V3.00
« Reply #10 on: October 12, 2017, 09:52:56 AM »
Here's another capture of the comparisons USNO v.s. other software.  Better alignment today :)
Ken True/Saratoga, CA, USA main site: saratoga-weather.org
Davis VP1+ FARS, Boltek-PCI/NexStorm, microSferics ToA, Blitzortung RED, GRLevel3, WD, WL, VWS, Cumulus, Meteobridge/hub
Free weather PHP scripts/website templates - update notifications on Twitter saratogaWXPHP