-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata-visualization.php
545 lines (472 loc) · 23 KB
/
data-visualization.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
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
<?php require_once ('header.php');
require_once ('backend/db.php'); ?>
<?php
// Enable error reporting
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Check if the user is logged in, if not then redirect to login page
if (!isset($_SESSION['user_id'])) {
// Redirect to the login page:
header("Location: login.php");
exit;
}
// Fetch user data from the database
$user_id = $_SESSION['user_id'];
// Get the site ID from the URL if it exists
$site_id = isset($_GET['site_id']) ? intval($_GET['site_id']) : null;
$sql = "SELECT id, username FROM users WHERE id = ?";
$stmt = $db->prepare($sql);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$user = $result->fetch_assoc();
} else {
echo "No user data found.";
exit();
}
$stmt->close();
//Fetch site(s) data (for the current user only) from the database
$sql = "SELECT * FROM sites WHERE user_id = ?";
$stmt = $db->prepare($sql);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
$sites = [];
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$row['site_data'] = json_decode($row['site_data'], true);
$sites[] = $row;
}
} else {
echo "No sites data found.";
exit();
}
$stmt->close();
//Fetch consumption data only from all sites (to compare anonymously)
$sql = "SELECT * FROM sites WHERE user_id != ?";
$stmt = $db->prepare($sql);
$stmt->bind_param("i", $user_id);
$stmt->execute();
$result = $stmt->get_result();
$allsites = [];
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$row['site_data'] = json_decode($row['site_data'], true);
//anon
$row['site_name'] = "";
$row['user_id'] = "";
$allsites[] = $row;
}
} else {
echo "No sites data found.";
exit();
}
$stmt->close();
$allsitesJSON = json_encode($allsites);
$sitesJSON = json_encode($sites);
$userJSON = json_encode($user);
?>
<script>
//Make data available to JS/HTML
var userData = <?php echo $userJSON; ?>; // the user's data
var sitesData = <?php echo $sitesJSON; ?>; // that user's sites
var allSitesData = <?php echo $allsitesJSON; ?>; // other sites as well (anonymized)
</script>
<!--TODO: JS only interface with all visualization options, all sites data is already here -->
<script src="3rdparty/plotly.min.js"></script>
<script src="3rdparty/plotly-locale-de.js"></script>
<script>Plotly.setPlotConfig({locale: 'de'})</script>
<link rel="stylesheet" href="daterangepicker.css" />
<script src="3rdparty/jquery.min.js"></script>
<script src="3rdparty/moment.min.js"></script>
<script src="3rdparty/daterangepicker.min.js"></script>
<script src="data-visualization.js"></script>
<div id="body-datavis" class="body-datavis">
<!-- TODO: Add dropdown to select from multiple sites (if any)
AND add which one to show as site parameter -->
<label for="siteSelect">Betrieb wählen:</label>
<select id="siteSelect">
<!-- Options are added with js right below -->
</select>
<script>
const dropdown = document.getElementById("siteSelect");
dropdown.innerHTML = '';
const options = [];
sitesData.forEach(site => {
const opt = document.createElement('option');
opt.value = site.id;
opt.textContent = site.site_name;
dropdown.appendChild(opt);
})
options.forEach(option => {
const opt = document.createElement('option');
opt.value = option.value;
opt.textContent = option.text;
dropdown.appendChild(opt);
});
//TODO: Add handlers to change plots/data when a option is chosen
dropdown.addEventListener('change', function() {
const selectedValue = dropdown.value;
console.log('Selected value:', selectedValue);
// TODO: Add the code you want to execute when a different option is chosen
// For example, you could call a function to update plots or data:
//updateDataBasedOnSelection(selectedValue);
});
</script>
</script>
<input type="text" id="daterange" placeholder="Zeitraum wählen (leer = alles)" value="Zeitraum wählen (leer = alles)" style="width:198px;"/>
<script>
// Initialize date range picker
$(function() {
$('#daterange').daterangepicker({
locale: {
format: 'DD.MM.YYYY',
applyLabel: 'Anwenden',
cancelLabel: 'Abbrechen',
fromLabel: 'Von',
toLabel: 'Bis',
customRangeLabel: 'Benutzerdefiniert',
weekLabel: 'W',
daysOfWeek: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
monthNames: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
}
});
});
</script>
<hr style="margin-top:20px; border: none; border-top: 1px solid #000; width: 63%;">
<div id="top-datavis">
<button onclick="showContent('content1')" style="height:56px;">Auswertung in Zahlen</button>
<button onclick="showContent('content2')" style="height:56px;">Grafische Auswertung</button>
<button onclick="showContent('content3')" style="height:56px;">Vergleich Verbräuche</button>
<button onclick="showContent('content4')" style="height:56px;">Sonderauswertung</button>
</div>
<div id="bottom-datavis" style="width: 100%;">
<div id="content1" class="content-datavis">
<h2>Auswertung in Zahlen</h2>
<p>Betriebsdaten im Branchenvergleich zum Minimal-, Maximal-, und Durchschnittswert bezogen auf 1kg Wäsche.</p>
<table border="1" style="table-layout: fixed; margin: 0 auto; margin-top: 8%;">
<tr>
<th style="width: 5%; padding: 6px;"></th>
<th style="width: 5%; padding: 6px;">Mein Betrieb</th>
<th style="width: 5%; padding: 6px;">Minimaler Wert</th>
<th style="width: 5%; padding: 6px;">Maximaler Wert</th>
<th style="width: 5%; padding: 6px;">Durchschnitt</th>
</tr>
<!--TODO: fill these in from data with js -->
<tr>
<td>Wasser [l]</td>
<td style="background-color: yellow; color: black;">6,750</td>
<td>1,000</td>
<td>29,674</td>
<td>11,082</td>
</tr>
<tr>
<td>Strom [kWh]</td>
<td>0,635</td>
<td>0,000</td>
<td>1,620</td>
<td>0,237</td>
</tr>
<tr>
<td>therm. Energie [kWh]</td>
<td style="background-color: green;">0,130</td>
<td>0,001</td>
<td>3,854</td>
<td>1,476</td>
</tr>
<tr>
<td>Waschmittel [g]</td>
<td>10,000</td>
<td>0,020</td>
<td>33,657</td>
<td>15,636</td>
</tr>
</table>
<!-- TODO: Ersparnis durch Nanofiltration aus Daten generieren -->
<div style="margin-top:3%; display:flex; align-items:center;">
<p style="margin-left:50%; font-size: 12px;">Mögliche Einsparung von Wasser durch den Einsatz von Nanofiltration: bis zu <span id="nanofilt_sav">2.625</span> L. <br> <a href="https://www.rewamem.de/">Mehr Informationen.</a> </p>
</div>
<span class="info-button">
<div class="tooltip"> Mögliche Einsparung von Wasser durch den Einsatz von Nanofiltration: bis zu <span id="nanofilt_sav">4.625</span> L. <br> <a href="https://www.rewamem.de/">Mehr Informationen.</a> </div>
</span>
<div style="margin-top: 14%; width: 90%; display: flex; align-items: center; justify-content: space-between; gap: 20px;">
<p style="margin: 0; margin-left: 6%;">* Gegenüberstellung der einzelnen Betriebsdaten im Vergleich zum Schnitt der Branche bezogen auf 1kg Wäsche.</p>
<hr style="flex-grow: 1; margin: 0 10px; border: none;">
<div style="display: flex; flex-direction: column; gap: 10px;">
<div style="display: flex; align-items: center; gap: 10px;">
<span style="width: 20px; height: 20px; background-color: red;"></span>
<span>Dringender Handlungsbedarf</span>
</div>
<div style="display: flex; align-items: center; gap: 10px;">
<span style="width: 20px; height: 20px; background-color: yellow;"></span>
<span>Verbesserung möglich</span>
</div>
<div style="display: flex; align-items: center; gap: 10px;">
<span style="width: 20px; height: 20px; background-color: green;"></span>
<span>Stand der Technik</span>
</div>
</div>
</div>
</div>
<div id="content2" class="content-datavis" style="width: 100%;">
<h2>Grafische Auswertung</h2>
<p>Grafische Datenauswertung nach Verbräuchen von Wasser, Strom [kWh], thermischer Energie [kWh], und Waschmittel.</p>
<div class="button-container">
<button class="action-btn" data-action="wasser">Wasser</button>
<button class="action-btn" data-action="strom">Strom [kWh]</button>
<button class="action-btn" data-action="energie">therm. Energie [kWh]</button>
<button class="action-btn" data-action="waschmittel">Waschmittel</button>
</div>
<div id="plot2" style="width: 100%;"></div>
<script>
// Define the data points for different types
var trace1 = {
x: [1, 2, 3, 4, 5],
y: [10, 15, 13, 17, 10],
mode: 'markers',
type: 'scatter',
name: 'Type 1',
marker: { size: 12, symbol: 'circle', color: 'red' }
};
var trace2 = {
x: [2, 3, 4, 5, 6],
y: [16, 5, 11, 9, 15],
mode: 'markers',
type: 'scatter',
name: 'Type 2',
marker: { size: 12, symbol: 'square', color: 'orange' }
};
var trace3 = {
x: [1, 2, 3, 4, 5],
y: [12, 9, 15, 12, 14],
mode: 'markers',
type: 'scatter',
name: 'Type 3',
marker: { size: 12, symbol: 'diamond', color: 'green' }
};
var trace4 = {
x: [4],
y: [12],
mode: 'markers',
type: 'scatter',
name: 'Eigener Betrieb',
marker: { size: 12, symbol: 'triangle-up', color: 'orange' }
};
var trace5 = {
x: [3, 4, 5, 6, 7],
y: [6, 13, 11, 16.3, 10.2],
mode: 'markers',
type: 'scatter',
name: 'Type 5',
marker: { size: 12, symbol: 'circle', color: 'blue' }
};
var trace6 = {
x: [1,2,4,6],
y: [8.8, 5, 5, 4.5],
mode: 'markers',
type: 'scatter',
name: 'Type 6',
marker: { size: 12, symbol: 'triangle-up', color: 'blue' }
};
var trace7 = {
x: [2,3,5,6],
y: [4.8, 15, 12.6, 8.5],
mode: 'markers',
type: 'scatter',
name: 'Type 7',
marker: { size: 12, symbol: 'diamond', color: 'yellow' }
};
var data2 = [trace1, trace2, trace3, trace4, trace5, trace6, trace7];
var plotContainer = document.getElementById('bottom-datavis');
var containerWidth = plotContainer.clientWidth;
var containerHeight = plotContainer.clientHeight * 0.75;
var layout2 = {
title: '',
font: { size: 16, color: document.documentElement.getAttribute('data-theme') === 'dark' ? 'white' : 'black' },
paper_bgcolor: document.documentElement.getAttribute('data-theme') === 'dark' ? '#2c2c2c' : 'white',
plot_bgcolor: document.documentElement.getAttribute('data-theme') === 'dark' ? '#2c2c2c' : 'white',
width: containerWidth,
height: containerHeight
};
var config2 = {responsive: true, displaylogo: false, locale: 'de'};
Plotly.newPlot('plot2', data2, layout2, config2);
</script>
<div style="margin-top: 4%; width: 95%; display: flex; align-items: center; justify-content: space-between; gap: 20px;">
<p style="margin: 0; margin-left: 6%;">Darstellung der Betriebsdaten für das ausgewählte Unternehmen in <span style="color:orange;">Orange</span>. <br>* Gegenüberstellung der einzelnen Betriebsdaten im Vergleich zum Schnitt der Branche bezogen auf 1kg Wäsche.</p>
<hr style="flex-grow: 1; margin: 0 5px; border: none;">
<div style="display: flex; flex-direction: column; gap: 10px;">
<div style="display: flex; align-items: center; gap: 10px;">
<span style="width: 20px; height: 20px; background-color: red;"></span>
<span>Dringender Handlungsbedarf</span>
</div>
<div style="display: flex; align-items: center; gap: 10px;">
<span style="width: 20px; height: 20px; background-color: yellow;"></span>
<span>Verbesserung möglich</span>
</div>
<div style="display: flex; align-items: center; gap: 10px;">
<span style="width: 20px; height: 20px; background-color: green;"></span>
<span>Stand der Technik</span>
</div>
<span class="info-button">
<div class="tooltip"> Mögliche Einsparung von Wasser durch den Einsatz von Nanofiltration: bis zu <span id="nanofilt_sav">2.625</span> L. <br> <a href="https://www.rewamem.de/">Mehr Informationen.</a> </div>
</span>
</div>
<hr style="flex-grow: 1; margin: 0 10px; border: none;">
<div class="checkbox-list">
<table>
<tr>
<td><input type="checkbox" value="Eigener Betrieb" checked></td>
<td><span class="marker triangle"></span></td>
<td>Eigener Betrieb</td>
<tr>
<td><input type="checkbox" value="berufskleidung" checked></td>
<td><span class="marker circle"></span></td>
<td>Berufskleidung</td>
</tr>
<tr>
<td><input type="checkbox" value="hotelwaesche" checked></td>
<td><span class="marker square"></span></td>
<td>Hotelwäsche</td>
</tr>
<tr>
<td><input type="checkbox" value="krankenhaus" checked></td>
<td><span class="marker diamond"></span></td>
<td>Krankenhaus / Altenheim flach</td>
</tr>
<tr>
<td><input type="checkbox" value="kombination_krankenhaus" checked></td>
<td><span class="marker blue-triangle"></span></td>
<td>Kombination Krankenhaus / Altenheim / Bewohnerwäsche / Reinigungsteile</td>
</tr>
<tr>
<td><input type="checkbox" value="kombination_handtuch" checked></td>
<td><span class="marker yellow-diamond"></span></td>
<td>Kombination aus Handtuchrollen / Fußmatten / Feuchtwischbezügen</td>
</tr>
<tr>
<td><input type="checkbox" value="sonstige" checked></td>
<td><span class="marker red-circle"></span></td>
<td>sonstige</td>
</tr>
</table>
</div>
</div>
</div>
<div id="content3" class="content-datavis">
<h2>Vergleich Verbräuche</h2>
<p>Die Verbräuche des eigenen Betriebs von Wasser, Strom [kWh], thermischer Energie [kWh], und Waschmittel im Vergleich mit angezeigter Waschmenge und Verarbeitungsschwerpunkt.</p>
<div class="button-container">
<button class="action-btn" data-action="wasser">Wasser</butto>
<button class="action-btn" data-action="strom">Strom [kWh]</button>
<button class="action-btn" data-action="energie">therm. Energie [kWh]</button>
<button class="action-btn" data-action="waschmittel">Waschmittel</button>
</div>
</div>
<div id="content4" class="content-datavis" style="width: 100%;">
<h2>Sonderauswertung</h2>
<p>Grafische Datenauswertung nach Verbräuchen von Wasser, Strom [kWh], thermischer Energie [kWh], und Waschmittel. Der Branchenvergleich kann hier gesondert nach Art der Wäsche gefiltert durchgeführt werden.</p>
<div class="button-container">
<button class="action-btn" data-action="wasser">Wasser</button>
<button class="action-btn" data-action="strom">Strom [kWh]</button>
<button class="action-btn" data-action="energie">therm. Energie [kWh]</button>
<button class="action-btn" data-action="waschmittel">Waschmittel</button>
</div>
<div id="plot4" style="width: 100%;"></div>
<script>
var xValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var yValues = [5, 10, 2, 8, 7, 3, 9, 12, 4, 6];
var trace = {
type: 'bar',
x: xValues,
y: yValues,
marker: {
color: '#C8A2C8',
line: {
width: 2.5
}
}
};
//calculate statistics
var average = yValues.reduce((a, b) => a + b, 0) / yValues.length;
var plus15Percent = average * 1.15;
var minus15Percent = average * 0.85;
var averageLine = {
type: 'line',
x0: 0,
x1: xValues.length + 1,
y0: average,
y1: average,
line: {
color: 'black',
width: 2,
dash: 'dash'
}
};
var plus15Line = {
type: 'line',
x0: 0,
x1: xValues.length + 1,
y0: plus15Percent,
y1: plus15Percent,
line: {
color: 'red',
width: 2,
dash: 'dash'
}
};
var minus15Line = {
type: 'line',
x0: 0,
x1: xValues.length + 1,
y0: minus15Percent,
y1: minus15Percent,
line: {
color: 'green',
width: 2,
dash: 'dash'
}
};
//end calculate statistics
var data4 = [ trace ];
var plotContainer = document.getElementById('bottom-datavis');
var containerWidth = plotContainer.clientWidth;
var containerHeight = plotContainer.clientHeight * 0.75;
var layout4 = {
title: 'Title 4',
font: { size: 16, color: document.documentElement.getAttribute('data-theme') === 'dark' ? 'white' : 'black' },
paper_bgcolor: document.documentElement.getAttribute('data-theme') === 'dark' ? '#2c2c2c' : 'white',
plot_bgcolor: document.documentElement.getAttribute('data-theme') === 'dark' ? '#2c2c2c' : 'white',
width: containerWidth,
height: containerHeight,
shapes: [averageLine, plus15Line, minus15Line]
};
var config4 = {responsive: true, displaylogo: false, locale: 'de'};
Plotly.newPlot('plot4', data4, layout4, config4);
</script>
<script>
// Add an event listener to update the plot size on window resize
window.addEventListener('resize', function() {
var plotContainer = document.getElementById('bottom-datavis');
var newWidth = plotContainer.clientWidth;
var newHeight = plotContainer.clientHeight * 0.75;
Plotly.relayout('plot2', { width: newWidth, height: newHeight });
Plotly.relayout('plot4', { width: newWidth, height: newHeight });
});
// Add event listeners for action-buttons
document.querySelectorAll('.action-btn').forEach(button => {
button.addEventListener('click', function() {
const action = button.getAttribute('data-action');
console.log(`${action} button clicked`);
// TODO: change plots !
});
});
</script>
<div style="margin-top: 7%; width: 90%; display: flex; align-items: center; justify-content: space-between; gap: 20px;">
<p style="margin: 0; margin-left: 6%;">Darstellung der Betriebsdaten für das ausgewählte Unternehmen in <span style="color:orange;">Orange</span>. <br>* Gegenüberstellung der einzelnen Betriebsdaten im Vergleich zum Schnitt der Branche bezogen auf 1kg Wäsche.</p>
</div>
</div>
</div>
</div>
<?php require_once('footer.php');?>