Skip to content

Commit 5f038ae

Browse files
committed
Re-order ajaxweewx() and weather record snapshot now owned by moment.js for locale
Updates #56
1 parent 1ad7039 commit 5f038ae

File tree

1 file changed

+77
-76
lines changed

1 file changed

+77
-76
lines changed

Diff for: skins/Belchertown/index.html.tmpl

+77-76
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
var moment_locale = "$system_locale".substring(0, 2);
1919
moment.locale(moment_locale); // "en" or "de", etc.
2020

21+
ajaxweewx(); // Initial call. Load from weewx (date, daily high, low, etc)
22+
2123
#if $Extras.has_key("forecast_enabled") and $Extras.forecast_enabled == '1'
2224
// Load forecast
2325
ajaxforecast(); // Initial call. Load forecast data like 8 day outlook, weather icon and observation text
@@ -41,7 +43,6 @@
4143
#end if
4244

4345
#if $Extras.has_key("mqtt_enabled") and $Extras.mqtt_enabled == '1'
44-
ajaxweewx(); // Initial call. Load from weewx (daily high, low, etc)
4546
connect(); // Begin mqtt after weewx initial load
4647
// If the Restart button is clicked, reconnect to mqtt and update weewx and forecast data
4748
jQuery(document).on('click', '.restart-interval', function() {
@@ -194,6 +195,79 @@
194195
cache:false
195196
});
196197

198+
function ajaxweewx() {
199+
jQuery.getJSON("$belchertown_root_url/json/weewx_data.json", update_weewx_data);
200+
};
201+
202+
// Update weewx data elements
203+
function update_weewx_data( data ) {
204+
console.log("Updating weewx data");
205+
// Daily High Low
206+
high = data["day"]["outTemp"]["max"];
207+
low = data["day"]["outTemp"]["min"];
208+
jQuery(".high").html( high );
209+
jQuery(".low").html( low );
210+
211+
// Barometer trending by finding a negative number
212+
count = ( data["current"]["barometer_trend"].match(/-/g) || [] ).length
213+
214+
if ( count >= 1 ) {
215+
jQuery(".wx-barometer-trend").html( '<i class="fa fa-arrow-down barometer-down"></i>' );
216+
} else {
217+
jQuery(".wx-barometer-trend").html( '<i class="fa fa-arrow-up barometer-up"></i>' );
218+
}
219+
220+
// Current wind gust
221+
jQuery(".curwindgust").text( parseFloat( data["current"]["windGust"] ).toFixed(1) );
222+
223+
// Daily max gust span
224+
jQuery(".dailymaxgust").html( parseFloat( data["day"]["wind"]["max"] ).toFixed(1) );
225+
226+
// Daily stats section
227+
jQuery(".snapshot-records-today-header").html( moment.unix( data["current"]["epoch"] ).format( 'dddd, LL' ) );
228+
jQuery(".snapshot-records-month-header").html( moment.unix( data["current"]["epoch"] ).format( 'MMMM YYYY' ) );
229+
jQuery(".dailystatshigh").html( data["day"]["outTemp"]["max"] );
230+
jQuery(".dailystatslow").html( data["day"]["outTemp"]["min"] );
231+
jQuery(".dailystatswind").html( data["day"]["wind"]["max"] );
232+
jQuery(".dailystatsuv").html( data["day"]["uv"]["max"] );
233+
jQuery(".dailystatsrain").html( data["day"]["rain"]["sum"] );
234+
jQuery(".dailystatsrainrate").html( data["day"]["rain"]["max"] );
235+
236+
// Sunrise and Sunset
237+
jQuery(".sunrise-value").html( data["almanac"]["sunrise"] );
238+
jQuery(".sunset-value").html( data["almanac"]["sunset"] );
239+
240+
// Moon icon, phase and illumination percent
241+
switch ( data["almanac"]["moon"]["moon_phase"] ) {
242+
case "New Moon":
243+
jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-new'></div>" );
244+
break;
245+
case "Waxing Crescent":
246+
jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-waxing-crescent-1'></div>" );
247+
break;
248+
case "First Quarter":
249+
jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-first-quarter'></div>" );
250+
break;
251+
case "Waxing Gibbous":
252+
jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-waxing-gibbous-3'></div>" );
253+
break;
254+
case "Full Moon":
255+
jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-full'></div>" );
256+
break;
257+
case "Waning Gibbous":
258+
jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-waning-gibbous-3'></div>" );
259+
break;
260+
case "Last Quarter":
261+
jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-first-quarter'></div>" );
262+
break;
263+
case "Waning Crescent":
264+
jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-waning-crescent-4'></div>" );
265+
break;
266+
}
267+
jQuery(".moon-phase").html( titleCase( data["almanac"]["moon"]["moon_phase"] ) ); // Javascript function above
268+
jQuery(".moon-visible").html( "<strong>" + data["almanac"]["moon"]["moon_fullness"] + "%</strong> visible" );
269+
}
270+
197271
#if $Extras.has_key("forecast_enabled") and $Extras.forecast_enabled == '1'
198272
function ajaxforecast() {
199273
jQuery.getJSON("$forecast_json_url", update_forecast_data);
@@ -332,79 +406,6 @@
332406
}
333407
}
334408

