-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMMM-Surf.js
More file actions
1510 lines (1339 loc) · 73.4 KB
/
MMM-Surf.js
File metadata and controls
1510 lines (1339 loc) · 73.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* global Module */
/* Magic Mirror
* Module: MMM-Surf
* By PrivacyWonk
* CC BY-NC 4.0 Licensed.
* Staying alive.
*/
Module.register("MMM-Surf", {
// Default module config.
defaults: {
debug: 0, //Debug is turned off by default
// Magicseaweed API Configuration
MagicSeaweedAPIBase: "http://magicseaweed.com/api/",
forecastEndpoint: "/forecast/?spot_id=",
//Surf forecast (Magicseaweed) variables
MagicAPI: "", //MagicSeaweed API Key
MagicSeaweedSpotID: "", //spot ID from magic seaweed URL (e.g. 319 from http://magicseaweed.com/Ocean-City-NJ-Surf-Report/391/)
MagicSeaweedSpotName: "", // shorthand name for your spot...e.g. Secret Spot / Lowers / The End / etc
spotCoast: "", //what coast the spot sits on values are "N, E, S, W"
spotSwellHold: [], //best swell direction for spot. Accepts multiple cardinal directions, e.g. "N","S","SSW","ESE" see: https://en.wikipedia.org/wiki/Compass_rose#/media/File:Kompassrose.svg
spotWind: [], //best wind direction for spot. Accepts multiple cardinal directions, e.g. "N","S","SSW","ESE"
spotSwellMin: "", //minimum swell size that works at the spot
spotSwellMax: "", //maximum swell size that works at the spot
// Define wind directions that are bad for a spot. E.g. if east coast spot, winds blowing E->W are bad / onshore or N<->S are sideshore.)
eastSpotBadWinds: ["NNE", "NE", "ENE", "E", "ESE", "SE", "SSE"],
westSpotBadWinds: ["SSW", "SW", "WSW", "W", "WNS", "NW", "NNW"],
northSpotBadWinds: ["WNW", "NW", "NNW", "N", "NNE", "NE", "ENE"],
southSpotBadWinds: ["ESE", "SE", "SSW", "S", "SSE", "SE", "WSW"],
// define wind thresholds. less than green max, between green and orange max, greater than red wind speeds
greenWindMax: "", //in MPH
orangeWindMax: "", //in MPH
redWindMax: "", //in MPH
//----------------------------------------
//Dark Sky Base API URL
DarkSkyAPIBase: "https://api.darksky.net/forecast/",
// DarkSky variables
DarkSkyAPI: "", //API key for DarkSky from darksky.net
DarkSkyLat: "", //Latitude for forecast
DarkSkyLong: "", //Longtitude for forecast
//-----------------------------------------
// NOAA API Configuration
NOAAapiBase: "https://tidesandcurrents.noaa.gov/api/",
//NOAA Variables
station_id: "", //Numeric station ID from NOAA
noaatz: "", // gmt, lst, lst_ldt (Local Standard Time or Local Daylight Time) of station
//----------------------------------------
//Other variables
units: config.units,
windunits: "bft", // choose from mph, bft
updateInterval: 30*60*1000, // conversion to milliseconds (Minutes * 60 Seconds * 1000). Only change minutes. Be kind, don't hammer APIs.
animationSpeed: 1000,
timeFormat: config.timeFormat,
lang: config.language,
showWindDirection: true,
fade: true,
fadePoint: 0.25, // Start on 1/4th of the list.
roundTmpDecs: 1,
iconset: "VCloudsWeatherIcons",
retryDelay: 2500,
iconTableDay: {
"chanceflurries": "wi-day-snow-wind",
"chancerain": "wi-day-showers",
"chancesleet": "wi-day-sleet",
"chancesnow": "wi-day-snow",
"chancetstorms": "wi-day-storm-showers",
"clear": "wi-day-sunny",
"cloudy": "wi-cloud",
"flurries": "wi-snow-wind",
"fog": "wi-fog",
"haze": "wi-day-haze",
"hazy": "wi-day-haze",
"mostlycloudy": "wi-cloudy",
"mostlysunny": "wi-day-sunny-overcast",
"partlycloudy": "wi-day-cloudy",
"partlysunny": "wi-day-cloudy-high",
"rain": "wi-rain",
"sleet": "wi-sleet",
"snow": "wi-snow",
"tstorms": "wi-thunderstorm"
},
iconTableNight: {
"chanceflurries": "wi-night-snow-wind",
"chancerain": "wi-night-showers",
"chancesleet": "wi-night-sleet",
"chancesnow": "wi-night-alt-snow",
"chancetstorms": "wi-night-alt-storm-showers",
"clear": "wi-night-clear",
"cloudy": "wi-night-alt-cloudy",
"flurries": "wi-night-alt-snow-wind",
"fog": "wi-night-fog",
"haze": "wi-night-alt-cloudy-windy",
"hazy": "wi-night-alt-cloudy-windy",
"mostlycloudy": "wi-night-alt-cloudy",
"mostlysunny": "wi-night-alt-partly-cloudy",
"partlycloudy": "wi-night-alt-partly-cloudy",
"partlysunny": "wi-night-alt-partly-cloudy",
"rain": "wi-night-alt-rain",
"sleet": "wi-night-alt-sleet",
"snow": "wi-night-alt-snow",
"tstorms": "wi-night-alt-thunderstorm"
},
iconTableCompliments: {
"chanceflurries": "13",
"chancerain": "10",
"chancesleet": "13",
"chancesnow": "13",
"chancetstorms": "11",
"clear": "01",
"cloudy": "02",
"flurries": "13",
"fog": "50",
"haze": "50",
"hazy": "50",
"mostlycloudy": "03",
"mostlysunny": "02",
"partlycloudy": "02",
"partlysunny": "02",
"rain": "10",
"sleet": "13",
"snow": "13",
"tstorms": "11"
}
},
// Define required translations.
getTranslations: function() {
return {
en: "translations/en.json",
nl: "translations/nl.json",
de: "translations/de.json",
dl: "translations/de.json",
fr: "translations/fr.json",
pl: "translations/pl.json"
};
},
// Add moment.js functionality.
getScripts: function() {
return ["moment.js"];
},
// Import CSS files.
getStyles: function() {
return ["weather-icons.css", "weather-icons-wind.css", "font-awesome.css", "MMM-Surf.css"];
},
// Define start sequence.
start: function() {
Log.info("Starting module: " + this.name);
// Set locale.
moment.locale(config.language);
this.forecast = [];
this.hourlyforecast = [];
this.loaded = false;
this.error = false;
this.errorDescription = "";
this.getNOAA();
this.getDarkSky();
this.getMagicseaweed();
this.lastUpdatedTime = "";
this.haveforecast = 0;
},
getNOAA: function() {
if (this.config.debug === 1) { Log.info(moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + " SOCKET(SEND TO HELPER): GET_NOAA (1):"); }
this.sendSocketNotification("GET_NOAA", this.config);
}, //end getNOAA function
getDarkSky: function() {
if (this.config.debug === 1) { Log.info(moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + " SOCKET(SEND TO HELPER): GET_DARKSKY (1):"); }
this.sendSocketNotification("GET_DARKSKY", this.config);
}, //end getDarkSky
getMagicseaweed: function() {
if (this.config.debug === 1) { Log.info(moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + " SOCKET(SEND TO HELPER): GET_MAGIC (1):"); }
this.sendSocketNotification("GET_MAGIC", this.config);
}, //end getMagicseaweed function
// Override dom generator.
getDom: function() {
var wrapper = document.createElement("div");
var f;
var forecast;
var iconCell;
var icon;
var popCell;
var mmCell;
var hourCell;
var dayCell;
var startingPoint;
var currentStep;
var steps;
if (this.config.DarkSkyAPI === "") {
wrapper.innerHTML = this.translate("APIKEY") + this.name + ".";
wrapper.className = "dimmed light small";
return wrapper;
}
if (this.error) {
wrapper.innerHTML = "Error: " + this.errorDescription;
wrapper.className = "dimmed light small";
return wrapper;
}
if (!this.loaded) {
wrapper.innerHTML = this.translate("LOADING");
wrapper.className = "dimmed light small";
return wrapper;
}
//Build CURRENT WEATHER row
var small = document.createElement("div");
small.className = "normal medium";
var spacer = document.createElement("span");
spacer.innerHTML = " ";
var table_sitrep = document.createElement("table");
var row_sitrep = document.createElement("tr");
var spot_row = document.createElement("tr");
if (this.config.MagicSeaweedSpotName != "") {
var row = document.createElement("tr");
var spotTextCell = document.createElement("td");
//display spot name from config
spotTextCell.className = "spotName";
spotTextCell.setAttribute("colSpan", "10");
spotTextCell.innerHTML = this.config.MagicSeaweedSpotName;
spot_row.appendChild(spotTextCell);
table_sitrep.appendChild(spot_row);
}
var weatherIcon = document.createElement("td");
weatherIcon.className = "wi " + this.weatherType;
row_sitrep.appendChild(weatherIcon);
var temperature = document.createElement("td");
temperature.className = "bright";
temperature.innerHTML = " " + this.temperature + "°";
row_sitrep.appendChild(temperature);
var windIcon = document.createElement("td");
if (this.config.windunits == "mph") {
windIcon.innerHTML = this.windSpeedMph + "<sub>mph</sub>";
} else {
windIcon.className = "wi " + this.windSpeed;
}
row_sitrep.appendChild(windIcon);
row_sitrep.className = "pop";
var windDirectionIcon = document.createElement("td");
windDirectionIcon.className = "wi wi-wind " + this.windDirection;
windDirectionIcon.innerHTML = " ";
row_sitrep.appendChild(windDirectionIcon);
var HumidityIcon = document.createElement("td");
HumidityIcon.className = "wi wi-humidity lpad";
row_sitrep.appendChild(HumidityIcon);
var HumidityTxt = document.createElement("td");
HumidityTxt.innerHTML = this.Humidity + " ";
HumidityTxt.className = "vcen left";
row_sitrep.appendChild(HumidityTxt);
var sunriseSunsetIcon = document.createElement("td");
sunriseSunsetIcon.className = "wi " + this.sunriseSunsetIcon;
row_sitrep.appendChild(sunriseSunsetIcon);
var sunriseSunsetTxt = document.createElement("td");
sunriseSunsetTxt.innerHTML = this.sunriseSunsetTime;
sunriseSunsetTxt.className = "vcen left";
row_sitrep.appendChild(sunriseSunsetTxt);
var moonPhaseIcon = document.createElement("td");
//moonPhaseIcon.innerHTML = this.moonPhaseIcon;
moonPhaseIcon.className = "wi " + this.moonPhaseIcon;
row_sitrep.appendChild(moonPhaseIcon);
//close current weather conditions row (top)
table_sitrep.appendChild(row_sitrep);
small.appendChild(table_sitrep);
// CURRENT WATER CONDITIONS
var small2 = document.createElement("div");
small2.className = "normal medium test";
var spacer = document.createElement("span");
spacer.innerHTML = " ";
//add divider
var divider = document.createElement("hr");
divider.className = "hrDivider";
small2.appendChild(divider);
// Current Water Conditions (second row)
var table_watersitrep = document.createElement("table");
var row_watersitrep = document.createElement("tr");
row_watersitrep.className = "pop";
/* Display Water Temperature & Gear Choices
* wetsuit/gear choice evals water temp and makes a recommendation
* Not a science...weather conditions will influence your choice
*/
gear = "";
WaterEval = Math.round(this.WaterTemp);
if (WaterEval >= 73) {gear = "Boardies!";}
if (WaterEval >= 65 && WaterEval <= 72) { gear = "2mm";}
if (WaterEval >= 59 && WaterEval <= 64) { gear = "3/2";}
if (WaterEval >= 54 && WaterEval <= 58) { gear = "4/3";}
if (WaterEval >= 47 && WaterEval <= 53) { gear = "5/4/3";}
if (WaterEval <= 46) {gear = "6/5/4";}
var WaterTxt = document.createElement("td");
WaterTxt.innerHTML = Math.round(this.WaterTemp) + "° <br>" + "<span class=\"smaller\"> Gear: <br>" + gear + "</span>"; //round to nearest whole because 50.2 degrees doesn't make a difference
WaterTxt.className = "water";
row_watersitrep.appendChild(WaterTxt);
//Display Tide Data
var TideIcon = document.createElement("td");
if (this.DeltaPerc >= 0 && this.DeltaPerc <= 33) {
TideIcon.innerHTML = "<img src='./modules/MMM-Surf/img/" + this.TideTypeCurrent + "Tide1.png" + "'>";}
if (this.DeltaPerc >= 34 && this.DeltaPerc <= 66) {
TideIcon.innerHTML = "<img src='./modules/MMM-Surf/img/" + this.TideTypeCurrent + "Tide2.png" + "'>";}
if (this.DeltaPerc >= 67) {
TideIcon.innerHTML = "<img src='./modules/MMM-Surf/img/" + this.TideTypeCurrent + "Tide3.png" + "'>";}
TideIcon.className = "wi";
row_watersitrep.appendChild(TideIcon);
var TideTxt = document.createElement("td");
if (this.TideTypeCurrent == "Low") {
TideTxt.innerHTML = this.TideHeightCurrent + "' @ " + moment(this.TideTimeCurrent).format('LT') + " <br> " + this.DeltaPerc + "% out";
} else {
TideTxt.innerHTML = this.TideHeightCurrent + "'@ " + moment(this.TideTimeCurrent).format('LT') + " <br> " + this.DeltaPerc + "% in";
}
TideTxt.className = "small vcen left";
row_watersitrep.appendChild(TideTxt);
//Display Next Tide Data and Time
var nextTideIcon = document.createElement("td");
nextTideIcon.innerHTML = "<img src='./modules/MMM-Surf/img/" + this.TideTypeNext + ".png" + "'>";
nextTideIcon.className = "wi";
row_watersitrep.appendChild(nextTideIcon);
var nextTideTxt = document.createElement("td");
nextTideTxt.innerHTML = this.TideHeightNext + "' @ " + moment(this.TideTimeNext).format('LT');
nextTideTxt.className = "small vcen left";
row_watersitrep.appendChild(nextTideTxt);
//Close Water Conditions Row in table (second row)
table_watersitrep.appendChild(row_watersitrep);
small2.appendChild(table_watersitrep);
//Write Current Weather and Current Water
wrapper.appendChild(small);
wrapper.appendChild(small2);
// ------------------ 12 HOUR SURF FORECAST ------------------
//TODO: Make Vertical format work with Surf Forecast! Currently only horizontal
//TODO: Add vertical v. horizontal test?
var table = document.createElement("table");
var fctable = document.createElement("div");
var divider = document.createElement("hr");
divider.className = "hrDivider";
fctable.appendChild(divider);
table = document.createElement("table");
table.className = "small";
table.setAttribute("width", "25%");
//table.setAttribute("border", 1); // for layout testing only
row_forecastDay = document.createElement("tr"); //layout row for Day and Time
row_forecastRating = document.createElement("tr"); //layout row for Magicseaweed star rating
row_swellCharacteristics = document.createElement("tr"); // layout row for swell height and periodicity
row_swell = document.createElement("tr"); // layout row for swell direction icon and text
row_wind = document.createElement("tr"); //layout row for wind direction icon and text
for (f in this.magicforecast12hrs) {
dayTimeCell = document.createElement("td");
dayTimeCell.setAttribute('style', 'text-align: center;');
dayTimeCell.className = "hour";
dayTimeCell.innerHTML = this.magicforecast12hrs[f].day + " " + this.magicforecast12hrs[f].hour;
row_forecastDay.appendChild(dayTimeCell);
//Render Magicseaweed star rating
magicseaweedStarRating = document.createElement("td");
magicseaweedStarRating.setAttribute('style', 'text-align: center;');
magicseaweedStarRating.className = "align-center bright weather-icon";
icon = document.createElement("span");
if (this.magicforecast12hrs[f].rating.length == 0) {
//icon.className = "wi wi-na"; //old NA icon
icon.innerHTML = "<span class=\"swellred\"><i class=\"fa fa-times-circle\"></i></span>";
} else {
icon.innerHTML = this.magicforecast12hrs[f].rating.join(" ");
}
magicseaweedStarRating.appendChild(icon);
row_forecastRating.appendChild(magicseaweedStarRating);
//swell height and period
swellConditionsCell = document.createElement("td");
swellConditionsCell.setAttribute('style', 'text-align: center;');
/* Evaluate periodicity of swell and pop an indicator color
* red = not surfable
* orange = surfable but sloppy
* green = go go go
* source: https://magicseaweed.com/help/forecast-table/wave-period-overview
* Evaluate wave height for spot from config. If between Min and Max, pop green
*/
if (this.magicforecast12hrs[f].swellHeight >= this.config.spotSwellMin && this.magicforecast12hrs[f].swellHeight <= this.config.spotSwellMax) {
swellHeightRender = "<span class=\"swellgreen\">" + this.magicforecast12hrs[f].swellHeight +"'</span> @ "; }
else {
swellHeightRender = this.magicforecast12hrs[f].swellHeight + "' @ ";}
if (this.magicforecast12hrs[f].swellPeriod >= 0 && this.magicforecast12hrs[f].swellPeriod <= 6)
{swellPeriodRender = "<span class=\"swellred\">" + this.magicforecast12hrs[f].swellPeriod + "s</span>";}
if (this.magicforecast12hrs[f].swellPeriod >= 7 && this.magicforecast12hrs[f].swellPeriod <= 9)
{swellPeriodRender = "<span class=\"swellorange\">" + this.magicforecast12hrs[f].swellPeriod + "s</span>";}
if (this.magicforecast12hrs[f].swellPeriod >= 10)
{swellPeriodRender = "<span class=\"swellgreen\">" + this.magicforecast12hrs[f].swellPeriod + "s</span>";}
swellConditionsCell.innerHTML = swellHeightRender.concat(swellPeriodRender);
swellConditionsCell.className = "hour";
row_swellCharacteristics.appendChild(swellConditionsCell);
//swell direction
swellInfo = document.createElement("td");
swellInfoCell = document.createElement("strong");
swellInfo.setAttribute('style', 'text-align: center;');
swellInfoCell.innerHTML = "Swell: ";
swellInfoCell.className = "hour";
swellInfo.appendChild(swellInfoCell);
swellInfoCell = document.createElement("i");
for (i = 0, count = this.config.spotSwellHold.length; i < count; i++) {
if (this.config.debug === 1) {
//Log.info("SWELL (forecast/spothold): "+ this.magicforecast12hrs[f].swellCompassDirection+"/"+this.config.spotSwellHold[i]);
}
if (this.config.spotSwellHold[i] === this.magicforecast12hrs[f].swellCompassDirection) {
//Swell direction is the direction the swell is coming from, as opposed to the direction it is heading toward.
//The arrow displayed will have the small point facing the origin of the swell
swellInfoCell.className = "wi wi-wind from-" + Math.round(this.magicforecast12hrs[f].swellDirection) + "-deg swellgreen";
break;
} else{
swellInfoCell.className = "wi wi-wind from-" + Math.round(this.magicforecast12hrs[f].swellDirection) + "-deg";
}
} // end swell colorization loop
swellInfo.appendChild(swellInfoCell);
swellInfoCell = document.createElement("i");
swellInfoCell.innerHTML = " " + this.magicforecast12hrs[f].swellCompassDirection;
swellInfoCell.className = "hour";
swellInfo.appendChild(swellInfoCell);
row_swell.appendChild(swellInfo);
//wind direction
windInfo = document.createElement("td");
windInfo.setAttribute('style', 'text-align: center;');
windInfoCell = document.createElement("strong");
windInfoCell.innerHTML = "Wind: ";
windInfoCell.className = "hour";
windInfo.appendChild(windInfoCell);
windInfoCell = document.createElement("i");
for (i = 0, count = this.config.spotWind.length; i < count; i++) {
//if (this.config.debug === 1) { Log.info("WIND: " + this.magicforecast12hrs[f].windCompassDirection + " / " + this.config.spotWind[i]);}
if (this.config.spotWind[i] === this.magicforecast12hrs[f].windCompassDirection) {
//Wind direction is reported by the direction from which it originates.
//For example, a northerly wind blows from the north to the south.
//The arrow displayed will have the small point facing the origin of the wind
windInfoCell.className = "wi wi-wind " + this.magicforecast12hrs[f].windDirection + " swellgreen";
break;
} else {
// If statements to pop-color on sideshore and onshore winds determined - roughly - by the spot orientation
// if the spot is on the east coast, then any winds coming from the east, blowing west, are on shore and ugly (red)
// Wind directions have alreadybeen set in *SpotBadWinds in the config stanza
if (this.config.spotCoast === "E") {
if (this.config.eastSpotBadWinds.indexOf(this.magicforecast12hrs[f].windCompassDirection) != -1) {
windInfoCell.className = "wi wi-wind " + this.magicforecast12hrs[f].windDirection + " swellred";
} else {
windInfoCell.className = "wi wi-wind " + this.magicforecast12hrs[f].windDirection + " swellorange";
}
}
if (this.config.spotCoast === "W") {
if (this.config.westSpotBadWinds.indexOf(this.magicforecast12hrs[f].windCompassDirection) != -1) {
windInfoCell.className = "wi wi-wind " + this.magicforecast12hrs[f].windDirection + " swellred";
} else {
windInfoCell.className = "wi wi-wind " + this.magicforecast12hrs[f].windDirection + " swellorange";
}
}
if (this.config.spotCoast === "N") {
if (this.config.northSpotBadWinds.indexOf(this.magicforecast12hrs[f].windCompassDirection) != -1) {
windInfoCell.className = "wi wi-wind " + this.magicforecast12hrs[f].windDirection + " swellred";
} else {
windInfoCell.className = "wi wi-wind " + this.magicforecast12hrs[f].windDirection + " swellorange";
}
}
if (this.config.spotCoast === "S") {
if (this.config.southSpotBadWinds.indexOf(this.magicforecast12hrs[f].windCompassDirection) != -1) {
windInfoCell.className = "wi wi-wind " + this.magicforecast12hrs[f].windDirection + " swellred";
} else {
windInfoCell.className = "wi wi-wind " + this.magicforecast12hrs[f].windDirection + " swellorange";
}
}
} // end else loop
} // end wind colorization loop
windInfo.appendChild(windInfoCell);
windInfoCell = document.createElement("i");
if (this.magicforecast12hrs[f].windGusts <=this.config.greenWindMax) {
windInfoCell.innerHTML = " " + this.magicforecast12hrs[f].windCompassDirection + "<br>" + "Steady: " + this.magicforecast12hrs[f].windSpeed + "mph<br>" +"<span class=\"swellgreen\">Gusts: </span>" +this.magicforecast12hrs[f].windGusts + "mph";
}
if (this.magicforecast12hrs[f].windGusts > this.config.greenWindMax && this.magicforecast12hrs[f].windGusts <= this.config.orangeWindMax) {
windInfoCell.innerHTML = " " + this.magicforecast12hrs[f].windCompassDirection + "<br>" + "Steady: " + this.magicforecast12hrs[f].windSpeed + "mph<br>" +"<span class=\"swellorange\">Gusts: </span>" +this.magicforecast12hrs[f].windGusts + "mph";
}
if (this.magicforecast12hrs[f].windGusts >= this.config.redWindMax) {
windInfoCell.innerHTML = " " + this.magicforecast12hrs[f].windCompassDirection + "<br>" + "Steady: " + this.magicforecast12hrs[f].windSpeed + "mph<br>" +"<span class=\"swellred\">Gusts: </span>" +this.magicforecast12hrs[f].windGusts + "mph";
}
//windInfoCell.innerHTML = " " + this.magicforecast12hrs[f].windCompassDirection + "<br>" + "Steady: " + this.magicforecast12hrs[f].windSpeed + "mph<br>" +"Gusts: " +this.magicforecast12hrs[f].windGusts + "mph";
windInfoCell.className = "hour";
windInfo.appendChild(windInfoCell);
row_wind.appendChild(windInfo);
var nl = Number(f) + 1;
if ((nl % 4) === 0) {
table.appendChild(row_forecastDay);
table.appendChild(row_forecastRating);
table.appendChild(row_swellCharacteristics);
table.appendChild(row_swell);
table.appendChild(row_wind);
row_forecastDay = document.createElement("tr");
row_forecastRating = document.createElement("tr");
row_swellCharacteristics = document.createElement("tr");
row_swell = document.createElement("tr");
row_wind = document.createElement("tr");
}
//Force 12-hour row to stay on one line...not entirely sure how this works.
if (f > 2) {
break;
}
} //end magicforecast12hrs for loop
//write out Forecast table (every 3 hours)
table.appendChild(row_forecastDay);
table.appendChild(row_forecastRating);
table.appendChild(row_swellCharacteristics);
table.appendChild(row_swell);
table.appendChild(row_wind);
fctable.appendChild(table);
fctable.appendChild(divider.cloneNode(true));
// ------------------ DAILY SURF FORECAST ------------------
table = document.createElement("table");
table.className = "small";
table.setAttribute("width", "25%");
row_forecastDay = document.createElement("tr");
row_forecastRating = document.createElement("tr");
row_swellCharacteristics = document.createElement("tr");
row_swell = document.createElement("tr");
row_wind = document.createElement("tr");
row_lastUpdated = document.createElement("tr");
for (f in this.magicforecastDaily) {
dayCell = document.createElement("td");
dayCell.setAttribute('style', 'text-align: center;');
dayCell.className = "hour";
dayCell.innerHTML = this.magicforecastDaily[f].day + " " + this.magicforecastDaily[f].hour;
row_forecastDay.appendChild(dayCell);
//rating
magicseaweedStarRating = document.createElement("td");
magicseaweedStarRating.setAttribute('style', 'text-align: center;');
magicseaweedStarRating.className = "align-center bright weather-icon";
icon = document.createElement("span");
if (this.magicforecastDaily[f].rating.length == 0) {
//icon.className = "wi wi-na";
icon.innerHTML = "<span class=\"swellred\"><i class=\"fa fa-times-circle\"></i></span>";
} else {
icon.innerHTML = this.magicforecastDaily[f].rating.join(" ");
}
magicseaweedStarRating.appendChild(icon);
row_forecastRating.appendChild(magicseaweedStarRating);
//swell height and period
swellConditionsCell = document.createElement("td");
swellConditionsCell.setAttribute('style', 'text-align: center;');
/* Evaluate periodicity of swell and pop an indicator color
* red = not surfable
* orange = surfable but sloppy
* green = go go go
* source: https://magicseaweed.com/help/forecast-table/wave-period-overview
* Evaluate wave height for spot from config. If between Min and Max, pop green
*/
if (this.magicforecastDaily[f].swellHeight >= this.config.spotSwellMin && this.magicforecastDaily[f].swellHeight <= this.config.spotSwellMax) {
swellHeightRender = "<span class=\"swellgreen\">" + this.magicforecastDaily[f].swellHeight +"'</span> @ "; }
else {
swellHeightRender = this.magicforecastDaily[f].swellHeight + "' @ ";}
if (this.magicforecastDaily[f].swellPeriod >= 0 && this.magicforecastDaily[f].swellPeriod <= 6)
{swellPeriodRender = "<span class=\"swellred\">" + this.magicforecastDaily[f].swellPeriod + "s</span>";}
if (this.magicforecastDaily[f].swellPeriod >= 7 && this.magicforecastDaily[f].swellPeriod <= 9)
{swellPeriodRender = "<span class=\"swellorange\">" + this.magicforecastDaily[f].swellPeriod + "s</span>";}
if (this.magicforecastDaily[f].swellPeriod >= 10)
{swellPeriodRender = "<span class=\"swellgreen\">" + this.magicforecastDaily[f].swellPeriod + "s</span>";}
swellConditionsCell.innerHTML = swellHeightRender.concat(swellPeriodRender);
swellConditionsCell.className = "hour";
row_swellCharacteristics.appendChild(swellConditionsCell);
//swell direction
swellInfo = document.createElement("td");
swellInfo.setAttribute('style', 'text-align: center;');
swellInfoCell = document.createElement("strong");
swellInfoCell.innerHTML = "Swell: ";
swellInfoCell.className = "hour";
swellInfo.appendChild(swellInfoCell);
swellInfoCell = document.createElement("i");
for (i = 0, count = this.config.spotSwellHold.length; i < count; i++) {
//Log.info("Swell Compass Direction: "+ this.magicforecastDaily[f].swellCompassDirection);
//Log.info("Spot Best Swell: " +this.config.spotSwellHold[i]);
if (this.config.spotSwellHold[i] === this.magicforecastDaily[f].swellCompassDirection) {
//Swell direction is the direction the swell is coming from, as opposed to the direction it is heading toward.
//The arrow displayed will have the small point facing the origin of the swell
swellInfoCell.className = "wi wi-wind from-" + Math.round(this.magicforecastDaily[f].swellDirection) + "-deg swellgreen";
break;
} else{
swellInfoCell.className = "wi wi-wind from-" + Math.round(this.magicforecastDaily[f].swellDirection) + "-deg";
}
} // end swell colorization loop
swellInfo.appendChild(swellInfoCell);
swellInfoCell = document.createElement("i");
swellInfoCell.innerHTML = " " + this.magicforecastDaily[f].swellCompassDirection;
swellInfoCell.className = "hour";
swellInfo.appendChild(swellInfoCell);
row_swell.appendChild(swellInfo);
//wind direction
windInfo = document.createElement("td");
windInfo.setAttribute('style', 'text-align: center;');
windInfoCell = document.createElement("strong");
windInfoCell.innerHTML = "Wind: ";
windInfoCell.className = "hour";
windInfo.appendChild(windInfoCell);
windInfoCell = document.createElement("i");
for (i = 0, count = this.config.spotWind.length; i < count; i++) {
if (this.config.spotWind[i] === this.magicforecastDaily[f].windCompassDirection) {
//Wind direction is reported by the direction from which it originates. For example, a northerly wind blows from the north to the south.
//The arrow displayed will have the small point facing the origin of the wind
windInfoCell.className = "wi wi-wind " + this.magicforecastDaily[f].windDirection + " swellgreen";
break;
} else {
// If statements to pop-color on sideshore and onshore winds determined - roughly - by the spot orientation
// if the spot is on the east coast, then any winds coming from the east, blowing west, are on shore and ugly (red)
// Wind directions have alreadybeen set in *SpotBadWinds in the config stanza
if (this.config.spotCoast === "E") {
if (this.config.eastSpotBadWinds.indexOf(this.magicforecastDaily[f].windCompassDirection) != -1) {
windInfoCell.className = "wi wi-wind " + this.magicforecastDaily[f].windDirection + " swellred";
} else {
windInfoCell.className = "wi wi-wind " + this.magicforecastDaily[f].windDirection + " swellorange";
}
}
if (this.config.spotCoast === "W") {
if (this.config.westSpotBadWinds.indexOf(this.magicforecastDaily[f].windCompassDirection) != -1) {
windInfoCell.className = "wi wi-wind " + this.magicforecastDaily[f].windDirection + " swellred";
} else {
windInfoCell.className = "wi wi-wind " + this.magicforecastDaily[f].windDirection + " swellorange";
}
}
if (this.config.spotCoast === "N") {
if (this.config.northSpotBadWinds.indexOf(this.magicforecastDaily[f].windCompassDirection) != -1) {
windInfoCell.className = "wi wi-wind " + this.magicforecastDaily[f].windDirection + " swellred";
} else {
windInfoCell.className = "wi wi-wind " + this.magicforecastDaily[f].windDirection + " swellorange";
}
}
if (this.config.spotCoast === "S") {
if (this.config.southSpotBadWinds.indexOf(this.magicforecastDaily[f].windCompassDirection) != -1) {
windInfoCell.className = "wi wi-wind " + this.magicforecastDaily[f].windDirection + " swellred";
} else {
windInfoCell.className = "wi wi-wind " + this.magicforecastDaily[f].windDirection + " swellorange";
}
}
} // end else loop
} // end wind colorization loop
windInfo.appendChild(windInfoCell);
windInfoCell = document.createElement("i");
if (this.magicforecastDaily[f].windGusts <=this.config.greenWindMax) {
windInfoCell.innerHTML = " " + this.magicforecastDaily[f].windCompassDirection + "<br>" + "Steady: " + this.magicforecastDaily[f].windSpeed + "mph<br>" +"<span class=\"swellgreen\">Gusts: </span>" +this.magicforecastDaily[f].windGusts + "mph";
}
if (this.magicforecastDaily[f].windGusts > this.config.greenWindMax && this.magicforecastDaily[f].windGusts <= this.config.orangeWindMax) {
windInfoCell.innerHTML = " " + this.magicforecastDaily[f].windCompassDirection + "<br>" + "Steady: " + this.magicforecastDaily[f].windSpeed + "mph<br>" +"<span class=\"swellorange\">Gusts: </span>" +this.magicforecastDaily[f].windGusts + "mph";
}
if (this.magicforecastDaily[f].windGusts >= this.config.redWindMax) {
windInfoCell.innerHTML = " " + this.magicforecastDaily[f].windCompassDirection + "<br>" + "Steady: " + this.magicforecastDaily[f].windSpeed + "mph<br>" +"<span class=\"swellred\">Gusts: </span>" +this.magicforecastDaily[f].windGusts + "mph";
}
windInfoCell.className = "hour";
windInfo.appendChild(windInfoCell);
row_wind.appendChild(windInfo);
var nl = Number(f) + 1;
if ((nl % 4) === 0) {
table.appendChild(row_forecastDay);
table.appendChild(row_forecastRating);
table.appendChild(row_swellCharacteristics);
table.appendChild(row_swell);
table.appendChild(row_wind);
row_forecastDay = document.createElement("tr");
row_forecastRating = document.createElement("tr");
row_swellCharacteristics = document.createElement("tr");
row_swell = document.createElement("tr");
row_wind = document.createElement("tr");
}
//Force Daily row to stay on one line...not entirely sure how this works.
if (f > 2) {
break;
}
} //end magicForecastDaily loop
//Close forecast table for rendering to UI
table.appendChild(row_forecastDay);
table.appendChild(row_forecastRating);
table.appendChild(row_swellCharacteristics);
table.appendChild(row_swell);
table.appendChild(row_wind);
fctable.appendChild(table);
wrapper.appendChild(fctable);
//lastupdated indicator
var table_lastUpdated = document.createElement("table");
var row_lastUpdated = document.createElement("tr");
lastUpdatedCell = document.createElement("td");
lastUpdatedCell.setAttribute('style', "display:flex; flex-wrap: nowrap; align-items: center;font-size: 40%");
lastUpdatedCell.setAttribute("colSpan", "10");
// lastUpdatedCell.className = "weathericon";
lastUpdatedCell.innerHTML = "last updated at: " + this.lastUpdatedTime + " <img src='https://im-5.msw.ms/md/themes/msw_built/3/i/logo.png'>";
row_lastUpdated.appendChild(lastUpdatedCell);
table_lastUpdated.appendChild(row_lastUpdated);
wrapper.appendChild(table_lastUpdated);
return wrapper; //return the wrapper to browser for rendering
}, //end getDom function
/* processWeather(data)
*
* Processes DarkSky data for current conditions data only.
* this feeds the first row of icons
*/
processWeather: function(data) {
if (this.config.debug === 1) { Log.info(data); } //print Object to browser console
if (this.config.debug === 1) { Log.info(moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + " Processing Data: DarkSky (6)") };
//if (data.currently.estimated.hasOwnProperty("estimated") && this.haveforecast == 1) {
// if (this.config.debug === 1) { console.log("WeatherUnderground served us an estimated forecast. Skipping update..."); }
// return;
//}
this.haveforecast = 1;
if (data.flags.hasOwnProperty("darksky-unavailable")) {
this.errorDescription = data.response.error.description;
this.error = true;
this.updateDom(this.config.animationSpeed);
} else {
this.error = false;
var forecast;
var i;
var count;
var iconTable = this.config.iconTableDay;
var sunrise = new Date();
this.sunrise=data.daily.data[0].sunriseTime;
// this.sunrhour = Number(data.daily.data[0].sunriseTime);
// sunrise.setHours(data.daily.data[0].sunriseTime.sunrise.hour);
// sunrise.setMinutes(data.daily.data[0].sunriseTime.sunrise.minute);
var sunset = new Date();
this.sunset = data.daily.data[0].sunsetTime;
// this.sunshour = Number(data.daily.data[0].sunsetTime.sunset.hour);
// sunset.setHours(daily.data[0].sunsetTime.sunset.hour);
// sunset.setMinutes(data.daily.data[0].sunsetTime.sunset.minute);
// The moment().format("h") method has a bug on the Raspberry Pi.
// So we need to generate the timestring manually.
// See issue: https://github.com/MichMich/MagicMirror/issues/181
var now = new Date(); // pull in T/D for processing
var sunriseSunsetDateObject = (sunrise < now && sunset > now) ? sunset : sunrise;
var timeString = moment(sunriseSunsetDateObject).format("HH:mm");
if (this.config.timeFormat !== 24) {
if (this.config.showPeriod) {
if (this.config.showPeriodUpper) {
timeString = moment(sunriseSunsetDateObject).format("h:mm A");
} else {
timeString = moment(sunriseSunsetDateObject).format("h:mm a");
}
} else {
timeString = moment(sunriseSunsetDateObject).format(
"h:mm");
}
} // end timeFormat if
this.sunriseSunsetTime = timeString;
this.sunriseSunsetIcon = (sunrise < now && sunset > now) ? "wi-sunset" : "wi-sunrise";
this.iconTable = (sunrise < now && sunset > now) ? this.config
.iconTableDay : this.config.iconTableNight;
this.weatherType = this.iconTable[data.currently.icon];
this.windDirection = this.deg2Cardinal(data.currently.windBearing);
this.windDirectionTxt = data.currently.windBearing;
this.Humidity = data.currently.humidity*100;
this.windSpeed = "wi-wind-beaufort-" + this.ms2Beaufort(data.currently.windSpeed);
this.windSpeedMph = data.currently.windSpeed;
this.moonPhaseIcon = this.moon_icon(data.daily.data[0].moonPhase);
if (this.config.units == "metric") {
this.temperature = data.currently.temp_c;
var fc_text = data.forecast.txt_forecast.forecastday[0].fcttext_metric.replace(/(.*\d+)(C)(.*)/gi, "$1°C$3");
} else {
this.temperature = data.currently.temperature;
var fc_text = data.currently.summary;
}
this.temperature = this.roundValue(this.temperature);
this.loaded = true;
this.updateDom(this.config.animationSpeed);
if (this.config.debug === 1) { Log.info(moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' Rendering DarkSky data to UI (7)'); }
if (this.config.debug === 1) { Log.info('-------------------------------------------------------------------'); }
} //end if/else clause
}, //end processWeather
/* processNOAA_TIDE_DATA(data)
*
* Processes NOAA Tide Data to find previous, current, immediate next, and future tides
*
*/
processNOAA_TIDE_DATA: function(data) {
//JSON Structure - { "predictions" : [{"t":"2017-11-24 04:28", "v":"0.845", "type":"L"}
if (this.config.debug === 1) { Log.info(moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + " Processing Data: NOAA_TIDE (6)") };
if (this.config.debug === 1) { Log.info(data); } //print Object to browser console
var previousTideCount = 0;
var NextTide = ""; //flag for IDing the next tide after Current
var CurrentTide = ""; //flag for IDing the current tide given current time compared to previous and next tide
for (i = 0, count = data.predictions.length; i < count; i++) {
var len = data.predictions.length;
var current = data.predictions[i];
var previous = data.predictions[(i + len - 1) % len];
var next = data.predictions[(i + 1) % len];
//Modulus to itterate through Object to get next tide
var TideTableTime = new Date(current.t); //get current tide date element [i]
var NextTideTime = new Date(next.t); //get next tide date element [i+1]
var PrevTideTime = new Date(previous.t); //get previous tide date element [i-1]
if (current.type == "H") { data.predictions[i].type = "High"; } //change Object element from H to High
if (current.type == "L") { data.predictions[i].type = "Low"; } //change Object element from L to Low
var now = new Date(); //define current time/date for processing
if ((CurrentTide == "" || CurrentTide == "false") && (TideTableTime >= now && TideTableTime <= NextTideTime)) {
//Evaluate if the Tide is current, if so skip. If no, evaluate time of tide
//if the tide time provided by NOAA is between now (current date/time) and the next tide...we're in the current tide!
NextTide = 'false'; //set flag
CurrentTide = 'true'; //set flag
data.predictions[i].TideStatus = 'CURRENT'; //add indicator to NOAA Tide Object
var TideDelta = Math.abs(TideTableTime - PrevTideTime) / 36e5;
//returns in miliseconds 36e5 is the scientific notation for 60*60*1000, dividing by which converts the milliseconds difference into hours
//delta between Current Tide and Previous Tide, returns hours
var TideDeltaNow = Math.abs(now - PrevTideTime) / 36e5;
//delta between current Time and Previous Tide in Object[i-1]
this.DeltaPerc = Math.round(Math.abs(TideDeltaNow / TideDelta) * 100);
//divide two deltas to get percentage of action for current tide
continue;
}
if (TideTableTime < now) {
//if NOAA provided time is less than current date/time, it's in the past
NextTide = "false";
CurrentTide = "false";
data.predictions[i].TideStatus = "PREVIOUS"; //add indicator to NOAA Tide Object
continue;
}
if (CurrentTide == "true" && NextTide == "false" && NextTideTime > TideTableTime) {
//if the NextTideTime is greater than the current TideTableTime[i] under eval, it's the next one
NextTide = "true";
data.predictions[i].TideStatus = "NEXT"; //add indicator to NOAA Tide Object
continue;
}
if (CurrentTide == "true" && NextTide == "true") {
//if all flags are true, then we're in the future
data.predictions[i].TideStatus = "FUTURE"; //add indicator to NOAA Tide Object
continue;
}
} //end for loop
const currentKey = Object.keys(data.predictions).find(key => data.predictions[key].TideStatus === 'CURRENT');
//find the Object ID based on the TideStatus key
var CurTide = 0;
var PTide = 0;
var NTide = 0;
CurTide = currentKey;
PTide = CurTide; //solving for javascript math weirdness
PTide--; //subtrack one from CurTide to get Previous Tide
NTide = CurTide;
NTide++; //Add one to CurTide to get next tide
var TideTypePrevious = data.predictions[PTide].type;
var TideHeightPrevious = data.predictions[PTide].v;
var TideTimePrevious = new Date(data.predictions[PTide].t);
if (this.config.debug === 1) {
Log.info("---PREVIOUS TIDE--- " + TideTypePrevious + " tide was at: " + TideTimePrevious + " with a height of " + TideHeightPrevious + " ft.");
}
this.TideTimeCurrent = new Date(data.predictions[CurTide].t); //Object variable t for time
this.TideHeightCurrent = this.roundValue(data.predictions[CurTide].v); // Current tide height
this.TideTypeCurrent = data.predictions[CurTide].type; // High or Low
if (this.config.debug === 1) {
Log.info("***CURRENT TIDE*** " + this.DeltaPerc + "% into " + this.TideTypeCurrent + " tide. Full tide @ " + this.TideTimeCurrent.getHours() + ":" + this.TideTimeCurrent.getMinutes() + "with a height of " + this.TideHeightCurrent + "ft.");
}
this.TideTimeNext = new Date(data.predictions[NTide].t);
this.TideHeightNext = this.roundValue(data.predictions[NTide].v);
this.TideTypeNext = data.predictions[NTide].type;
if (this.config.debug === 1) {
Log.info("+++NEXT TIDE+++ " + this.TideTypeNext + " tide is at: " + this.TideTimeNext + " with a height of " + this.TideHeightNext + " ft.");
}
this.loaded = true;
this.updateDom(this.config.animationSpeed);
if (this.config.debug === 1) { Log.info(moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' Rendering NOAA Tide data to UI (7)'); }
if (this.config.debug === 1) { Log.info('-------------------------------------------------------------------'); }
}, // end processNOAA_TIDE_DATA function
/* processNOAA_WATERTEMP(data)
*
* Processes NOAA Water Temperature data to find
* current water temperature
*
*/
processNOAA_WATERTEMP: function(data) {
//Example JSON structure:
//"metadata":{"id":"8534720","name":"Atlantic City","lat":"39.3550","lon":"-74.4183"},
//"data": [{"t":"2017-11-24 00:00", "v":"50.7", "f":"0,0,0"}
if (this.config.debug === 1) { Log.info(moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + " Processing Data: NOAA Water Temp (6)") };
if (this.config.debug === 1) { Log.info(data); } //print Object to browser console
var stationID = data.metadata.id; //only used in debug mode currently
var stationName = data.metadata.name; //only used in debug mode currently
//var coords_lat = data.metadata.lat; //not used
//var coords_lon = data.metadata.lon; //not used
//Effeciency assumption: most current reading will always be last element
//NOAA provides 13 measurements. Object counts start at 0...need to subtract 1 to get to item 12, the most recent measurement
var now = new Date();
var CurrentHour = now.getHours();
var WaterTempLength = data.data.length - 1;
var WaterTempTime = new Date(data.data[WaterTempLength].t);
var WaterTempHour = WaterTempTime.getHours();
this.WaterTemp = data.data[WaterTempLength].v; // pull current water temp from data.
if (this.config.debug === 1) {
Log.info("***CURRENT WATER*** temperature at " + stationName + " is: " + this.WaterTemp + " at " + WaterTempTime + ".");
}
this.loaded = true;
this.updateDom(this.config.animationSpeed);
if (this.config.debug === 1) { Log.info(moment().format('YYYY-MM-DDTHH:mm:ss.SSSZZ') + ' Rendering NOAA Water Temp data to UI (7)'); }
if (this.config.debug === 1) { Log.info('-------------------------------------------------------------------'); }