no message
This commit is contained in:
@@ -272,7 +272,7 @@ class Abrechnung extends IPSModule
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 15-Minuten-Schritte
|
// 15-Minuten-Schritte
|
||||||
for ($ts = $from; $ts < $to; $ts += 900) {
|
for ($ts = $from; $ts < $to; $ts += 900) {
|
||||||
$slotEnd = min($to, $ts + 900);
|
$slotEnd = min($to, $ts + 900);
|
||||||
|
|
||||||
@@ -281,122 +281,121 @@ class Abrechnung extends IPSModule
|
|||||||
$pSolar = $this->getTariffPriceAt($tariffs, ['Solartarif'], $ts);
|
$pSolar = $this->getTariffPriceAt($tariffs, ['Solartarif'], $ts);
|
||||||
$pFeed = $this->getTariffPriceAt($tariffs, ['Einspeisetarif'], $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;
|
foreach ($powerMeters as $m) {
|
||||||
$expTotal = 0.0;
|
|
||||||
$slot = [];
|
|
||||||
|
|
||||||
// Deltas je Zähler des Users
|
$name = $m['name'];
|
||||||
foreach ($meters as $name => $mm) {
|
$impDelta = 0.0;
|
||||||
|
$expDelta = 0.0;
|
||||||
|
|
||||||
$impDelta = 0.0;
|
// IMPORT
|
||||||
$expDelta = 0.0;
|
if (!empty($m['var_consumption']) && IPS_VariableExists((int)$m['var_consumption'])) {
|
||||||
|
$impDelta = $this->getDeltaFromArchive((int)$m['var_consumption'], $ts, $slotEnd);
|
||||||
|
}
|
||||||
|
|
||||||
// IMPORT
|
// EXPORT
|
||||||
if (!empty($mm['importVar'])) {
|
if (!empty($m['var_feed']) && IPS_VariableExists((int)$m['var_feed'])) {
|
||||||
$varId = (int)$mm['importVar'];
|
$expDelta = $this->getDeltaFromArchive((int)$m['var_feed'], $ts, $slotEnd);
|
||||||
if (IPS_VariableExists($varId)) {
|
}
|
||||||
$impDelta = $this->getDeltaFromArchive($varId, $ts, $slotEnd);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// EXPORT
|
if ($impDelta > 0.0 || $expDelta > 0.0) {
|
||||||
if (!empty($mm['exportVar'])) {
|
$globalSlot[$name] = [
|
||||||
$varId = (int)$mm['exportVar'];
|
'imp' => $impDelta,
|
||||||
if (IPS_VariableExists($varId)) {
|
'exp' => $expDelta,
|
||||||
$expDelta = $this->getDeltaFromArchive($varId, $ts, $slotEnd);
|
'user_id' => (int)$m['user_id']
|
||||||
}
|
];
|
||||||
}
|
|
||||||
|
|
||||||
// Nur hinzufügen, wenn Werte vorhanden sind
|
$globalImpTotal += $impDelta;
|
||||||
if ($impDelta > 0.0 || $expDelta > 0.0) {
|
$globalExpTotal += $expDelta;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$slot[$name] = [
|
// Wenn keine Imp/Exp vorhanden → nächster Slot
|
||||||
'imp' => $impDelta,
|
if ($globalImpTotal == 0.0 && $globalExpTotal == 0.0) {
|
||||||
'exp' => $expDelta
|
continue;
|
||||||
];
|
}
|
||||||
|
|
||||||
$impTotal += $impDelta;
|
// ==========================================================
|
||||||
$expTotal += $expDelta;
|
// 2) Verhältnis PV / Netz
|
||||||
|
// ==========================================================
|
||||||
|
if ($globalImpTotal == 0.0 && $globalExpTotal > 0.0) {
|
||||||
|
// nur Export → PV deckt alles
|
||||||
|
$ratio = 0.0;
|
||||||
|
$pvCoversAll = true;
|
||||||
|
|
||||||
}
|
} elseif ($globalExpTotal == 0.0 && $globalImpTotal > 0.0) {
|
||||||
|
// nur Import → Netz deckt alles
|
||||||
|
$ratio = 0.0;
|
||||||
|
$pvCoversAll = false;
|
||||||
|
|
||||||
}
|
} elseif ($globalImpTotal <= $globalExpTotal) {
|
||||||
|
// PV produziert genug
|
||||||
|
$ratio = $globalExpTotal ? ($globalImpTotal / $globalExpTotal) : 0.0;
|
||||||
|
$pvCoversAll = true;
|
||||||
|
|
||||||
// Logging der Eingangswerte
|
} else {
|
||||||
|
// Netzbezug notwendig
|
||||||
|
$ratio = $globalImpTotal ? ($globalExpTotal / $globalImpTotal) : 0.0;
|
||||||
|
$pvCoversAll = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Fall 1: Weder Import noch Export -> nichts zu berechnen
|
// ==========================================================
|
||||||
if ($impTotal == 0.0 && $expTotal == 0.0) {
|
// 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;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verhältnis PV / Netz pro User
|
$imp = $v['imp'];
|
||||||
if ($impTotal == 0.0 && $expTotal > 0.0) {
|
$exp = $v['exp'];
|
||||||
// Kein Import, aber Export → PV deckt alles
|
|
||||||
$ratio = 0.0;
|
|
||||||
$pvCoversAll = true;
|
|
||||||
|
|
||||||
} elseif ($expTotal == 0.0 && $impTotal > 0.0) {
|
// Totale speichern
|
||||||
// Kein Export, aber Import → Netz deckt alles
|
$this->powerCostCache[$userId][$name]['imp'] += $imp;
|
||||||
$ratio = 0.0;
|
$this->powerCostCache[$userId][$name]['exp'] += $exp;
|
||||||
$pvCoversAll = false;
|
|
||||||
|
|
||||||
} elseif ($impTotal <= $expTotal) {
|
// PV deckt alles
|
||||||
// PV produziert genug oder mehr
|
if ($pvCoversAll) {
|
||||||
$ratio = $expTotal > 0 ? ($impTotal / $expTotal) : 0.0;
|
$this->powerCostCache[$userId][$name]['solar_bezug'] += $imp;
|
||||||
$pvCoversAll = true;
|
$this->powerCostCache[$userId][$name]['solareinspeisung'] += (1 - $ratio) * $exp;
|
||||||
|
$this->powerCostCache[$userId][$name]['solarverkauf'] += $ratio * $exp;
|
||||||
|
|
||||||
|
if ($pSolar !== null) {
|
||||||
|
$this->powerCostCache[$userId][$name]['cost_solar'] += ($imp * $pSolar) / 100.0;
|
||||||
|
}
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Netz deckt einen Teil
|
||||||
} else {
|
} else {
|
||||||
// Import ist größer als Export → Netz deckt den Rest
|
$this->powerCostCache[$userId][$name]['solar_bezug'] += $ratio * $imp;
|
||||||
$ratio = $impTotal > 0 ? ($expTotal / $impTotal) : 0.0;
|
$this->powerCostCache[$userId][$name]['netz_bezug'] += (1 - $ratio) * $imp;
|
||||||
$pvCoversAll = false;
|
$this->powerCostCache[$userId][$name]['solarverkauf'] += $exp;
|
||||||
}
|
|
||||||
|
|
||||||
|
if ($pGrid !== null) {
|
||||||
|
$this->powerCostCache[$userId][$name]['cost_grid'] += ((1 - $ratio) * $imp * $pGrid) / 100.0;
|
||||||
// Werte pro Zähler verteilen
|
}
|
||||||
foreach ($slot as $name => $v) {
|
if ($pSolar !== null) {
|
||||||
$imp = $v['imp'];
|
$this->powerCostCache[$userId][$name]['cost_solar'] += ($ratio * $imp * $pSolar) / 100.0;
|
||||||
$exp = $v['exp'];
|
}
|
||||||
|
if ($pFeed !== null) {
|
||||||
$this->powerCostCache[$userId][$name]['imp'] += $imp;
|
$this->powerCostCache[$userId][$name]['rev_zev'] += ($exp * $pSolar) / 100.0;
|
||||||
$this->powerCostCache[$userId][$name]['exp'] += $exp;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
if ($pSolar !== null) {
|
|
||||||
$this->powerCostCache[$userId][$name]['cost_solar'] += ($imp * $pSolar) / 100.0;
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
|
|
||||||
}
|
|
||||||
} 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;
|
|
||||||
|
|
||||||
if ($pGrid !== null) {
|
|
||||||
$this->powerCostCache[$userId][$name]['cost_grid'] += ((1 - $ratio) * $imp * $pGrid) / 100.0;
|
|
||||||
}
|
|
||||||
if ($pSolar !== null) {
|
|
||||||
$this->powerCostCache[$userId][$name]['cost_solar'] += ($ratio * $imp * $pSolar) / 100.0;
|
|
||||||
}
|
|
||||||
if ($pFeed !== null) {
|
|
||||||
$this->powerCostCache[$userId][$name]['rev_zev'] += ($exp * $pSolar) / 100.0;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function GetCalculatedPowerCosts($userId)
|
private function GetCalculatedPowerCosts($userId)
|
||||||
|
|||||||
Reference in New Issue
Block a user