335-
function ajaxweewx() {
336-
jQuery.getJSON("$belchertown_root_url/json/weewx_data.json", update_weewx_data);
337-
};
338-
339-
// Update weewx data elements
340-
function update_weewx_data( data ) {
341-
console.log("Updating weewx data");
342-
// Daily High Low
343-
high = data["day"]["outTemp"]["max"];
344-
low = data["day"]["outTemp"]["min"];
345-
jQuery(".high").html( high );
346-
jQuery(".low").html( low );
347-
348-
// Barometer trending by finding a negative number
349-
count = ( data["current"]["barometer_trend"].match(/-/g) || [] ).length
350-
351-
if ( count >= 1 ) {
352-
jQuery(".wx-barometer-trend").html( '<i class="fa fa-arrow-down barometer-down"></i>' );
353-
} else {
354-
jQuery(".wx-barometer-trend").html( '<i class="fa fa-arrow-up barometer-up"></i>' );
355-
}
356-
357-
// Current wind gust
358-
jQuery(".curwindgust").text( parseFloat( data["current"]["windGust"] ).toFixed(1) );
359-
360-
// Daily max gust span
361-
jQuery(".dailymaxgust").html( parseFloat( data["day"]["wind"]["max"] ).toFixed(1) );
362-
363-
// Daily stats section
364-
jQuery(".snapshot-records-today-header").html( moment.unix( data["current"]["epoch"] ).format( 'dddd, MMMM D, YYYY' ) ); // e.g. Tuesday, January 15, 2019
365-
jQuery(".snapshot-records-month-header").html( moment.unix( data["current"]["epoch"] ).format( 'MMMM, YYYY' ) ); // e.g. January, 2019
366-
jQuery(".dailystatshigh").html( data["day"]["outTemp"]["max"] );
367-
jQuery(".dailystatslow").html( data["day"]["outTemp"]["min"] );
368-
jQuery(".dailystatswind").html( data["day"]["wind"]["max"] );
369-
jQuery(".dailystatsuv").html( data["day"]["uv"]["max"] );
370-
jQuery(".dailystatsrain").html( data["day"]["rain"]["sum"] );
371-
jQuery(".dailystatsrainrate").html( data["day"]["rain"]["max"] );
372-
373-
// Sunrise and Sunset
374-
jQuery(".sunrise-value").html( data["almanac"]["sunrise"] );
375-
jQuery(".sunset-value").html( data["almanac"]["sunset"] );
376-
377-
// Moon icon, phase and illumination percent
378-
switch ( data["almanac"]["moon"]["moon_phase"] ) {
379-
case "New Moon":
380-
jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-new'></div>" );
381-
break;
382-
case "Waxing Crescent":
383-
jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-waxing-crescent-1'></div>" );
384-
break;
385-
case "First Quarter":
386-
jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-first-quarter'></div>" );
387-
break;
388-
case "Waxing Gibbous":
389-
jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-waxing-gibbous-3'></div>" );
390-
break;
391-
case "Full Moon":
392-
jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-full'></div>" );
393-
break;
394-
case "Waning Gibbous":
395-
jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-waning-gibbous-3'></div>" );
396-
break;
397-
case "Last Quarter":
398-
jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-first-quarter'></div>" );
399-
break;
400-
case "Waning Crescent":
401-
jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-waning-crescent-4'></div>" );
402-
break;
403-
}
404-
jQuery(".moon-phase").html( titleCase( data["almanac"]["moon"]["moon_phase"] ) ); // Javascript function above
405-
jQuery(".moon-visible").html( "<strong>" + data["almanac"]["moon"]["moon_fullness"] + "%</strong> visible" );
406-
}
407-
408409
// mqtt connect
409410
function connect(){
410411
console.log("Connecting to MQTT");
@@ -993,7 +994,7 @@
993994

994995
<div class="col-sm-6 stn-quick-stats">
995996
<div class="stats-title">
996-
Today, <span class="snapshot-records-today-header">$current.dateTime.format("%A, %B %d, %Y")</span><!-- AJAX -->
997+
<span class="snapshot-records-today-header"></span><!-- JS and AJAX -->
997998
</div>
998999
<table>
9991000
<tr>
@@ -1015,7 +1016,7 @@
10151016
<!-- Quick this month stats -->
10161017
<div class="col-sm-6 stn-quick-stats border-left">
10171018
<div class="stats-title">
1018-
Month of <span class="snapshot-records-month-header">$current.dateTime.format("%B, %Y")</span><!-- AJAX -->
1019+
<span class="snapshot-records-month-header">$current.dateTime.format("%B %Y")</span><!-- AJAX -->
10191020
</div>
10201021
<table>
10211022
<tr>

0 commit comments

Comments
 (0)