-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.php
209 lines (171 loc) · 4.58 KB
/
index.php
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
<!DOCTYPE html>
<html prefix="og: http://ogp.me/ns#" lang="en" itemscope itemtype="http://schema.org/WebPage">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
<!-- All Search Engines -->
<meta name="robots" content="noindex,nofollow" />
<!-- Google Specific -->
<meta name="googlebot" content="noindex,nofollow" />
<!-- tell Google not to translate this page -->
<meta name="google" content="notranslate" />
<!-- DNS prefetch -->
<link rel="dns-prefetch" href="//code.highcharts.com" />
<!-- external stylesheets -->
<link rel="stylesheet" href="https://necolas.github.io/normalize.css/8.0.0/normalize.css" />
<!-- internal stylesheets -->
<!-- hacky inline stylesheets -->
<style type="text/css">
#chart {
width: 100%;
height: 100vh;
}
</style>
<!-- general page information -->
<title>Solar</title>
<!-- JS external -->
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<!-- JS internal -->
<script>
function returnSum(arr) {
return Math.round(arr.reduce(function(pv, cv) {
return pv + cv;
}, 0));
}
<?php
require "db.php";
$conn = new mysqli($host, $user, $pw, $db);
if(!isset($_GET["lastDays"])) {
$queryData = "SELECT * FROM `data` ORDER BY `ts` ASC";
$range = "Gesamtdaten";
} else if(isset($_GET["lastDays"])) {
$threshold = time('now') - $_GET["lastDays"] * 86400;
$queryData = "SELECT * FROM `data` WHERE `ts` >= " .$threshold. " ORDER BY `ts` ASC";
$range = "Daten der letzten " .$_GET["lastDays"]. " Tage";
}
$getData = $conn->query($queryData);
$data = [
"ts" => [],
"production" => [],
"purchased" => [],
"feedin" => [],
"consumption" => [],
"selfconsumption" => [],
];
if($getData->num_rows > 0) {
while($dataset = $getData->fetch_assoc()) {
foreach($dataset as $name => $subArray) {
array_push($data[$name], $subArray);
}
}
}
foreach($data as $name => $subArray) {
if($name != "ts") {
echo '
const ' .$name. ' = ' .json_encode($subArray, JSON_NUMERIC_CHECK). '
';
} else if($name == "ts") {
echo '
var tempArray = ' .json_encode($subArray, JSON_NUMERIC_CHECK). '
const ts = [];
tempArray.forEach(function(timestamp) {
var date = new Date(timestamp * 1000);
ts.push(date);
});
';
}
}
?>
</script>
</head>
<body>
<div id="chart"></div>
<script>
(function() {
Highcharts.chart("chart", {
chart: {
type: "spline",
zoomType: "x"
},
title: {
useHTML: true,
text: "Solarübersicht"
},
subtitle: {
text: <?php echo '"' .$range. '"'; ?>
},
xAxis: {
categories: ts
},
yAxis: {
title: {
text: "Value"
},
labels: {
formatter: function () {
return this.value.toLocaleString("en-US");
}
}
},
legend: {
enabled: true
},
tooltip: {
crosshairs: true,
shared: true
},
plotOptions: {
spline: {
marker: {
radius: 4,
lineColor: "#666666",
lineWidth: 1
}
}
},
series: [{
name: "Production (SUM: " + returnSum(production).toLocaleString("en-US") + ")",
marker: {
symbol: "triangle"
},
color: "darkgreen",
data: production
}, {
name: "FeedIn (SUM: " + returnSum(feedin).toLocaleString("en-US") + ")",
marker: {
symbol: "square"
},
color: "yellowgreen",
data: feedin,
visible: false
}, {
name: "Purchased (SUM: " + returnSum(purchased).toLocaleString("en-US") + ")",
marker: {
symbol: "diamond"
},
color: "red",
data: purchased,
visible: false
}, {
name: "Consumption (SUM: " + returnSum(consumption).toLocaleString("en-US") + ")",
marker: {
symbol: "cross"
},
color: "orange",
data: consumption
}, {
name: "SelfConsumption (SUM: " + returnSum(selfconsumption).toLocaleString("en-US") + ")",
marker: {
symbol: "triangle-down"
},
color: "purple",
data: selfconsumption,
visible: false
}]
});
})();
</script>
</body>
</html>