-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
537 lines (477 loc) · 23.8 KB
/
Copy pathindex.html
File metadata and controls
537 lines (477 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta charset="UTF-8">
<title>GridWorks Visualizer</title>
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;700&display=swap" rel="stylesheet">
<!-- Libraries -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/luxon@3.0.1/build/global/luxon.min.js"></script>
<script>
let house_alias, password;
async function exportCSV(start_ms, end_ms) {
const csvButton= document.getElementById('csv_button');
const csvLoadingText = document.getElementById('csvLoadingText');
csvButton.style.display = 'none';
csvLoadingText.style.display = 'inline';
const startdate = document.getElementById('startDatePicker').value;
const starttime = document.getElementById('startTimePicker').value;
const starttime_luxon = luxon.DateTime.fromFormat(`${startdate} ${starttime}`, 'yyyy-MM-dd HH:mm', { zone: 'America/New_York' });
const startUnixMilliseconds = starttime_luxon.toUTC().toMillis();
const enddate = document.getElementById('endDatePicker').value;
const endtime = document.getElementById('endTimePicker').value;
const endtime_luxon = luxon.DateTime.fromFormat(`${enddate} ${endtime}`, 'yyyy-MM-dd HH:mm', { zone: 'America/New_York' });
const endUnixMilliseconds = endtime_luxon.toUTC().toMillis();
const selectedChannels = Array.from(document.querySelectorAll('input[name="channels"]:checked'))
.map(checkbox => checkbox.value);
const timestep_wip = document.getElementsByName('csv_inputs')[0];
const timestep = timestep_wip.value;
try {
const response = await fetch(`https://visualizer.electricity.works/csv`, {
// const response = await fetch(`http://localhost:8000/csv`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
house_alias: `${house_alias}`,
password: password,
start_ms: startUnixMilliseconds,
end_ms: endUnixMilliseconds,
selected_channels: selectedChannels,
timestep: timestep,
})
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const contentType = response.headers.get("Content-Type");
if (contentType && contentType.includes("application/json")) {
const data = await response.json();
if ('success' in data && data.success === false) {
alert(data.message);
if (data.reload) {
location.reload();
}
}
} else {
const startDate = new Date(startUnixMilliseconds);
const formattedStartDate = startDate.toISOString().slice(0, 16).replace('T', '-');
const endDate = new Date(endUnixMilliseconds);
const formattedEndDate = endDate.toISOString().slice(0, 16).replace('T', '-');
const blob = await response.blob();
const url = window.URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `${house_alias}_${timestep}s_${formattedStartDate}-${formattedEndDate}.csv`;
document.body.appendChild(a);
a.click();
a.remove();
window.URL.revokeObjectURL(url);
}
} catch (error) {
console.error('Error downloading CSV:', error);
alert(`Error downloading CSV`);
} finally {
csvButton.style.display = 'inline';
csvLoadingText.style.display = 'none';
}
}
async function fetchPlots(house_alias, password, start_ms, end_ms, channels) {
const ipResponse = await fetch('https://api.ipify.org?format=json');
const ipData = await ipResponse.json();
const ipAddress = ipData.ip;
const userAgent = navigator.userAgent;
const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
try {
const response = await fetch(`https://visualizer.electricity.works/plots`, {
// const response = await fetch(`http://localhost:8000/plots`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
house_alias: `${house_alias}`,
password: password,
start_ms: start_ms,
end_ms: end_ms,
selected_channels: channels,
ip_address: ipAddress,
user_agent: userAgent,
timezone: timezone
})
});
const contentType = response.headers.get("Content-Type");
if (contentType && contentType.includes("application/json")) {
const data = await response.json();
if ('success' in data && data.success === false) {
alert(data.message);
if (data.reload) {
location.reload();
}
}
} else {
const blob = await response.blob();
const zip = await JSZip.loadAsync(blob);
const plotsDiv1 = document.getElementById('Plot1');
const plotsDiv2 = document.getElementById('Plot2');
const plotsDiv3 = document.getElementById('Plot3');
const plotsDiv4 = document.getElementById('Plot4');
const plotsDiv5 = document.getElementById('Plot5');
const plotsDiv6 = document.getElementById('Plot6');
const plotsDivPng = document.getElementById('PlotPng');
plotsDiv1.innerHTML = '';
plotsDiv2.innerHTML = '';
plotsDiv3.innerHTML = '';
plotsDiv4.innerHTML = '';
plotsDiv5.innerHTML = '';
plotsDiv6.innerHTML = '';
plotsDivPng.innerHTML = '';
let iframeCount = 0;
for (const filename of Object.keys(zip.files)) {
const fileData = await zip.files[filename].async('blob');
if (filename.endsWith('.html')) {
const blob = new Blob([await zip.files[filename].async('text')], { type: 'text/html' });
const htmlUrl = URL.createObjectURL(blob);
const iframe = document.createElement('iframe');
iframe.src = htmlUrl;
iframe.style.width = '90%';
iframe.style.maxWidth = '1500px';
iframe.style.height = '375px';
iframe.style.border = 'none';
if (iframeCount === 0) {
plotsDiv1.appendChild(iframe);
} else if (iframeCount === 1) {
plotsDiv2.appendChild(iframe);
} else if (iframeCount === 2) {
iframe.style.height = '300px';
plotsDiv3.appendChild(iframe);
} else if (iframeCount === 3) {
plotsDiv4.appendChild(iframe);
} else if (iframeCount === 4) {
plotsDiv5.appendChild(iframe);
} else if (iframeCount === 5) {
plotsDiv6.appendChild(iframe);
}
iframeCount++;
} else if (filename.endsWith('.png')) {
const imgUrl = URL.createObjectURL(fileData);
const img = document.createElement('img');
img.src = imgUrl;
img.alt = 'Plot Image';
plotsDivPng.appendChild(img);
}
}
}
} catch (error) {
console.error('Error fetching plots:', error);
alert(`Error fetching plots for house '${house_alias}'.`);
} finally {
resetButton();
}
}
function getDefaultDate(is_start) {
const nyDate = new Date(new Date().toLocaleString("en-US", { timeZone: "America/New_York" }));
if (is_start) {
nyDate.setDate(nyDate.getDate() - 1);
nyDate.setHours(20, 0, 0, 0);
}
const year = nyDate.getFullYear();
const month = String(nyDate.getMonth() + 1).padStart(2, '0');
const day = String(nyDate.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
}
function getDefaultTime(is_start) {
const nyDate = new Date(new Date().toLocaleString("en-US", { timeZone: "America/New_York" }));
if (is_start) {
nyDate.setDate(nyDate.getDate() - 1);
nyDate.setHours(20, 0, 0, 0);
}
const hours = String(nyDate.getHours()).padStart(2, '0');
const minutes = String(nyDate.getMinutes()).padStart(2, '0');
return `${hours}:${minutes}`;
}
function setNow() {
const nyDate = new Date(new Date().toLocaleString("en-US", { timeZone: "America/New_York" }));
nyDate.setHours(nyDate.getHours() + 1);
document.getElementById('endDatePicker').value = nyDate.toISOString().split('T')[0];
document.getElementById('endTimePicker').value = nyDate.toTimeString().split(' ')[0].substring(0, 5);
getData(event)
}
function handleKey(event) {
if (event.key === "Enter") {
const target = document.activeElement;
if (target.tagName !== "BUTTON") {
event.preventDefault();
document.querySelector('input[type="submit"]').click();
}
}
}
function resetButton() {
const submitButton = document.querySelector('input[type="submit"]');
const nowButton = document.getElementById('nowButton');
const csvButton= document.getElementById('csv_button');
const loadingText = document.getElementById('loadingText');
submitButton.style.display = 'inline';
nowButton.style.display = 'inline';
csvButton.style.display = 'inline';
loadingText.style.display = 'none';
}
function HousePassword() {
house_alias = prompt("Enter house alias:");
password = prompt("Enter password:");
document.getElementById("houseAliasHeader").textContent = `${house_alias.charAt(0).toUpperCase()}${house_alias.slice(1)}`;
document.getElementById('startDatePicker').value = getDefaultDate(true);
document.getElementById('startTimePicker').value = getDefaultTime(true);
document.getElementById('endDatePicker').value = getDefaultDate();
document.getElementById('endTimePicker').value = getDefaultTime();
document.getElementById("content").style.display = "block";
getData(event)
}
function getData(event) {
event.preventDefault();
const submitButton = document.querySelector('input[type="submit"]');
const nowButton = document.getElementById('nowButton');
const csvButton = document.getElementById('csv_button');
const loadingText = document.getElementById('loadingText');
const checkboxDiv = document.getElementById("checkboxDiv");
submitButton.style.display = 'none';
nowButton.style.display = 'none';
csvButton.style.display = 'none';
loadingText.style.display = 'inline';
checkboxDiv.style.display = "none";
const selectedChannels = Array.from(document.querySelectorAll('input[name="channels"]:checked'))
.map(checkbox => checkbox.value);
const startdate = document.getElementById('startDatePicker').value;
const starttime = document.getElementById('startTimePicker').value;
const starttime_luxon = luxon.DateTime.fromFormat(`${startdate} ${starttime}`, 'yyyy-MM-dd HH:mm', { zone: 'America/New_York' });
const startUnixMilliseconds = starttime_luxon.toUTC().toMillis();
const enddate = document.getElementById('endDatePicker').value;
const endtime = document.getElementById('endTimePicker').value;
const endtime_luxon = luxon.DateTime.fromFormat(`${enddate} ${endtime}`, 'yyyy-MM-dd HH:mm', { zone: 'America/New_York' });
const endUnixMilliseconds = endtime_luxon.toUTC().toMillis();
fetchPlots(house_alias, password, startUnixMilliseconds, endUnixMilliseconds, selectedChannels)
}
function toggleCheckbox() {
const checkboxDiv = document.getElementById("checkboxDiv");
if (checkboxDiv.style.display === "none") {
checkboxDiv.style.display = "block";
document.getElementById("content").style.display = "none";
} else {
checkboxDiv.style.display = "none";
document.getElementById("content").style.display = "block";
}
}
</script>
<style>
body {
background-color: #ffffff;
font-family: 'Helvetica Neue', Arial, sans-serif;
margin: 0;
padding: 0;
font-family: 'Montserrat';
}
#PlotPng, #Plot1, #Plot2, #Plot3, #Plot4, #Plot5, #Plot6 {
display: flex;
justify-content: center;
padding-bottom:15px;
}
#PlotPng img {
width: 100%;
max-width: 1100px;
height: auto;
margin-bottom: 10px;
}
#header{
height: 58px;
background-color: rgb(55, 55, 55);
display: flex;
align-items: stretch;
margin-bottom: 0;
}
#houseAliasHeader {
font-family: 'Montserrat';
font-size: 35px;
padding-bottom: 25px;
margin: 0px;
}
#checkboxButton {
margin-right: 12px;
}
#submit_button, #checkboxButton, #close-button, #csv_button {
cursor: pointer;
font-size:15px;
font-family: 'Montserrat';
margin-top:0px;
color:white;
border-radius:30px;
text-align:center;
height:40px;
padding-left: 20px;
padding-right: 20px;
background-color:rgb(63, 63, 63);
border: none;
/* transition: background-color 0.5s; */
}
#submit_button:hover, #checkboxButton:hover, #close-button:hover, #csv_button:hover {
background-color:rgb(55, 55, 55);
}
#Inputs{
min-height: 110px;
margin-left: 5%;
margin-right: 5%;
margin-bottom: 30px;
margin-top:30px;
padding: 30px;
background-color: #eeeeee;
border-radius: 10px;
}
.menuItem{
transition: background-color 0.5s;
}
.menuItem:hover{
background-color: rgb(46, 46, 46);
}
a{
text-decoration: none;
}
#checkboxDiv{
box-sizing: border-box;
left: 50%;
height:90%;
/* max-height: 600px; */
overflow:scroll ;
transform: translate(-50%, -0%);
background-color: #eeeeee;
color: rgb(53, 53, 53);
position: absolute;
width: 100%;
max-width: 800px;
margin-top: 20px;
border-radius: 10px;
padding-left: 40px;
padding-right: 30px;
padding-bottom: 25px;
padding-top: 15px;
z-index: 1;
}
#PlotContainer {
padding-top: 10px;
background-color: #ffffff;
width: 100%;
margin-bottom: 20px;
}
#footer {
background-color: #eeeeee;
color: #6c6c6c;
font-size: 14px;
width: 100%;
margin: 0px;
padding: 10px;
text-align: center;
bottom: 0;
left: 0;
}
</style>
</head>
<body onload="HousePassword()">
<div id='container_of_checkbox'>
<div id="checkboxDiv" style="display: none;">
<button id="close-button" style="float: right; margin-top: 15px;" onclick="toggleCheckbox()">X</button>
<h2>Select channels</h2>
<h4>Heat pump</h4>
<label><input type="checkbox" name="channels" value="hp-lwt" checked>LWT</label><br>
<label><input type="checkbox" name="channels" value="hp-ewt" checked>EWT</label><br>
<label><input type="checkbox" name="channels" value="hp-odu-pwr" checked>Outdoor unit power</label><br>
<label><input type="checkbox" name="channels" value="hp-idu-pwr" checked>Indoor unit power</label><br>
<label><input type="checkbox" name="channels" value="primary-flow" checked>Primary pump flow rate</label><br>
<label><input type="checkbox" name="channels" value="primary-pump-pwr">Primary pump power</label><br>
<h4>Distribution</h4>
<label><input type="checkbox" name="channels" value="dist-swt" checked>SWT</label><br>
<label><input type="checkbox" name="channels" value="dist-rwt" checked>RWT</label><br>
<label><input type="checkbox" name="channels" value="dist-flow" checked>Distribution pump flow rate</label><br>
<label><input type="checkbox" name="channels" value="dist-pump-pwr">Distribution pump power</label><br>
<h4>Zones</h4>
<label><input type="checkbox" name="channels" value="zone_heat_calls" checked>Heat calls</label><br>
<label><input type="checkbox" name="channels" value="oat">Outside air temperature</label><br>
<h4>Buffer</h4>
<label><input type="checkbox" name="channels" value="buffer-hot-pipe" checked>Hot pipe</label><br>
<label><input type="checkbox" name="channels" value="buffer-cold-pipe" checked>Cold pipe</label><br>
<label><input type="checkbox" name="channels" value="buffer-depths" checked>Buffer depths</label><br>
<h4>Storage</h4>
<label><input type="checkbox" name="channels" value="store-hot-pipe" checked>Hot pipe</label><br>
<label><input type="checkbox" name="channels" value="store-cold-pipe" checked>Cold pipe</label><br>
<label><input type="checkbox" name="channels" value="storage-depths" checked>Storage depths</label><br>
<label><input type="checkbox" name="channels" value="store-flow" checked>Storage pump flow rate</label><br>
<label><input type="checkbox" name="channels" value="store-pump-pwr">Storage pump power</label><br>
<h2>Plots</h2>
<label><input type="checkbox" name="channels" value="show-points">Show points</label><br>
<h2>Export to CSV</h2>
<label><input type="checkbox" name="channels" value="all-data" checked>Export all data channels</label><br>
Time step: <label><input type="number" style="width: 50px;" name="csv_inputs" value="5"></label> seconds<br>
<br>
<button id="csv_button" onclick='exportCSV()'>Export to CSV</button>
<span id="csvLoadingText" style="color: rgb(55, 55, 55); display: none; position: absolute">Preparing for download, please wait...</span>
<br>
</div>
</div>
<div id="content" style="display: none;">
<div id="header">
<div style="height: 100%; margin: 0; padding: 0; width: 175px;">
<span style="color: white; font-family: 'Montserrat'; font-weight:400; display: flex; align-items: center; margin-top: 10px; margin-left: 30px;">
GRIDWORKS<br>CONSULTING
</span>
</div>
<a href="">
<div class='menuItem' style="height: 100%; margin: 0; padding: 0; width: 135px; display: flex; align-items: center; justify-content: center;">
<div style="display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100%;">
<span style="color: white; font-size: 14px; font-weight: bold;">
Visualizer
</span>
<!-- <div style="position:absolute; height: 2px; background-color: white; margin-top: 30px; width: 20px; border-radius: 5px;"></div> -->
</div>
</div>
</a>
<a href="https://gridworks-consulting.com/">
<div class='menuItem' style="height: 100%; margin: 0; padding: 0; width: 135px; display: flex; align-items: center; justify-content: center;">
<div style="text-align: center;">
<span style="color: white; font-size: 14px;">
About
</span>
</div>
</div>
</a>
</div>
<div id="Inputs">
<h2 id="houseAliasHeader" style="color: rgb(55, 55, 55);"></h2>
<form onsubmit="getData(event)" onkeydown="handleKey(event)">
<label style="color: rgb(55, 55, 55);" for="startDatePicker">Start:<br></label>
<input type="date" id="startDatePicker" name="startDatePicker">
<input type="time" id="startTimePicker" name="startTimePicker"><br><br>
<label style="color: rgb(55, 55, 55);" for="endDatePicker">End:<br></label>
<input type="date" id="endDatePicker" name="endDatePicker">
<input type="time" id="endTimePicker" name="endTimePicker">
<button type="button" id="nowButton" onclick=setNow()>Latest</button><br>
<br><br>
<button type="button" id="checkboxButton" onclick=toggleCheckbox()>Options</button>
<input id='submit_button' type="submit" style='position: absolute' value="Plot">
<span id="loadingText" style="font-weight: bold; color: rgb(55, 55, 55); display: none; position: absolute; margin-top:11px;">Loading data...</span>
</form>
</div>
<div id="PlotContainer">
<div id="Plot1"></div>
<div id="Plot2"></div>
<div id="Plot3"></div>
<div id="Plot4"></div>
<div id="Plot5"></div>
<div id="Plot6"></div>
<div id="PlotPng"></div>
</div>
</div>
<!-- <div id="footer">
Copyright © GridWorks Energy Consulting 2024. All rights reserved.
</div> -->
</body>
</html>