no message

This commit is contained in:
2025-12-12 08:14:12 +01:00
parent b4de095a20
commit 558fd9aa4e

View File

@@ -281,90 +281,90 @@ class Abrechnung extends IPSModule
$pSolar = $this->getTariffPriceAt($tariffs, ['Solartarif'], $ts);
$pFeed = $this->getTariffPriceAt($tariffs, ['Einspeisetarif'], $ts);
foreach ($metersByUser as $userId => $meters) {
// ==========================================================
// 1) GLOBAL DELTAS EINMAL BERECHNEN
// ==========================================================
$globalImpTotal = 0.0;
$globalExpTotal = 0.0;
$globalSlot = [];
$impTotal = 0.0;
$expTotal = 0.0;
$slot = [];
// Deltas je Zähler des Users
foreach ($meters as $name => $mm) {
foreach ($powerMeters as $m) {
$name = $m['name'];
$impDelta = 0.0;
$expDelta = 0.0;
// IMPORT
if (!empty($mm['importVar'])) {
$varId = (int)$mm['importVar'];
if (IPS_VariableExists($varId)) {
$impDelta = $this->getDeltaFromArchive($varId, $ts, $slotEnd);
}
if (!empty($m['var_consumption']) && IPS_VariableExists((int)$m['var_consumption'])) {
$impDelta = $this->getDeltaFromArchive((int)$m['var_consumption'], $ts, $slotEnd);
}
// EXPORT
if (!empty($mm['exportVar'])) {
$varId = (int)$mm['exportVar'];
if (IPS_VariableExists($varId)) {
$expDelta = $this->getDeltaFromArchive($varId, $ts, $slotEnd);
}
if (!empty($m['var_feed']) && IPS_VariableExists((int)$m['var_feed'])) {
$expDelta = $this->getDeltaFromArchive((int)$m['var_feed'], $ts, $slotEnd);
}
// Nur hinzufügen, wenn Werte vorhanden sind
if ($impDelta > 0.0 || $expDelta > 0.0) {
$slot[$name] = [
$globalSlot[$name] = [
'imp' => $impDelta,
'exp' => $expDelta
'exp' => $expDelta,
'user_id' => (int)$m['user_id']
];
$impTotal += $impDelta;
$expTotal += $expDelta;
$globalImpTotal += $impDelta;
$globalExpTotal += $expDelta;
}
}
}
// Logging der Eingangswerte
// Fall 1: Weder Import noch Export -> nichts zu berechnen
if ($impTotal == 0.0 && $expTotal == 0.0) {
// Wenn keine Imp/Exp vorhanden → nächster Slot
if ($globalImpTotal == 0.0 && $globalExpTotal == 0.0) {
continue;
}
// Verhältnis PV / Netz pro User
if ($impTotal == 0.0 && $expTotal > 0.0) {
// Kein Import, aber Export → PV deckt alles
// ==========================================================
// 2) Verhältnis PV / Netz
// ==========================================================
if ($globalImpTotal == 0.0 && $globalExpTotal > 0.0) {
// nur Export → PV deckt alles
$ratio = 0.0;
$pvCoversAll = true;
} elseif ($expTotal == 0.0 && $impTotal > 0.0) {
// Kein Export, aber Import → Netz deckt alles
} elseif ($globalExpTotal == 0.0 && $globalImpTotal > 0.0) {
// nur Import → Netz deckt alles
$ratio = 0.0;
$pvCoversAll = false;
} elseif ($impTotal <= $expTotal) {
// PV produziert genug oder mehr
$ratio = $expTotal > 0 ? ($impTotal / $expTotal) : 0.0;
} elseif ($globalImpTotal <= $globalExpTotal) {
// PV produziert genug
$ratio = $globalExpTotal ? ($globalImpTotal / $globalExpTotal) : 0.0;
$pvCoversAll = true;
} else {
// Import ist größer als Export → Netz deckt den Rest
$ratio = $impTotal > 0 ? ($expTotal / $impTotal) : 0.0;
// Netzbezug notwendig
$ratio = $globalImpTotal ? ($globalExpTotal / $globalImpTotal) : 0.0;
$pvCoversAll = false;
}
// ==========================================================
// 3) PRO USER VERTEILEN
// ==========================================================
foreach ($globalSlot as $name => $v) {
$userId = $v['user_id'];
// Falls User nicht im Cache ist → ignorieren
if (!isset($this->powerCostCache[$userId][$name])) {
continue;
}
// Werte pro Zähler verteilen
foreach ($slot as $name => $v) {
$imp = $v['imp'];
$exp = $v['exp'];
// Totale speichern
$this->powerCostCache[$userId][$name]['imp'] += $imp;
$this->powerCostCache[$userId][$name]['exp'] += $exp;
// PV deckt alles
if ($pvCoversAll) {
// PV deckt gesamten Verbrauch
$this->powerCostCache[$userId][$name]['solar_bezug'] += $imp;
$this->powerCostCache[$userId][$name]['solareinspeisung'] += (1 - $ratio) * $exp;
$this->powerCostCache[$userId][$name]['solarverkauf'] += $ratio * $exp;
@@ -374,11 +374,11 @@ foreach ($meters as $name => $mm) {
}
if ($pFeed !== null) {
$this->powerCostCache[$userId][$name]['rev_feedin'] += ((1 - $ratio) * $exp * $pFeed) / 100.0;
$this->powerCostCache[$userId][$name]['rev_zev'] += (($ratio) * $exp * $pSolar) / 100.0;
$this->powerCostCache[$userId][$name]['rev_zev'] += ($ratio * $exp * $pSolar) / 100.0;
}
// Netz deckt einen Teil
} else {
// Teil Netzbezug
$this->powerCostCache[$userId][$name]['solar_bezug'] += $ratio * $imp;
$this->powerCostCache[$userId][$name]['netz_bezug'] += (1 - $ratio) * $imp;
$this->powerCostCache[$userId][$name]['solarverkauf'] += $exp;
@@ -391,13 +391,12 @@ foreach ($meters as $name => $mm) {
}
if ($pFeed !== null) {
$this->powerCostCache[$userId][$name]['rev_zev'] += ($exp * $pSolar) / 100.0;
}
}
}
}
}
}
}
}
}
}
private function GetCalculatedPowerCosts($userId)
{