Skip to content

Commit 0fa6403

Browse files
authored
Merge pull request #110 from seehase/feature/day_chart_improvements
Fix bug with cumulative line
2 parents a84fe9f + 5f1193b commit 0fa6403

File tree

5 files changed

+12
-9
lines changed

5 files changed

+12
-9
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/ZonPHP/SEEHASE/
44
/ZonPHP/SEE/
55
/ZonPHP/SOLAR1/
6+
/ZonPHP/SOLARTEST/
67
/ZonPHP/TILLY/
78
/ZonPHP/TIL/
89
/ZonPHP/.settings/

ZonPHP/charts/day_chart.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@
8181
date("Y-m-d", strtotime($maxdag)) . "%' ORDER BY Datum_Dag, Naam ASC";
8282
$resultmd = mysqli_query($con, $sqlmdinv) or die("Query failed. dag-max-dag " . mysqli_error($con));
8383

84-
if (mysqli_num_rows($resultmd) != 0) {
84+
if (mysqli_num_rows($resultmd) > 0) {
8585
while ($row = mysqli_fetch_array($resultmd)) {
8686
$inverter_name = $row['Naam'];
8787
$time_only = substr($row['Datum_Dag'], -9);
8888
$today_max = $chartdatestring . $time_only; // current chart date string + max time
8989
$today_max_utc = convertLocalDateTime($today_max); // date in UTC
9090
$today_max_unix_utc = convertToUnixTimestamp($today_max_utc); // unix timestamp in UTC
91+
$today_max_unix_utc = $today_max_unix_utc - ($today_max_unix_utc % 60); // round to nearest minute (skip seconds)
9192
$allValuesMaxDay[$inverter_name][$today_max_unix_utc] = intval($row['gem']);
9293
// remember first and last date
9394
if ($max_first_val > $today_max_unix_utc) {
@@ -123,14 +124,14 @@
123124
$inverterValues = $allValuesPerInverter[$inverter_name];
124125

125126
// loop over all times from all inverters from min to max
126-
for ($time = $max_first_val; $time <= $max_last_val; $time += 300) {
127+
for ($time = $max_first_val; $time <= $max_last_val; $time += 300) {
127128
$currentInverterVal = "NaN";
128129
$timeInMillis = $time * 1000;
129130
if (isset($inverterValues[$time])) {
130131
$currentInverterVal = $inverterValues[$time];
131132
$cumSum += ($currentInverterVal / 12);
132-
$cumDataString .= "{x: $timeInMillis, y: $cumSum},";
133133
}
134+
$cumDataString .= "{x: $timeInMillis, y: $cumSum},";
134135
$dataSeriesString .= '{x:' . $timeInMillis . ', y: ' . $currentInverterVal . '},';
135136
if (!isset($totalsumCumArray[$timeInMillis])) {
136137
$totalsumCumArray[$timeInMillis] = 0;
@@ -310,7 +311,8 @@ function buildSubtitle(ctx) {
310311
let dataZonPHP = data.dataZonPHP;
311312
let txt = data.txt;
312313
let totalValue = 0;
313-
let lastDate = Date.now();
314+
let lastDate = new Date();
315+
lastDate = `${lastDate.getHours()}:${lastDate.getMinutes()}`;
314316
let lastValue = 0;
315317
let todayMax = 0;
316318
let maxDay = Date.now();
@@ -359,9 +361,8 @@ function customDayLegendClick(e, legendItem, legend) {
359361
cumSum = cloneAndResetY(dataset.dataCUM)
360362
}
361363
for (let ii in dataset.data) {
362-
363364
// cum
364-
if (dataset.dataCUM[ii].y != null) {
365+
if (dataset.dataCUM[ii] != null && dataset.dataCUM[ii].y != null) {
365366
cumSum[ii].y = cumSum[ii].y + dataset.dataCUM[ii].y;
366367
}
367368
}
@@ -387,6 +388,7 @@ function customDayLegendClick(e, legendItem, legend) {
387388
chart.options.plugins.subtitle = {
388389
text: buildSubtitle(legend),
389390
display: true,
391+
padding: {top: 5, left: 0, right: 0, bottom: 3},
390392
};
391393
chart.update();
392394
}

ZonPHP/inc/header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<meta name="keywords" content="ZonPHP,Sonne,Zon,sun PV, Photovoltaik, Datenlogger, SMA, Solar, Analyse">
99
<meta name="description" content="PV Anlagen Monitoring">
1010
<meta name="author" content="seehase">
11-
<meta name="apple-mobile-web-app-capable" content="yes">
11+
<meta name="mobile-web-app-capable" content="yes">
1212

1313
<?php
1414
if ($params['autoReload'] > 0) {

ZonPHP/inc/version_info.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/********************************************************************
33
* Version
44
*********************************************************************/
5-
$version = "v4.0.16";
5+
$version = "v4.0.17";
66

77
// Change SessionId if needed e.g. if you run multi instances
88
$zonPHPSessionID = "SOLAR_" . str_replace('.', '_', $version);

ZonPHP/validate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<meta name="keywords" content="ZonPHP,Sonne,Zon,sun PV, Photovoltaik, Datenlogger, SMA, Solar, Analyse">
1818
<meta name="description" content="PV Anlagen Monitoring">
1919
<meta name="author" content="seehase">
20-
<meta name="apple-mobile-web-app-capable" content="yes">
20+
<meta name="mobile-web-app-capable" content="yes">
2121

2222
<title>ZonPHP Parameter Validation</title>
2323
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet">

0 commit comments

Comments
 (0)