-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquick.html
More file actions
930 lines (808 loc) · 32.7 KB
/
quick.html
File metadata and controls
930 lines (808 loc) · 32.7 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SLU Aviation Weather Dashboard - Quick View</title>
<link rel="icon" href="assets/favicon.svg" type="image/svg+xml">
<link rel="shortcut icon" href="assets/favicon.svg" type="image/svg+xml">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
html, body {
height: 100vh;
overflow: hidden;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #1a1a1a;
color: #e0e0e0;
}
body {
display: flex;
flex-direction: column;
}
header {
background-color: #2a2a2a;
padding: 10px 20px;
border-bottom: 3px solid #ffa500;
flex-shrink: 0;
}
h1 {
color: #ffa500;
font-size: 1.5em;
text-align: center;
margin: 0;
}
.dashboard-grid {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr;
padding: 10px;
gap: 10px;
flex: 1;
min-height: 0;
overflow: hidden;
}
.flight-status-section {
grid-column: 1;
grid-row: 1;
display: flex;
flex-direction: column;
min-height: 0;
}
.announcements-section {
grid-column: 2;
grid-row: 1;
background-color: #2a2a2a;
border: 2px solid #ffa500;
border-radius: 8px;
padding: 15px;
overflow-y: auto;
min-height: 0;
}
.metar-section {
grid-column: 1;
grid-row: 2;
display: flex;
flex-direction: column;
gap: 8px;
overflow-y: auto;
min-height: 0;
}
.weather-conditions-section {
grid-column: 2;
grid-row: 2;
display: flex;
flex-direction: column;
min-height: 0;
overflow-y: auto;
}
h2, h3 {
color: #ffa500;
margin: 0 0 8px 0;
font-size: 1.1em;
flex-shrink: 0;
}
/* KCPS fallback badge */
.fallback-badge {
display: none;
margin-left: 8px;
padding: 2px 6px;
font-size: 0.7em;
border-radius: 999px;
background-color: rgba(255, 152, 0, 0.15);
color: #ffb74d;
border: 1px solid #444;
vertical-align: middle;
white-space: nowrap;
}
.metar-time {
font-weight: normal;
font-size: 0.85em;
color: #999;
}
.metar {
background-color: #2a2a2a;
padding: 10px;
white-space: pre-wrap;
font-size: 0.9em;
font-family: 'Courier New', monospace;
border-radius: 5px;
border: 1px solid #444;
flex-shrink: 0;
overflow: hidden;
}
.announcement-item {
margin-bottom: 12px;
padding: 10px;
border-left: 4px solid #ff6b35;
background-color: #1a1a1a;
border-radius: 4px;
}
.announcement-date {
font-size: 0.75em;
color: #999;
margin-bottom: 5px;
}
.announcement-title {
font-weight: bold;
color: #ffa500;
margin-bottom: 5px;
font-size: 0.95em;
}
.announcement-content {
font-size: 0.85em;
line-height: 1.3;
}
.flight-status-card {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
background-color: #2a2a2a;
border-radius: 12px;
padding: 20px;
border: 3px solid;
text-align: center;
}
.flight-status-card.cat-a {
border-color: #548235;
background: linear-gradient(135deg, rgba(84, 130, 53, 0.16), rgba(84, 130, 53, 0.07));
}
.flight-status-card.cat-b {
border-color: #ffff00;
background: linear-gradient(135deg, rgba(255, 255, 0, 0.20), rgba(255, 255, 0, 0.10));
}
.flight-status-card.cat-c {
border-color: #ed7d31;
background: linear-gradient(135deg, rgba(237, 125, 49, 0.20), rgba(237, 125, 49, 0.10));
}
.flight-status-card.cat-d {
border-color: #ff0000;
background: linear-gradient(135deg, rgba(255, 0, 0, 0.18), rgba(255, 0, 0, 0.08));
}
.flight-status-card.cat-f {
border-color: #000000;
background: linear-gradient(135deg, rgba(20, 20, 20, 0.9), rgba(45, 45, 45, 0.8));
}
.status-title {
font-size: 3.3em;
line-height: 1;
font-weight: bold;
margin-bottom: 10px;
}
.flight-status-card.cat-a .status-title { color: #548235; }
.flight-status-card.cat-b .status-title { color: #000; }
.flight-status-card.cat-c .status-title { color: #ed7d31; }
.flight-status-card.cat-d .status-title,
.flight-status-card.cat-f .status-title { color: #fff; }
.status-details {
font-size: 1em;
color: #ccc;
line-height: 1.4;
}
.weather-conditions-card {
background-color: #2a2a2a;
border: 2px solid #4a90e2;
border-radius: 8px;
padding: 15px;
flex: 1;
overflow-y: auto;
min-height: 0;
}
.weather-metrics {
display: grid;
grid-template-columns: 1fr 1fr;
grid-template-rows: 1fr 1fr 1fr;
gap: 8px;
height: 100%;
}
.weather-metric {
background-color: #1a1a1a;
border: 2px solid #4a90e2;
border-radius: 6px;
padding: 8px;
display: flex;
align-items: center;
gap: 8px;
transition: all 0.3s ease;
}
.weather-metric.warning {
border-color: #ff9800;
background-color: rgba(255, 152, 0, 0.1);
}
.weather-metric.alert {
border-color: #f44336;
background-color: rgba(244, 67, 54, 0.1);
}
.weather-icon {
font-size: 2em;
flex-shrink: 0;
}
.weather-info {
flex: 1;
min-width: 0;
}
.weather-label {
font-size: 0.7em;
color: #999;
text-transform: uppercase;
margin-bottom: 2px;
}
.weather-value {
font-size: 1.2em;
font-weight: bold;
color: #e0e0e0;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.footer {
text-align: center;
padding: 5px 10px;
background-color: #2a2a2a;
color: #999;
border-top: 1px solid #444;
font-size: 0.7em;
flex-shrink: 0;
}
.footer p {
margin: 2px 0;
line-height: 1.3;
}
#updateTime {
color: #ffa500;
font-weight: bold;
}
/* Airport closed overlay */
.airport-closed-overlay {
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(211, 47, 47, 0.95);
display: none;
justify-content: center;
align-items: center;
z-index: 100;
border-radius: 12px;
}
.airport-closed-overlay.active {
display: flex;
}
.airport-closed-message {
color: white;
text-align: center;
padding: 20px;
}
.airport-closed-message h2 {
font-size: 2em;
margin: 0 0 15px 0;
color: white;
text-transform: uppercase;
letter-spacing: 2px;
}
.airport-closed-message p {
font-size: 1.2em;
margin: 10px 0;
line-height: 1.5;
}
.airport-closed-message .icon {
font-size: 3em;
margin-bottom: 15px;
}
/* Position overlay only over flight status section */
.flight-status-section {
position: relative;
}
</style>
</head>
<body>
<header>
<h1>SLU Aviation Weather Dashboard</h1>
</header>
<div class="dashboard-grid">
<!-- Flight Status Section (Top Left) -->
<div class="flight-status-section">
<!-- Airport Closed Overlay (inside flight status section) -->
<div id="airportClosedOverlay" class="airport-closed-overlay">
<div class="airport-closed-message">
<div class="icon">🚫</div>
<h2>All flights are grounded</h2>
<p><strong>See airport announcements for details</strong></p>
</div>
</div>
<div id="overall-flight-status" class="flight-status-card cat-a">
<div class="status-title">A</div>
<div class="status-details">Loading weather conditions...</div>
</div>
</div>
<!-- Announcements Section (Top Right) -->
<div class="announcements-section">
<h2>Airport Announcements</h2>
<div id="announcements-content">
<div class="announcement-item">
<div class="announcement-title">Loading announcements...</div>
</div>
</div>
</div>
<!-- METAR Section (Bottom Left) -->
<div class="metar-section">
<h3>METAR Data</h3>
<div>
<h3>KCPS METAR <span id="kcps-time" class="metar-time"></span></h3>
<div id="kcps-metar" class="metar">Loading KCPS METAR...</div>
</div>
<div>
<h3>KSTL METAR <span id="kstl-time" class="metar-time"></span></h3>
<div id="kstl-metar" class="metar">Loading KSTL METAR...</div>
</div>
</div>
<!-- Weather Conditions Section (Bottom Right) -->
<div class="weather-conditions-section">
<div class="weather-conditions-card">
<h3>Current Weather Conditions <span id="fallbackBadgeQuick" class="fallback-badge" title="KCPS unavailable — using KSTL conditions">Using KSTL</span></h3>
<div id="metar-embed-container" style="display: flex; justify-content: center; align-items: center; height: calc(100% - 35px);">
<a href="https://metar-taf.com/metar/KCPS" id="metartaf-quick" style="font-size:18px; font-weight:500; color:#000; width:100%; height:100%; display:block">METAR St. Louis Downtown Airport</a>
</div>
<div id="weather-metrics-fallback" class="weather-metrics" style="display: none;">
<div class="weather-metric" id="temp-metric">
<div class="weather-icon">🌡️</div>
<div class="weather-info">
<div class="weather-label">Temperature</div>
<div class="weather-value" id="temp-value">-- °F</div>
</div>
</div>
<div class="weather-metric" id="heatindex-metric">
<div class="weather-icon">🔥</div>
<div class="weather-info">
<div class="weather-label">Heat Index</div>
<div class="weather-value" id="heatindex-value">-- °F</div>
</div>
</div>
<div class="weather-metric" id="wind-metric">
<div class="weather-icon">🌬️</div>
<div class="weather-info">
<div class="weather-label">Wind</div>
<div class="weather-value" id="wind-value">-- kt</div>
</div>
</div>
<div class="weather-metric" id="visibility-metric">
<div class="weather-icon">👁️</div>
<div class="weather-info">
<div class="weather-label">Visibility</div>
<div class="weather-value" id="visibility-value">-- SM</div>
</div>
</div>
<div class="weather-metric" id="clouds-metric">
<div class="weather-icon">☁️</div>
<div class="weather-info">
<div class="weather-label">Ceiling</div>
<div class="weather-value" id="clouds-value">-- ft</div>
</div>
</div>
<div class="weather-metric" id="crosswind-metric">
<div class="weather-icon">💨</div>
<div class="weather-info">
<div class="weather-label">Max Crosswind</div>
<div class="weather-value" id="crosswind-value">-- kt</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="footer">
<p>Data last updated: <span id="updateTime">N/A</span></p>
<p>Disclaimer: This page provides general aviation weather information and restrictions for planning purposes only. Always consult official weather briefings and Air Traffic Control for actual flight operations.</p>
</div>
<!-- Shared weather utilities -->
<script src="shared-weather.js"></script>
<script>
const kcpsElevation = 413;
const kstlElevation = 618;
const KCPS_RUNWAY_12_HDG = 122;
const KCPS_RUNWAY_30_HDG = 302;
function getMinutesAgo(timestamp) {
if (!timestamp) return '';
const metarTime = new Date(timestamp);
const now = new Date();
const diffMinutes = Math.floor((now - metarTime) / (1000 * 60));
if (diffMinutes < 1) return '(< 1 min ago)';
if (diffMinutes < 60) return `(${diffMinutes} min${diffMinutes > 1 ? 's' : ''} ago)`;
const hours = Math.floor(diffMinutes / 60);
const mins = diffMinutes % 60;
if (hours === 1 && mins === 0) return '(1 hr ago)';
if (mins === 0) return `(${hours} hrs ago)`;
return `(${hours} hr${hours > 1 ? 's' : ''} ${mins} min${mins > 1 ? 's' : ''} ago)`;
}
// A-F category system matching the operations manual and dashboard.html
let lastQuickCategory = { category: 'A', categoryClass: 'cat-a', details: 'No solo restrictions in effect.' };
function updateQuickCategoryCard(letter, categoryClass, details) {
const card = document.getElementById('overall-flight-status');
if (!card) return;
card.className = `flight-status-card ${categoryClass}`;
card.innerHTML = `
<div class="status-title">${letter}</div>
<div class="status-details">${details}</div>
`;
}
function calculateFlightCategory(data) {
const effectiveWind = getEffectiveWindSpeed(data.windSpeed, data.windGust);
let cw12 = null, cw30 = null;
if (data.windDirection != null && data.windSpeed != null) {
cw12 = calculateCrosswind(data.windDirection, data.windSpeed, KCPS_RUNWAY_12_HDG, data.windGust);
cw30 = calculateCrosswind(data.windDirection, data.windSpeed, KCPS_RUNWAY_30_HDG, data.windGust);
}
const ceilingRestricted = isCeilingRestricted(data.cloudCeiling);
const visRestricted = isVisibilityRestricted(data.visibility);
const studentSurfaceRestricted = effectiveWind !== null && effectiveWind >= 20;
const studentCrossRestricted = (cw12 !== null && cw12 > 10) || (cw30 !== null && cw30 > 10);
const privateSurfaceRestricted = effectiveWind !== null && effectiveWind >= 25;
const privateCrossRestricted = (cw12 !== null && cw12 > 15) || (cw30 !== null && cw30 > 15);
const instCommSurfaceRestricted = effectiveWind !== null && effectiveWind >= 30;
const instCommCrossRestricted = (cw12 !== null && cw12 > 20) || (cw30 !== null && cw30 > 20);
let tempStudentRestricted = false, tempPrivateRestricted = false, tempInstCommRestricted = false;
if (data.temperatureC != null) {
const tempF = data.temperatureC * 9 / 5 + 32;
if (tempF <= 5) tempInstCommRestricted = true;
else if (tempF <= 14) tempPrivateRestricted = true;
else if (tempF <= 23) tempStudentRestricted = true;
if (data.dewPointC != null && tempF >= 80) {
const T = data.temperatureC, DP = data.dewPointC;
const rh = 100 * Math.exp((17.625 * DP) / (243.04 + DP)) / Math.exp((17.625 * T) / (243.04 + T));
const hi = calculateHeatIndex(tempF, rh);
if (hi != null) {
if (hi >= 105) tempInstCommRestricted = true;
else if (hi >= 100) tempPrivateRestricted = true;
else if (hi >= 95) tempStudentRestricted = true;
}
}
}
const studentRestricted = ceilingRestricted || visRestricted || studentSurfaceRestricted || studentCrossRestricted || tempStudentRestricted;
const privateRestricted = ceilingRestricted || visRestricted || privateSurfaceRestricted || privateCrossRestricted || tempPrivateRestricted;
const instCommRestricted = ceilingRestricted || visRestricted || instCommSurfaceRestricted || instCommCrossRestricted || tempInstCommRestricted;
// Shared factors (ceiling/vis affect all levels equally)
const sharedFactors = [];
if (ceilingRestricted) sharedFactors.push('ceiling below 1,500 ft AGL');
if (visRestricted) sharedFactors.push('visibility below 3 SM');
if (instCommRestricted) {
const factors = [...sharedFactors];
if (instCommSurfaceRestricted) factors.push('surface winds at or above 30 kt');
if (instCommCrossRestricted) factors.push('crosswind above 20 kt');
if (tempInstCommRestricted) factors.push('temperature/heat index');
return { category: 'D', categoryClass: 'cat-d', details: `Instrument/Commercial solo restricted: ${factors.join(', ')}` };
}
if (privateRestricted) {
const factors = [...sharedFactors];
if (privateSurfaceRestricted) factors.push('surface winds at or above 25 kt');
if (privateCrossRestricted) factors.push('crosswind above 15 kt');
if (tempPrivateRestricted) factors.push('temperature/heat index');
return { category: 'C', categoryClass: 'cat-c', details: `Private pilot solo restricted: ${factors.join(', ')}` };
}
if (studentRestricted) {
const factors = [...sharedFactors];
if (studentSurfaceRestricted) factors.push('surface winds at or above 20 kt');
if (studentCrossRestricted) factors.push('crosswind above 10 kt');
if (tempStudentRestricted) factors.push('temperature/heat index');
return { category: 'B', categoryClass: 'cat-b', details: `Student pilot solo restricted: ${factors.join(', ')}` };
}
return { category: 'A', categoryClass: 'cat-a', details: 'No solo restrictions in effect.' };
}
let metarRefreshTimer = null;
let metarScriptEl = null;
function refreshMetarTafWidget() {
const container = document.getElementById('metar-embed-container');
if (!container) return;
if (metarRefreshTimer) clearTimeout(metarRefreshTimer);
metarRefreshTimer = setTimeout(() => {
const anchorId = 'metartaf-quick';
let anchor = document.getElementById(anchorId);
if (!anchor) {
anchor = document.createElement('a');
anchor.href = 'https://metar-taf.com/metar/KCPS';
anchor.id = anchorId;
anchor.style.cssText = 'font-size:18px; font-weight:500; color:#000; width:100%; height:100%; display:block';
anchor.textContent = 'METAR St. Louis Downtown Airport';
container.innerHTML = '';
container.appendChild(anchor);
}
if (metarScriptEl && metarScriptEl.parentNode) {
metarScriptEl.parentNode.removeChild(metarScriptEl);
metarScriptEl = null;
}
const script = document.createElement('script');
script.async = true;
const bgColor = '333333'; // Quick view is dark-themed
// Vendor expects anchor id 'metartaf-' + target
script.src = `https://metar-taf.com/embed-js/KCPS?bg_color=${bgColor}&layout=landscape&visibility=mi&qnh=inHg&rh=dp&target=quick`;
metarScriptEl = script;
container.appendChild(script);
}, 250);
}
async function fetchWeatherData() {
try {
const data = await fetchWeatherDataFromJSON();
if (!data) {
throw new Error('Failed to fetch weather data');
}
// Update timestamp
const updateTimeElement = document.getElementById('updateTime');
if (updateTimeElement) {
updateTimeElement.textContent = new Date().toLocaleString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric',
hour: 'numeric',
minute: '2-digit',
hour12: true
});
}
const kcpsMetarValid = !!(data.kcps && data.kcps.metar && data.kcps.metar.trim().replace(/\0/g, '').length > 0);
const kstlMetarValid = !!(data.kstl && data.kstl.metar && data.kstl.metar.trim().replace(/\0/g, '').length > 0);
// Display KCPS METAR
if (kcpsMetarValid) {
document.getElementById("kcps-metar").innerText = data.kcps.metar.replace(/\0/g, '');
if (data.kcps.timestamp) {
document.getElementById("kcps-time").innerText = getMinutesAgo(data.kcps.timestamp);
}
} else {
document.getElementById("kcps-metar").innerText = "KCPS METAR unavailable";
}
// Display KSTL METAR
if (kstlMetarValid) {
document.getElementById("kstl-metar").innerText = data.kstl.metar.replace(/\0/g, '');
if (data.kstl.timestamp) {
document.getElementById("kstl-time").innerText = getMinutesAgo(data.kstl.timestamp);
}
} else {
document.getElementById("kstl-metar").innerText = "KSTL METAR unavailable";
}
// Use KCPS data preferentially; fall back to KSTL when KCPS unavailable
const weatherData = kcpsMetarValid ? data.kcps : (kstlMetarValid ? data.kstl : null);
// Toggle fallback badge visibility
const fbQuick = document.getElementById('fallbackBadgeQuick');
if (fbQuick) fbQuick.style.display = (!kcpsMetarValid && kstlMetarValid) ? 'inline-block' : 'none';
if (weatherData) {
// Calculate and display flight category
const cat = calculateFlightCategory(weatherData);
lastQuickCategory = cat;
updateQuickCategoryCard(cat.category, cat.categoryClass, cat.details);
// Update weather graphics (for fallback)
updateWeatherGraphics(weatherData);
// Refresh the METAR-TAF widget with new data
refreshMetarTafWidget();
}
} catch (err) {
console.error('Error fetching weather data:', err);
const kcpsEl = document.getElementById('kcps-metar');
const kstlEl = document.getElementById('kstl-metar');
if (kcpsEl) kcpsEl.innerText = 'Error loading weather data';
if (kstlEl) kstlEl.innerText = 'Error loading weather data';
}
}
function updateWeatherGraphics(data) {
// Temperature (restrictions: cold temps only)
if (data.temperatureC !== undefined && data.temperatureC !== null) {
const tempF = data.temperatureC * 9/5 + 32;
document.getElementById('temp-value').textContent = `${tempF.toFixed(0)}°F`;
const tempMetric = document.getElementById('temp-metric');
tempMetric.classList.remove('warning', 'alert');
if (tempF <= 5) {
tempMetric.classList.add('alert');
} else if (tempF <= 23) {
tempMetric.classList.add('warning');
}
}
// Heat Index (restrictions: >=95/100/105)
if (data.temperatureC !== undefined && data.dewPointC !== undefined) {
const tempC = data.temperatureC;
const dewpointC = data.dewPointC;
const tempF = tempC * 9/5 + 32;
const humidity = 100 * Math.exp((17.625 * dewpointC) / (243.04 + dewpointC)) / Math.exp((17.625 * tempC) / (243.04 + tempC));
const hiMetric = document.getElementById('heatindex-metric');
const hiValueEl = document.getElementById('heatindex-value');
hiMetric.classList.remove('warning', 'alert');
if (tempF >= 80) {
const heatIndex = calculateHeatIndex(tempF, humidity);
if (heatIndex != null) {
hiValueEl.textContent = `${heatIndex.toFixed(0)}°F`;
if (heatIndex >= 105) {
hiMetric.classList.add('alert');
} else if (heatIndex >= 95) {
hiMetric.classList.add('warning');
}
} else {
hiValueEl.textContent = '-- °F';
}
} else {
hiValueEl.textContent = '-- °F';
}
}
// Wind (use gust if higher for thresholds)
if ((data.windSpeed !== undefined && data.windSpeed !== null) || (data.windGust !== undefined && data.windGust !== null)) {
const windDir = data.windDirection || 0;
const displayWind = data.windSpeed ?? '--';
const gustText = ((data.windGust ?? 0) > 0) ? ` G${data.windGust}` : '';
document.getElementById('wind-value').textContent = `${windDir}° @ ${displayWind} kt${gustText}`;
const effWind = getEffectiveWindSpeed(data.windSpeed, data.windGust);
const windMetric = document.getElementById('wind-metric');
windMetric.classList.remove('warning', 'alert');
if (effWind !== null) {
if (effWind > 25) {
windMetric.classList.add('alert');
} else if (effWind > 20) {
windMetric.classList.add('warning');
}
}
}
// Visibility (Unified: alert when < 3 SM)
if (data.visibility !== undefined && data.visibility !== null) {
document.getElementById('visibility-value').textContent = `${data.visibility} SM`;
const visMetric = document.getElementById('visibility-metric');
visMetric.classList.remove('warning', 'alert');
if (isVisibilityRestricted(data.visibility)) {
visMetric.classList.add('alert');
}
}
// Clouds/Ceiling (Unified: alert when AGL < 1,500 ft)
// METAR cloudCeiling is already in AGL format
if (data.cloudCeiling !== undefined && data.cloudCeiling !== null) {
if (data.cloudCeiling >= 99999) {
document.getElementById('clouds-value').textContent = 'Clear';
} else {
document.getElementById('clouds-value').textContent = `${data.cloudCeiling} ft AGL`;
const cloudsMetric = document.getElementById('clouds-metric');
cloudsMetric.classList.remove('warning', 'alert');
if (isCeilingRestricted(data.cloudCeiling)) {
cloudsMetric.classList.add('alert');
}
}
}
// Crosswind
if (data.windDirection !== undefined && data.windSpeed !== undefined) {
const crosswind12 = calculateCrosswind(data.windDirection, data.windSpeed, KCPS_RUNWAY_12_HDG);
const crosswind30 = calculateCrosswind(data.windDirection, data.windSpeed, KCPS_RUNWAY_30_HDG);
const maxCrosswind = Math.max(crosswind12, crosswind30);
document.getElementById('crosswind-value').textContent = `${maxCrosswind.toFixed(1)} kt`;
const crosswindMetric = document.getElementById('crosswind-metric');
crosswindMetric.classList.remove('warning', 'alert');
if (maxCrosswind > 15) {
crosswindMetric.classList.add('alert');
} else if (maxCrosswind > 10) {
crosswindMetric.classList.add('warning');
}
}
}
function checkMetarEmbedLoad() {
// Wait a few seconds for the embed to load
setTimeout(() => {
const embedContainer = document.getElementById('metar-embed-container');
const embedTarget = document.getElementById('metartaf-quick');
const fallback = document.getElementById('weather-metrics-fallback');
// Check if embed loaded successfully by checking if content was replaced
if (embedTarget && embedTarget.textContent === 'METAR St. Louis Downtown Airport') {
// Embed didn't load, show fallback
console.warn('METAR-TAF embed failed to load, showing fallback');
embedContainer.style.display = 'none';
fallback.style.display = 'grid';
}
}, 5000); // Wait 5 seconds for embed to load
}
async function fetchAnnouncements() {
try {
const owner = 'CenterForDigitalHumanities';
const repo = 'aviation-dashboard';
// Fetch discussions directly from GitHub API
// Note: This uses the public REST API endpoint for discussions
const discussionsUrl = `https://api.github.com/repos/${owner}/${repo}/discussions`;
const response = await fetch(discussionsUrl, {
headers: {
'Accept': 'application/vnd.github.v3+json'
}
});
if (!response.ok) {
console.warn(`GitHub API returned ${response.status}, falling back to default announcement`);
showDefaultAnnouncement();
return;
}
const discussions = await response.json();
// Filter for announcements (category name or label)
const announcements = discussions
.filter(d => d.category?.name === 'Announcements')
.filter(d => d.state === 'open')
.sort((a, b) => new Date(b.created_at) - new Date(a.created_at)) // Newest first
.slice(0, 10) // Limit to 10 most recent
.map(d => ({
title: d.title,
content: d.body || '',
date: d.created_at
}));
if (announcements.length === 0) {
const container = document.getElementById('announcements-content');
container.innerHTML = `
<div class="announcement-item">
<div class="announcement-title">No announcements at this time</div>
<div class="announcement-content">Check back later for updates.</div>
</div>
`;
return;
}
displayAnnouncements(announcements);
} catch (error) {
console.error('Error fetching announcements:', error);
showDefaultAnnouncement();
}
}
function displayAnnouncements(announcements) {
const container = document.getElementById('announcements-content');
// Check if any announcement contains #noflying
const hasNoFlying = announcements.some(a =>
(a.title && a.title.toLowerCase().includes('#noflying')) ||
(a.content && a.content.toLowerCase().includes('#noflying'))
);
// Show overlay if #noflying is present
const overlay = document.getElementById('airportClosedOverlay');
if (hasNoFlying && overlay) {
overlay.classList.add('active');
} else if (overlay) {
overlay.classList.remove('active');
}
// Update flight category card: F for no-fly, otherwise restore last weather category
if (hasNoFlying) {
updateQuickCategoryCard('F', 'cat-f', 'No flights. See airport announcements for details.');
} else {
updateQuickCategoryCard(lastQuickCategory.category, lastQuickCategory.categoryClass, lastQuickCategory.details);
}
container.innerHTML = announcements.map(announcement => {
const date = new Date(announcement.date);
const formattedDate = date.toLocaleDateString('en-US', {
month: 'short',
day: 'numeric',
year: 'numeric'
});
// Strip HTML tags from content for display
const strippedContent = announcement.content.replace(/<[^>]*>/g, '');
// Limit content length
const truncatedContent = strippedContent.length > 200
? strippedContent.substring(0, 200) + '...'
: strippedContent;
return `
<div class="announcement-item">
<div class="announcement-date">${formattedDate}</div>
<div class="announcement-title">${announcement.title}</div>
<div class="announcement-content">${truncatedContent}</div>
</div>
`;
}).join('');
}
function showDefaultAnnouncement() {
const container = document.getElementById('announcements-content');
container.innerHTML = `
<div class="announcement-item">
<div class="announcement-title">Welcome to the Aviation Dashboard</div>
<div class="announcement-content">This dashboard provides real-time weather conditions and flight
restrictions for SLU Aviation operations. Please check this section regularly for important updates.
</div>
</div>
`;
}
// Initial fetch on page load
fetchWeatherData();
fetchAnnouncements();
// Load the METAR-TAF widget initially
refreshMetarTafWidget();
// Check if METAR embed loads successfully
checkMetarEmbedLoad();
// Set up auto-refresh timers
// Refresh weather data every 5 minutes (300000 milliseconds)
setInterval(fetchWeatherData, 300000);
// Refresh announcements every 15 minutes (900000 milliseconds)
setInterval(fetchAnnouncements, 900000);
</script>
</body>
</html>