-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathstations.html
More file actions
620 lines (532 loc) · 23.8 KB
/
stations.html
File metadata and controls
620 lines (532 loc) · 23.8 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
<!DOCTYPE html>
<html lang='en'>
<head>
<!-- map of WeeWX weather stations, by matthew wall -->
<!-- the page includes a map, a list of stations (station_table_div), and a -->
<!-- list of hardware (hardware_types_div). it also includes a small graph -->
<!-- that contains a histogram of when the last contact was made over -->
<!-- the past 'pingdays' days. -->
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<meta name='viewport' content='initial-scale=1'/>
<title>WeeWX: Stations Running WeeWX</title>
<link href='css/weewx.css' rel='stylesheet' type='text/css'/>
<script src='js/showcase.js' type='text/javascript'></script>
<script src='js/md5.js' type='text/javascript'></script>
<script src='js/echo.js' type='text/javascript'></script>
<script src='js/google-api-key.js' type='text/javascript'></script>
<style>
#map_container {
margin-top: 10px;
}
#map_canvas {
border: 1px solid #5f8ea9;
height: 500px;
}
.location {
font-family: Helvetic, Arial, sans-serif;
font-size: 10pt;
font-weight: bold;
max-width: 200px;
margin: 0;
}
.location_details {
font-family: Helvetic, Arial, sans-serif;
font-size: 8pt;
float: left;
padding-right: 20px;
}
.location_img {
float: right;
}
.gm-style-iw {
width: 250px;
}
.details {
font-style: italic;
text-align: right;
font-size: 80%;
}
#content {
width: auto;
}
#instructions {
padding-right: 20px;
}
#hardware_summary {
float: right;
padding-bottom: 30px;
}
#ping_details_container {
padding-top: 10px;
padding-bottom: 20px;
}
#hardware_types_div td {
padding-right: 10px;
}
#sites {
padding-top: 20px;
padding-right: 20px;
padding-bottom: 30px;
}
#station_table_div table {
padding-top: 10px;
}
#station_table_div td {
background-repeat: no-repeat;
background-position: center;
vertical-align: top;
}
.sort_buttons {
padding-top: 10px;
padding-bottom: 10px;
}
.button_pair {
float: left;
padding-left: 10px;
padding-right: 10px;
font-weight: normal;
}
.alignright {
text-align: right;
}
.oddrow {
background-color: #f4f4f4;
}
.evenrow {
background-color: #ffffff;
}
.indicator {
width: 18px;
border: 1px solid #2f5e79;
cursor: cell;
}
.thumbnail {
height: 104px;
}
.infoBox {
background: url('/images/tipbox90pad.gif') no-repeat scroll 0 18px;
width: 250px;
}
.info-content {
overflow: hidden;
background-color: #ffffff;
border: 1px solid #555555;
margin-left: 10px;
padding: 4px;
}
</style>
<script type='text/javascript'>
// Asynchronously load Google Maps API, InfoBox API, and station data.
async function load() {
// Start fetching station data immediately
const fetchPromise = fetch("/api/v2/stations/?limit=3000&slim=1").then(response => response.json());
// Load the Google Maps API.
const gmapPromise = new Promise(resolve => {
window.gmapCallback = resolve;
const script = document.createElement('script');
script.src = `https://maps.googleapis.com/maps/api/js?key=${google_key}&callback=gmapCallback&loading=async`;
script.async = true;
document.head.appendChild(script);
});
// Wait for Google Maps and station data to load.
const [_, sites] = await Promise.all([gmapPromise, fetchPromise]);
// Once Google Maps is loaded, we can import InfoBox.
const {InfoBox} = await import("./js/infobox-1.1.19.js");
// Initialize the map and UI.
initMap(InfoBox, sites);
}
// Main initialization function
function initMap(InfoBox, sites) {
let map;
let showThumbs = true;
let oldZoomLevel = 0;
const infowindow = new InfoBox({
content: 'nothing selected',
disableAutoPan: false,
maxWidth: 0,
pixelOffset: new google.maps.Size(10, -50),
zIndex: null,
closeBoxMargin: "2px 2px 2px 2px",
closeBoxURL: "images/close.gif",
infoBoxClearance: new google.maps.Size(1, 1),
isHidden: false,
pane: "floatPane",
enableEventPropagation: false
});
const zoomThreshold = 9; /* when to switch from dots to pins */
const pingdays = 30; /* number of days in ping histogram */
const staledays = 7; /* number of days before considered stale */
const backgroundColor = '#ffffff';
const highlightColor = '#9fcef9';
const maxTitleLen = 70;
const redDotURL = './images/dot-red.png';
function initialize() {
const now = Math.round((new Date()).getTime() / 1000);
/* create a map with the settings we want */
const settings = {
zoom: 2,
center: new google.maps.LatLng(21.0, 0.0),
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
const canvas = document.getElementById("map_canvas");
map = new google.maps.Map(canvas, settings);
map.addListener('zoom_changed', () => {
const zoomLevel = map.getZoom();
if ((oldZoomLevel < zoomThreshold && zoomLevel >= zoomThreshold) ||
(oldZoomLevel >= zoomThreshold && zoomLevel < zoomThreshold)) {
set_marker_image(map);
}
oldZoomLevel = zoomLevel;
});
/* track counts of each station type */
const counts = {total: 0};
/* histogram of when each station last phoned home */
let maxpings = 0;
const pings = new Array(pingdays).fill(0);
let stale = 0;
let dead = 0;
/* loop through all sites to get the data we need */
sites.forEach((site, i) => {
const title = decode_html(get_title(site));
const pos = new google.maps.LatLng(site.latitude, site.longitude);
const mkr = new google.maps.Marker({
position: pos,
map: map,
title: `${title}\n${site.station_type}`,
icon: redDotURL,
});
site.marker = mkr;
attach_info(map, mkr, i);
/* do the station count accounting */
counts.total++;
counts[site.station_type] = (counts[site.station_type] || 0) + 1;
/* do the ping accounting */
const tdiff = now - site.last_seen;
const idx = Math.round(tdiff / 86400);
if (idx < pingdays) {
pings[idx]++;
if (idx > staledays) {
stale++;
}
} else {
dead++;
}
if (pings[idx] > maxpings) {
maxpings = pings[idx];
}
});
build_station_table('description', 'up');
populate_hardware_table(counts);
draw_ping_histogram(pings, maxpings, counts.total, stale, dead);
// Add event listeners for toggles
document.getElementById('hardware_summary_toggle').addEventListener('click', function () {
toggle(this, 'hardware_types_div');
});
document.getElementById('sites_toggle').addEventListener('click', function () {
toggle(this, 'station_table_div');
});
}
function set_marker_image(map) {
const z = map.getZoom();
const url = z < zoomThreshold ? redDotURL : '';
sites.forEach(site => site.marker.setIcon(url));
}
function build_station_table(sort_metric, sort_order) {
const station_table_div = document.getElementById('station_table_div');
station_table_div.innerHTML = '';
const tbl = document.createElement('table');
const thead = document.createElement('thead');
const station_list_body = document.createElement('tbody');
station_list_body.id = 'station_list_body';
const tr = document.createElement('tr');
const th = document.createElement('th');
th.colSpan = 4;
th.className = 'sort_buttons';
['Description', 'URL', 'Latitude', 'Longitude', 'Hardware', 'Version', 'Last Seen'].forEach(label => {
const metric = label.toLowerCase().replace(' ', '_');
const sortParam = metric === 'description' ? 'description' :
metric === 'url' ? 'station_url' :
metric === 'hardware' ? 'station_type' :
metric === 'version' ? 'weewx_info' : metric;
th.appendChild(create_buttons(station_list_body, label, sortParam));
});
const thumbButton = document.createElement('input');
thumbButton.type = 'checkbox';
thumbButton.checked = showThumbs;
thumbButton.addEventListener("click", () => toggle_thumbnails());
const thumbDiv = document.createElement('div');
thumbDiv.innerHTML = 'Thumbnails<br/>';
thumbDiv.appendChild(thumbButton);
th.appendChild(thumbDiv);
tr.appendChild(th);
thead.appendChild(tr);
tbl.appendChild(thead);
tbl.appendChild(station_list_body);
station_table_div.appendChild(tbl);
populate_station_list(station_list_body, sort_metric, sort_order);
}
function populate_station_list(list_container, sort_metric, sort_order) {
list_container.innerHTML = '';
const indices = get_sort_indices(sites, sort_metric, sort_order);
const disp = showThumbs ? 'inline' : 'none';
indices.forEach((idx, i) => {
const site = sites[idx];
const title = get_title(site);
const tr = document.createElement('tr');
tr.className = i % 2 === 0 ? 'oddrow' : 'evenrow';
const td1 = document.createElement('td');
td1.innerHTML = `<a href="${site.station_url}">${title}</a><br/><small>${site.station_url}</small>`;
tr.appendChild(td1);
const td2 = document.createElement('td');
const date = new Date(site.last_seen * 1000);
td2.innerHTML = `<div style="float: left">${site.weewx_info}</div><div style="float: right">${site.station_type}</div><div style="clear:both; float:right"><small>${date.toUTCString()}</small></div>`;
tr.appendChild(td2);
const td3 = document.createElement('td');
const basename = `/shots/${md5(site.station_url)}`;
td3.innerHTML = `<div class="thumbnail" style="display:${disp}"><a href="${basename}.jpg"><img src="/images/blank.gif" alt="" data-echo="${basename}.tn.jpg" width="50"></a></div>`;
tr.appendChild(td3);
const td4 = document.createElement('td');
td4.id = `site_${idx}`;
td4.className = 'indicator';
attach_station(td4, map, site.marker, idx);
tr.appendChild(td4);
list_container.appendChild(tr);
});
echo.init();
}
function create_buttons(container, label, sort_metric) {
const button_group = document.createElement("div");
button_group.className = 'button_pair';
const up_button = document.createElement('input');
up_button.type = 'submit';
up_button.value = `${label} ↑`;
up_button.addEventListener("click", () => populate_station_list(container, sort_metric, "up"));
const dn_button = document.createElement('input');
dn_button.type = 'submit';
dn_button.value = `${label} ↓`;
dn_button.addEventListener("click", () => populate_station_list(container, sort_metric, "dn"));
button_group.appendChild(up_button);
button_group.appendChild(document.createElement('br'));
button_group.appendChild(dn_button);
return button_group;
}
function populate_hardware_table(counts) {
const s = document.getElementById('hardware_types_div');
const tbl = document.createElement('table');
const tbdy = document.createElement('tbody');
Object.keys(counts).sort((a, b) => {
if (a === 'total') return -1;
if (b === 'total') return 1;
return a.toLowerCase().localeCompare(b.toLowerCase());
}).forEach(key => {
const tr = document.createElement('tr');
const td1 = document.createElement('td');
td1.innerHTML = key;
tr.appendChild(td1);
const td2 = document.createElement('td');
td2.className = 'alignright';
td2.innerHTML = counts[key];
tr.appendChild(td2);
const td3 = document.createElement('td');
td3.id = `station_type_${key}`;
td3.className = 'indicator';
attach_station_type(td3, key, Object.keys(counts));
tr.appendChild(td3);
tbdy.appendChild(tr);
});
tbl.appendChild(tbdy);
s.appendChild(tbl);
}
function draw_ping_histogram(pings, maxpings, total, stale, dead) {
const canvas = document.getElementById('ping_details');
if (!canvas) return;
canvas.width = 180;
canvas.height = 60;
const c = canvas.getContext("2d");
const w = canvas.width;
const h = canvas.height;
const barwidth = w / pings.length;
const unitheight = h / maxpings;
c.strokeStyle = "#dddddd";
for (let i = h; i >= 0; i -= 20 * unitheight) {
c.beginPath();
c.moveTo(1, i);
c.lineTo(w, i);
c.stroke();
}
c.fillStyle = "#888888";
for (let i = 0; i < pings.length; i++) {
const bh = pings[pings.length - i - 1] * unitheight;
c.fillRect(i * barwidth, h - bh, barwidth, bh);
c.beginPath();
c.moveTo(i * barwidth, h - 4);
c.lineTo(i * barwidth, h);
c.stroke();
}
c.fillText(`total: ${total}`, 10, 20);
c.fillText(`stale: ${stale}`, 10, 32);
c.fillText(`dead: ${dead}`, 10, 44);
}
function create_content(idx) {
const site = sites[idx];
const fn = `${md5(site.station_url)}.sm.jpg`;
const w = document.createElement("div");
w.className = 'info-content';
w.innerHTML = `
<p class="location"><a href="${site.station_url}">${site.description || site.station_url}</a></p>
<p class="location_img"><img src="/shots/${fn}" width="100" alt="Screenshot"></p>
<p class="location_details">
${site.latitude.toFixed(3)}, ${site.longitude.toFixed(3)}<br/>
${site.station_type}<br/>
${site.station_model}<br/>
</p>`;
return w;
}
function attach_info(map, marker, idx) {
marker.addListener('click', () => {
infowindow.setContent(create_content(idx));
infowindow.open(map, marker);
hide_all_dots();
show_dot(idx);
});
}
function attach_station(elem, map, marker, idx) {
elem.addEventListener('click', () => {
infowindow.setContent(create_content(idx));
if (marker) infowindow.open(map, marker);
hide_all_dots();
show_dot(idx);
});
}
function attach_station_type(elem, station_type, count_keys) {
elem.addEventListener('click', () => {
count_keys.forEach(key => dehighlight(document.getElementById(`station_type_${key}`)));
highlight(document.getElementById(`station_type_${station_type}`));
infowindow.close();
dehighlight_all();
hide_all_markers();
hide_all_dots();
sites.forEach((site, i) => {
if (station_type === 'total' || site.station_type === station_type) {
show_marker(i);
}
if (site.station_type === station_type) {
highlight_row(i);
}
});
});
}
const highlight = elem => { if (elem) elem.style.backgroundColor = highlightColor; };
const dehighlight = elem => { if (elem) elem.style.backgroundColor = backgroundColor; };
const highlight_row = idx => highlight(document.getElementById(`site_${idx}`));
const dehighlight_row = idx => dehighlight(document.getElementById(`site_${idx}`));
const dehighlight_all = () => sites.forEach((_, i) => dehighlight_row(i));
const show_dot = idx => { const e = document.getElementById(`site_${idx}`); if (e) e.style.backgroundImage = 'url(dot.png)'; };
const hide_dot = idx => { const e = document.getElementById(`site_${idx}`); if (e) e.style.backgroundImage = ''; };
const hide_all_dots = () => sites.forEach((_, i) => hide_dot(i));
const show_marker = idx => sites[idx].marker.setMap(map);
const hide_marker = idx => sites[idx].marker.setMap(null);
const hide_all_markers = () => sites.forEach((_, i) => hide_marker(i));
function get_title(x) {
let title = x.description || x.station_url || 'untitled';
if (title.length > maxTitleLen) {
title = title.substring(0, maxTitleLen) + '...';
}
return title;
}
function toggle_thumbnails() {
showThumbs = !showThumbs;
const tn = document.getElementsByClassName('thumbnail');
Array.from(tn).forEach(el => {
el.style.display = showThumbs ? 'inline' : 'none';
if (showThumbs) el.height = 104;
});
}
function decode_html(s) {
const e = document.createElement('div');
e.innerHTML = s;
return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
}
function toggle(control, id) {
const elem = document.getElementById(id);
if (!elem) return;
const isHidden = elem.style.display === 'none';
elem.style.display = isHidden ? 'inline' : 'none';
const indicator = control.querySelector('.indicator-icon');
if (indicator) {
indicator.innerHTML = isHidden ? '▼' : '▶';
}
}
function get_sort_indices(sites, sort_metric, sort_order) {
const indices = Array.from(sites.keys());
const direction = sort_order === 'up' ? 1 : -1;
indices.sort((a, b) => {
const aVal = sites[a][sort_metric];
const bVal = sites[b][sort_metric];
if (typeof aVal === 'string' && typeof bVal === 'string') {
return direction * aVal.localeCompare(bVal);
}
return direction * (aVal < bVal ? -1 : aVal > bVal ? 1 : 0);
});
return indices;
}
initialize();
populate_header('stations');
}
load();
</script>
</head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-D146BWZK54"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-D146BWZK54');
</script>
<body>
<div id='container'>
<div id='masthead'>
<h1><a href='.'>WeeWX</a></h1>
<p>Open source software for your weather station</p>
</div>
<div id='navigation'>
</div>
<div id='map_container'>
<div id='map_canvas'></div>
</div>
<div id='content'>
<div id='hardware_summary'>
<div id='ping_details_container'>
<canvas id='ping_details'></canvas>
</div>
<div id="hardware_summary_toggle" style='cursor: pointer'>
<span class="indicator-icon">▶</span>
<strong>Hardware</strong>
</div>
<div id='hardware_types_div' style='display:none'></div>
</div>
<div id='instructions'>
<strong>How to Add Your Station</strong><br/>
Enable <span class='code'>register_this_station</span>
in weewx.conf, then restart weeWX.
</div>
<div id='sites'>
<div id="sites_toggle" style='cursor: pointer'>
<span class="indicator-icon">▶</span>
<strong>Stations</strong>
</div>
<div id='station_table_div' style='display:none'></div>
</div>
</div>
</div>
</body>
</html>