removed: value || 0

This commit is contained in:
Patrick Haßel 2024-10-17 16:10:38 +02:00
parent 6f9fb935e3
commit b784f236df
2 changed files with 42 additions and 10 deletions

View File

@ -1,6 +1,6 @@
import {IValue} from "./IValue";
type GetValue = (v: number) => number;
type GetValue = (v: number) => number | null;
type CombineValue = (a: number, b: number) => number;

View File

@ -66,21 +66,18 @@ export class DashboardComponent implements OnInit {
getElectricitySeries(): DisplayOrSeparator[] {
const consumptionPower = Value.positiveOnly(Value.plus(this.photovoltaicPower, this.gridPower));
const selfConsumed = Value.map(this.photovoltaicProduced, producedTotal => {
if (this.gridDelivered === null || this.gridDelivered.value === null) {
return null;
}
const producedAfterChange = producedTotal - PRODUCED_UNTIL_METER_CHANGE;
const deliveredAfterChange = this.gridDelivered?.value || 0;
const deliveredAfterChange = this.gridDelivered?.value;
const selfAfterChange = producedAfterChange - deliveredAfterChange;
const selfRatio = selfAfterChange / producedAfterChange;
return selfRatio * producedTotal;
});
const deliveringAny = (this.gridPower?.value || 0) < 0;
const purchasingAny = (this.gridPower?.value || 0) > 0;
const purchasingMuch = (this.gridPower?.value || 0) > PURCHASING_MUCH;
const producingAny = (this.photovoltaicPower?.value || 0) > 0;
const gridColor = deliveringAny ? 'magenta' : (purchasingMuch ? 'red' : (purchasingAny ? 'orange' : 'green'));
const productionColor = producingAny ? 'green' : 'black';
const gridColor = this.getGridPowerColor();
const productionColor = this.getProductionPowerColor();
return [
new Display('Bezug', '', this.gridPurchased),
new Display('Einspeisung', '', this.gridDelivered),
@ -94,4 +91,39 @@ export class DashboardComponent implements OnInit {
];
}
private getGridPowerColor(): string {
if (this.gridPower !== null && this.gridPower.value !== null) {
const deliveringAny = this.gridPower.value < 0;
if (deliveringAny) {
return 'magenta';
}
const purchasingMuch = this.gridPower.value > PURCHASING_MUCH;
if (purchasingMuch) {
return 'red';
}
const purchasingAny = this.gridPower.value > 0;
if (purchasingAny) {
return 'orange';
}
return 'green';
}
return '';
}
private getProductionPowerColor() {
if (this.photovoltaicPower === null || this.photovoltaicPower.value === null) {
return '';
}
const producingAny = this.photovoltaicPower.value > 0;
if (producingAny) {
return 'green';
}
return 'black';
}
}