no message
This commit is contained in:
@@ -25,6 +25,7 @@
|
|||||||
<div style="margin-top:10px;display:flex;flex-direction:column;gap:8px;max-width:520px;">
|
<div style="margin-top:10px;display:flex;flex-direction:column;gap:8px;max-width:520px;">
|
||||||
<div style="font-weight:600;">Werte</div>
|
<div style="font-weight:600;">Werte</div>
|
||||||
<div id="values" style="display:flex;flex-direction:column;gap:6px;"></div>
|
<div id="values" style="display:flex;flex-direction:column;gap:6px;"></div>
|
||||||
|
<div id="debug" style="margin-top:8px;font-size:12px;opacity:0.65;"></div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -36,6 +37,7 @@
|
|||||||
const elNext = document.getElementById('next');
|
const elNext = document.getElementById('next');
|
||||||
const elValues = document.getElementById('values');
|
const elValues = document.getElementById('values');
|
||||||
const elPeriod = document.getElementById('period');
|
const elPeriod = document.getElementById('period');
|
||||||
|
const elDebug = document.getElementById('debug');
|
||||||
|
|
||||||
// Range ändern -> sofort rechnen
|
// Range ändern -> sofort rechnen
|
||||||
elRange.addEventListener('change', () => requestAction('SetRange', elRange.value));
|
elRange.addEventListener('change', () => requestAction('SetRange', elRange.value));
|
||||||
@@ -81,6 +83,15 @@
|
|||||||
} else {
|
} else {
|
||||||
renderValues({});
|
renderValues({});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data.debug) {
|
||||||
|
const p = data.debug.prod, f = data.debug.feed, g = data.debug.grid;
|
||||||
|
elDebug.textContent =
|
||||||
|
`Logs: Prod(count=${p?.count ?? 0}) Feed(count=${f?.count ?? 0}) Grid(count=${g?.count ?? 0})`;
|
||||||
|
} else {
|
||||||
|
elDebug.textContent = '';
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nur diese vier Werte anzeigen (fixe Reihenfolge)
|
// Nur diese vier Werte anzeigen (fixe Reihenfolge)
|
||||||
|
|||||||
@@ -121,6 +121,11 @@ private function RecalculateAndPush(): void
|
|||||||
'Einspeisung' => (float)$feed,
|
'Einspeisung' => (float)$feed,
|
||||||
'Netz' => (float)$grid,
|
'Netz' => (float)$grid,
|
||||||
'Hausverbrauch'=> (float)$house
|
'Hausverbrauch'=> (float)$house
|
||||||
|
],
|
||||||
|
'debug' => [
|
||||||
|
'prod' => $dbgProd,
|
||||||
|
'feed' => $dbgFeed,
|
||||||
|
'grid' => $dbgGrid
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -174,17 +179,21 @@ private function RecalculateAndPush(): void
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function readDelta($varId, $tStart, $tEnd)
|
private function readDelta(int $varId, int $tStart, int $tEnd, ?array &$dbg = null): float
|
||||||
{
|
{
|
||||||
if (!is_int($tStart)) {
|
$dbg = [
|
||||||
$tStart = strtotime($tStart);
|
'varId' => $varId,
|
||||||
}
|
'count' => 0,
|
||||||
if (!is_int($tEnd)) {
|
'vStart' => null,
|
||||||
$tEnd = strtotime($tEnd);
|
'vEnd' => null
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($varId <= 0 || !IPS_VariableExists($varId)) {
|
||||||
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
$archiveID = @IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0];
|
$archiveID = IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0] ?? 0;
|
||||||
if (!$archiveID || !IPS_VariableExists($varId)) {
|
if ($archiveID <= 0) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,32 +202,40 @@ private function RecalculateAndPush(): void
|
|||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
usort($values, fn($a, $b) => (int)$a['TimeStamp'] <=> (int)$b['TimeStamp']);
|
usort($values, static fn($a, $b) => (int)$a['TimeStamp'] <=> (int)$b['TimeStamp']);
|
||||||
|
$dbg['count'] = count($values);
|
||||||
|
|
||||||
|
// Fallback: erster/letzter Eintrag im Fenster
|
||||||
|
$first = (float)$values[0]['Value'];
|
||||||
|
$last = (float)$values[count($values)-1]['Value'];
|
||||||
|
|
||||||
$vStart = null;
|
$vStart = null;
|
||||||
$vEnd = null;
|
$vEnd = null;
|
||||||
|
|
||||||
foreach ($values as $v) {
|
foreach ($values as $v) {
|
||||||
if ($v['TimeStamp'] <= $tStart) {
|
$ts = (int)$v['TimeStamp'];
|
||||||
$vStart = $v['Value'];
|
if ($ts <= $tStart) {
|
||||||
|
$vStart = (float)$v['Value'];
|
||||||
}
|
}
|
||||||
if ($v['TimeStamp'] <= $tEnd) {
|
if ($ts <= $tEnd) {
|
||||||
$vEnd = $v['Value'];
|
$vEnd = (float)$v['Value'];
|
||||||
}
|
}
|
||||||
if ($v['TimeStamp'] > $tEnd) {
|
if ($ts > $tEnd) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($vStart === null) {
|
// Wenn kein Wert vor Start/Ende gefunden wurde -> nimm ersten/letzten Logwert
|
||||||
$vStart = (float)GetValue($varId);
|
if ($vStart === null) $vStart = $first;
|
||||||
}
|
if ($vEnd === null) $vEnd = $last;
|
||||||
if ($vEnd === null) {
|
|
||||||
$vEnd = (float)GetValue($varId);
|
$dbg['vStart'] = $vStart;
|
||||||
}
|
$dbg['vEnd'] = $vEnd;
|
||||||
|
|
||||||
$diff = $vEnd - $vStart;
|
$diff = $vEnd - $vStart;
|
||||||
return ($diff < 0) ? 0.0 : $diff;
|
return ($diff < 0) ? 0.0 : (float)$diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Buttons for quick navigation.
|
* Buttons for quick navigation.
|
||||||
*/
|
*/
|
||||||
@@ -271,11 +288,7 @@ private function RecalculateAndPush(): void
|
|||||||
return checkdate($m, $d, $y);
|
return checkdate($m, $d, $y);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Optional helper for the "actions" test button in form.json
|
|
||||||
public function TestPush(): void
|
|
||||||
{
|
|
||||||
$this->RecalculateAndPush();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
Reference in New Issue
Block a user