Skip to content

Commit b4a73b8

Browse files
authored
UI: Fix Infinity sign in charts & the wrong date formating (OpenEMS#2372)
1 parent 7e45591 commit b4a73b8

File tree

4 files changed

+29
-20
lines changed

4 files changed

+29
-20
lines changed

ui/src/app/edge/history/common/energy/chart/chart.spec.ts

+8-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ describe('History EnergyMonitor', () => {
1818

1919
it('getChartData()', () => {
2020
{
21-
// Line-Chart
21+
// Line - Chart
2222
expectView(defaultEMS, TEST_CONTEXT, 'line', History.DAY,
2323
{
2424
datasets: {
@@ -34,7 +34,9 @@ describe('History EnergyMonitor', () => {
3434
labels: LABELS(History.DAY.dataChannelWithValues.result.timestamps),
3535
options: History.LINE_CHART_OPTIONS('hour')
3636
}
37+
3738
});
39+
3840
}
3941
{
4042

@@ -59,16 +61,16 @@ describe('History EnergyMonitor', () => {
5961
}
6062
{
6163

62-
// // Bar-Chart Year
64+
// Bar-Chart Year
6365
expectView(defaultEMS, TEST_CONTEXT, 'bar', History.MONTH,
6466
{
6567
datasets: {
6668
data: [
6769
DATA('Erzeugung: 22.491 kWh', [908, 967, 900, 926, 403, 597, 957, null, 1579, 556, 852, 976, 1026, 724, 839, 749, 709, 978, 607, 790, 652, null, 1011, 697, 908, null, 1466, 808, 906, null]),
6870

6971
// Only one of the two following datasets is shown in legend
70-
DATA('Direktverbrauch: 5.808,7 kWh', [191.524, 214.083, 198.811, 196.842, 184.218, 201.167, 175.916, 0, 347.243, 166.862, 176.461, 218.586, 229.496, 228.661, 211.608, 217.075, 177.422, 179.495, 200.029, 229.434, 229.765, 0, 360.727, 171.324, 206.255, 0, 442.327, 225.59, 227.751, 0]),
71-
DATA('Direktverbrauch: 5.808,7 kWh', [191.524, 214.083, 198.811, 196.842, 184.218, 201.167, 175.916, 0, 347.243, 166.862, 176.461, 218.586, 229.496, 228.661, 211.608, 217.075, 177.422, 179.495, 200.029, 229.434, 229.765, 0, 360.727, 171.324, 206.255, 0, 442.327, 225.59, 227.751, 0]),
72+
DATA('Direktverbrauch: 5.808,7 kWh', [191.524, 214.083, 198.811, 196.842, 184.218, 201.167, 175.916, null, 347.243, 166.862, 176.461, 218.586, 229.496, 228.661, 211.608, 217.075, 177.422, 179.495, 200.029, 229.434, 229.765, null, 360.727, 171.324, 206.255, null, 442.327, 225.59, 227.751, null]),
73+
DATA('Direktverbrauch: 5.808,7 kWh', [191.524, 214.083, 198.811, 196.842, 184.218, 201.167, 175.916, null, 347.243, 166.862, 176.461, 218.586, 229.496, 228.661, 211.608, 217.075, 177.422, 179.495, 200.029, 229.434, 229.765, null, 360.727, 171.324, 206.255, null, 442.327, 225.59, 227.751, null]),
7274
DATA('Beladung: 3.944,3 kWh', [113.476, 162.917, 150.189, 157.158, 149.782, 159.833, 155.084, null, 228.757, 128.138, 157.539, 59.414, 156.504, 107.339, 156.392, 158.925, 158.578, 121.505, 120.971, 154.566, 173.235, null, 204.273, 156.676, 143.745, null, 247.673, 157.41, 104.249, null]),
7375
DATA('Entladung: 3.394,4 kWh', [112.818, 126.532, 139.622, 133.212, 169.24, 98.705, 109.367, null, 204.267, 118.504, 121.261, 74.97, 144.175, 89.897, 141.582, 111.261, 122.274, 106.232, 139.405, 132.225, 143.86, null, 235.044, 63.914, 123.844, null, 242.102, 130.546, 59.571, null]),
7476
DATA('Netzeinspeisung: 12.738 kWh', [603, 590, 551, 572, 69, 236, 626, null, 1003, 261, 518, 698, 640, 388, 471, 373, 373, 677, 286, 406, 249, null, 446, 369, 558, null, 776, 425, 574, null]),
@@ -90,8 +92,8 @@ describe('History EnergyMonitor', () => {
9092
DATA('Erzeugung: 68.466 kWh', [1912, 3816, 7165, 10452, 20841, 22491, 1546, null, null, null, null, null]),
9193

9294
// Only one of the two following datasets is shown in legend
93-
DATA('Direktverbrauch: 22.466,2 kWh', [1597.394, 2056.891, 3150.228, 3720.697, 5506.053, 5808.6720000000005, 546.405, 0, 0, 0, 0, 0]),
94-
DATA('Direktverbrauch: 22.466,2 kWh', [1597.394, 2056.891, 3150.228, 3720.697, 5506.053, 5808.6720000000005, 546.405, 0, 0, 0, 0, 0]),
95+
DATA('Direktverbrauch: 22.466,2 kWh', [1597.394, 2056.891, 3150.228, 3720.697, 5506.053, 5808.6720000000005, 546.405, null, null, null, null, null]),
96+
DATA('Direktverbrauch: 22.466,2 kWh', [1597.394, 2056.891, 3150.228, 3720.697, 5506.053, 5808.6720000000005, 546.405, null, null, null, null, null]),
9597
DATA('Beladung: 15.296,8 kWh', [294.606, 1673.109, 3337.772, 3074.303, 2495.947, 3944.328, 372.595, null, null, null, null, null]),
9698
DATA('Entladung: 12.898,2 kWh', [208.491, 1339.036, 2911.126, 2555.138, 2123.751, 3394.43, 335.402, null, null, null, null, null]),
9799
DATA('Netzeinspeisung: 30.703 kWh', [20, 86, 677, 3657, 12839, 12738, 627, null, null, null, null, null]),

ui/src/app/edge/history/common/energy/chart/chart.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ export class ChartComponent extends AbstractHistoryChart {
9797
...[chartType === 'bar' && {
9898
name: translate.instant('General.directConsumption'),
9999
nameSuffix: (energyValues: QueryHistoricTimeseriesEnergyResponse) => {
100-
return energyValues.result.data['_sum/ProductionActiveEnergy'] - energyValues.result.data['_sum/GridSellActiveEnergy'] - energyValues.result.data['_sum/EssDcChargeEnergy'];
100+
return Utils.subtractSafely(energyValues.result.data['_sum/ProductionActiveEnergy'], energyValues.result.data['_sum/GridSellActiveEnergy'], energyValues.result.data['_sum/EssDcChargeEnergy']);
101101
},
102102
converter: () =>
103-
data['ProductionActivePower']?.map((value, index) =>
104-
value - data['GridSell'][index] - data['EssCharge'][index])?.map(value => HistoryUtils.ValueConverter.NEGATIVE_AS_ZERO(value)),
103+
data['ProductionActivePower']?.map((value, index) => Utils.subtractSafely(value, data['GridSell'][index], data['EssCharge'][index]))
104+
?.map(value => HistoryUtils.ValueConverter.NEGATIVE_AS_ZERO(value)),
105105
color: 'rgb(244,164,96)',
106106
stack: [1, 2],
107107
order: 2

ui/src/app/edge/settings/profile/profile.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
</ion-item>
3737
<ion-item lines="none" *ngIf="edge.firstSetupProtocol">
3838
<ion-label translate>Index.FIRST_SETUP_PROTOCOL</ion-label>
39-
{{ edge.firstSetupProtocol | date:'dd.MM.YYYY hh:mm' }}
39+
{{ edge.firstSetupProtocol | date:'dd.MM.YYYY HH:mm' }}
4040
</ion-item>
4141
</ion-list>
4242
</ion-card-content>

ui/src/app/shared/service/utils.ts

+17-10
Original file line numberDiff line numberDiff line change
@@ -105,20 +105,27 @@ export class Utils {
105105
}
106106

107107
/**
108-
* Safely subtracts two - possibly 'null' - values: v1 - v2
108+
* Subtracts values from each other - possibly null values
109109
*
110-
* @param v1
111-
* @param v2
110+
* @param values the values
111+
* @returns a number, if at least one value is not null, else null
112112
*/
113-
public static subtractSafely(v1: number, v2: number): number {
114-
if (v1 == null) {
115-
return v2;
116-
} else if (v2 == null) {
117-
return v1;
118-
} else {
119-
return v1 - v2;
113+
public static subtractSafely(...values: (number | null)[]): number {
114+
let result = null;
115+
116+
for (const value of values) {
117+
if (value !== null) {
118+
if (result === null) {
119+
result = value;
120+
} else {
121+
result -= value;
122+
}
123+
}
120124
}
125+
126+
return result;
121127
}
128+
122129
/**
123130
* Safely divides two - possibly 'null' - values: v1 / v2
124131
*

0 commit comments

Comments
 (0)