-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
151 lines (143 loc) · 6.11 KB
/
index.html
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
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<style>
body { padding-top: 80px; padding-right: 80px; padding-left: 80px;}
</style>
<audio id="sound-daily-kw">
<source src="sounds/Blastwave_FX_CashRegister_S08IN_92.mp3" type="audio/mpeg">
</audio>
<audio id="sound-lifetime-1mW">
<source src="sounds/Blastwave_FX_ExplosionCrash_S08WA.132.mp3" type="audio/mpeg">
</audio>
<audio id="sound-lifetime-100kW">
<source src="sounds/zapsplat_emergency_alarm_siren.mp3" type="audio/mpeg">
</audio>
<audio id="sound-lifetime-10kW">
<source src="sounds/zapsplat_sound_design_ascending_metalic_tone_powerful_electric.mp3" type="audio/mpeg">
</audio>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
"use strict";
var chartDef = { initialised: false };
google.charts.load('current', {'packages':['gauge']});
google.charts.setOnLoadCallback(setupCharts);
function setupCharts() {
chartDef.formatterVolts = new google.visualization.NumberFormat({ suffix: 'V', fractionDigits: 1 });
chartDef.formatterPower = new google.visualization.NumberFormat({ suffix: 'kW', fractionDigits: 3});
chartDef.optionsVolts = {
width: 400, height: 400,
greenColor: 'LightBlue', greenFrom: 0, greenTo: 225,
redColor: 'LightGreen', redFrom: 250, redTo: 400,
yellowFrom:225, yellowTo: 250,
min: 0, max: 400,
minorTicks: 5
};
chartDef.optionPower = {
width: 400, height: 400,
min: 0, max: 3.2
};
chartDef.dataVoltsIn = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Input Volts', 0],
]);
chartDef.dataVoltsOut = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Output Volts', 0],
]);
chartDef.dataPowerOut = google.visualization.arrayToDataTable([
['Label', 'Value'],
['Output Power', 0]
]);
chartDef.chartVoltsIn = new google.visualization.Gauge(document.getElementById('chart_volts_in'));
chartDef.chartVoltsOut = new google.visualization.Gauge(document.getElementById('chart_volts_out'));
chartDef.chartPowerOut = new google.visualization.Gauge(document.getElementById('chart_power_out'));
drawCharts(chartDef);
updateDisplay(chartDef);
}
function drawCharts(chartDef) {
chartDef.formatterVolts.format(chartDef.dataVoltsIn, 1);
chartDef.chartVoltsIn.draw(chartDef.dataVoltsIn, chartDef.optionsVolts);
chartDef.formatterVolts.format(chartDef.dataVoltsOut, 1);
chartDef.chartVoltsOut.draw(chartDef.dataVoltsOut, chartDef.optionsVolts);
chartDef.formatterPower.format(chartDef.dataPowerOut, 1);
chartDef.chartPowerOut.draw(chartDef.dataPowerOut, chartDef.optionPower);
}
function updateDisplay(chartDef) {
// Change localhost and port to wherever the server that is running
$.get("http://localhost:8081/data", function(data, status) {
chartDef.dataVoltsIn.setValue(0, 1, data.inputVoltage);
chartDef.dataVoltsOut.setValue(0, 1, data.outputVoltage);
chartDef.dataPowerOut.setValue(0, 1, data.outputPower);
drawCharts(chartDef);
$("#today-kwh").text(data.energyToday + "kWh");
$("#today-time").text(data.hoursToday + "h " + data.minutesToday + "m");
$('#yesterday-kwh').text(data.energyYesterday + "kWh");
$('#yesterday-time').text(data.hoursYesterday + "h " + data.minutesYesterday + "m");
$('#lifetime-kwh').text(data.energyLifetime + "kWh");
$('#lifetime-time').text(data.hoursLifetime + "h " + data.minutesLifetime + "m");
$('#average-kwh').text(data.averageDailyProduction + "kWh");
$('#average-days').text(data.daysProducing + " days");
if (chartDef.initialised) {
if (Math.floor(data.energyToday) > Math.floor(chartDef.energyToday)) {
$('#sound-daily-kw')[0].play();
}
let energy = Math.floor(data.energyLifetime);
if (energy % 10 == 0 && energy > Math.floor(chartDef.energyLifetime)) {
if (energy % 1000 == 0) {
$('#sound-lifetime-1mW')[0].play();
} else if (energy % 100 == 0) {
$('#sound-lifetime-100kW')[0].play();
} else if (energy % 10 == 0) {
$('#sound-lifetime-10kW')[0].play();
}
}
chartDef.energyToday = data.energyToday;
chartDef.energyLifetime = data.energyLifetime;
} else {
chartDef.energyToday = data.energyToday;
chartDef.energyLifetime = data.energyLifetime;
chartDef.initialised = true;
}
setTimeout(updateDisplay, 5000, chartDef);
});
}
</script>
</head>
<body>
<table>
<tr>
<td id="chart_volts_in" style="width: 400px; height: 400px;">
</td>
<td id="chart_volts_out" style="width: 400px; height: 400px;">
</td>
<td id="chart_power_out" style="width: 400px; height: 400px;">
</td>
</tr>
</table>
<table class="table">
<tr>
<td>Today</td>
<td align="right" id="today-kwh">0kWh</td>
<td align="right" id="today-time">0h 0m</td>
</tr>
<tr>
<td>Yesterday</td>
<td align="right" id="yesterday-kwh">0kWh</td>
<td align="right" id="yesterday-time">0h 0m</td>
</tr>
<tr>
<td>Lifetime</td>
<td align="right" id="lifetime-kwh">0kWh</td>
<td align="right" id="lifetime-time">0h 0m</td>
</tr>
<tr>
<td>Average daily production</td>
<td align="right" id="average-kwh">0kWh</td>
<td align="right" id="average-days">0 days</td>
</tr>
</table>
</body>
</html>