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));
|
||||||
@@ -77,6 +79,23 @@
|
|||||||
|
|
||||||
// Nur die 4 gewünschten Werte anzeigen (fixe Reihenfolge)
|
// Nur die 4 gewünschten Werte anzeigen (fixe Reihenfolge)
|
||||||
renderValues(data.values || {});
|
renderValues(data.values || {});
|
||||||
|
|
||||||
|
if (data.debug) {
|
||||||
|
const p = data.debug.prod || {};
|
||||||
|
const f = data.debug.feed || {};
|
||||||
|
const g = data.debug.grid || {};
|
||||||
|
elDebug.textContent =
|
||||||
|
`Prod(var=${p.varId}, arch=${p.archiveId}, count=${p.count}) | ` +
|
||||||
|
`Feed(var=${f.varId}, arch=${f.archiveId}, count=${f.count}) | ` +
|
||||||
|
`Grid(var=${g.varId}, arch=${g.archiveId}, count=${g.count})`;
|
||||||
|
} else {
|
||||||
|
elDebug.textContent = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function renderValues(values) {
|
function renderValues(values) {
|
||||||
|
|||||||
@@ -104,13 +104,17 @@ private function RecalculateAndPush(): void
|
|||||||
[$tStart, $tEnd] = $this->getRange($range, $date);
|
[$tStart, $tEnd] = $this->getRange($range, $date);
|
||||||
|
|
||||||
// Debug-Container initialisieren (sonst "Undefined variable")
|
// Debug-Container initialisieren (sonst "Undefined variable")
|
||||||
$dbgProd = null;
|
$dbgProd = [];
|
||||||
$dbgFeed = null;
|
$dbgFeed = [];
|
||||||
$dbgGrid = null;
|
$dbgGrid = [];
|
||||||
|
|
||||||
$prod = $this->readDelta($this->ReadPropertyInteger('VarProduction'), $tStart, $tEnd, $dbgProd);
|
$prodVar = $this->ReadPropertyInteger('VarProduction');
|
||||||
$feed = $this->readDelta($this->ReadPropertyInteger('VarFeedIn'), $tStart, $tEnd, $dbgFeed);
|
$feedVar = $this->ReadPropertyInteger('VarFeedIn');
|
||||||
$grid = $this->readDelta($this->ReadPropertyInteger('VarGrid'), $tStart, $tEnd, $dbgGrid);
|
$gridVar = $this->ReadPropertyInteger('VarGrid');
|
||||||
|
|
||||||
|
$prod = $this->readDelta($prodVar, $tStart, $tEnd, $dbgProd);
|
||||||
|
$feed = $this->readDelta($feedVar, $tStart, $tEnd, $dbgFeed);
|
||||||
|
$grid = $this->readDelta($gridVar, $tStart, $tEnd, $dbgGrid);
|
||||||
|
|
||||||
$house = $prod - $feed + $grid;
|
$house = $prod - $feed + $grid;
|
||||||
if ($house < 0) $house = 0.0;
|
if ($house < 0) $house = 0.0;
|
||||||
@@ -183,11 +187,14 @@ private function RecalculateAndPush(): void
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function readDelta(int $varId, int $tStart, int $tEnd, ?array &$dbg = null): float
|
private function readDelta(int $varId, int $tStart, int $tEnd, array &$dbg): float
|
||||||
{
|
{
|
||||||
$dbg = [
|
$dbg = [
|
||||||
'varId' => $varId,
|
'varId' => $varId,
|
||||||
|
'archiveId' => 0,
|
||||||
'count' => 0,
|
'count' => 0,
|
||||||
|
'first' => null,
|
||||||
|
'last' => null,
|
||||||
'vStart' => null,
|
'vStart' => null,
|
||||||
'vEnd' => null
|
'vEnd' => null
|
||||||
];
|
];
|
||||||
@@ -197,6 +204,8 @@ private function RecalculateAndPush(): void
|
|||||||
}
|
}
|
||||||
|
|
||||||
$archiveID = IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0] ?? 0;
|
$archiveID = IPS_GetInstanceListByModuleID('{43192F0B-135B-4CE7-A0A7-1475603F3060}')[0] ?? 0;
|
||||||
|
$dbg['archiveId'] = $archiveID;
|
||||||
|
|
||||||
if ($archiveID <= 0) {
|
if ($archiveID <= 0) {
|
||||||
return 0.0;
|
return 0.0;
|
||||||
}
|
}
|
||||||
@@ -209,15 +218,15 @@ private function RecalculateAndPush(): void
|
|||||||
usort($values, static 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);
|
$dbg['count'] = count($values);
|
||||||
|
|
||||||
// Fallback: erster/letzter Eintrag im Fenster
|
$dbg['first'] = (float)$values[0]['Value'];
|
||||||
$first = (float)$values[0]['Value'];
|
$dbg['last'] = (float)$values[count($values)-1]['Value'];
|
||||||
$last = (float)$values[count($values)-1]['Value'];
|
|
||||||
|
|
||||||
$vStart = null;
|
$vStart = null;
|
||||||
$vEnd = null;
|
$vEnd = null;
|
||||||
|
|
||||||
foreach ($values as $v) {
|
foreach ($values as $v) {
|
||||||
$ts = (int)$v['TimeStamp'];
|
$ts = (int)$v['TimeStamp'];
|
||||||
|
|
||||||
if ($ts <= $tStart) {
|
if ($ts <= $tStart) {
|
||||||
$vStart = (float)$v['Value'];
|
$vStart = (float)$v['Value'];
|
||||||
}
|
}
|
||||||
@@ -229,9 +238,9 @@ private function RecalculateAndPush(): void
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wenn kein Wert vor Start/Ende gefunden wurde -> nimm ersten/letzten Logwert
|
// Wenn kein Wert vor Start/Ende gefunden wurde, nimm ersten/letzten im Fenster
|
||||||
if ($vStart === null) $vStart = $first;
|
if ($vStart === null) $vStart = $dbg['first'];
|
||||||
if ($vEnd === null) $vEnd = $last;
|
if ($vEnd === null) $vEnd = $dbg['last'];
|
||||||
|
|
||||||
$dbg['vStart'] = $vStart;
|
$dbg['vStart'] = $vStart;
|
||||||
$dbg['vEnd'] = $vEnd;
|
$dbg['vEnd'] = $vEnd;
|
||||||
@@ -240,6 +249,7 @@ private function RecalculateAndPush(): void
|
|||||||
return ($diff < 0) ? 0.0 : (float)$diff;
|
return ($diff < 0) ? 0.0 : (float)$diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Buttons for quick navigation.
|
* Buttons for quick navigation.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user