From 7eb85ce6302bea2e43eb1e91f5a8c2283622bafb Mon Sep 17 00:00:00 2001 From: ztimson Date: Tue, 1 Jan 2019 16:03:40 -0500 Subject: [PATCH] Fixed some of the math --- src/app/battery/battery.component.html | 2 +- src/app/battery/battery.service.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/app/battery/battery.component.html b/src/app/battery/battery.component.html index d4ad400..050d49b 100644 --- a/src/app/battery/battery.component.html +++ b/src/app/battery/battery.component.html @@ -1,7 +1,7 @@
-

Powerwall: {{batteryService.total}} V

+

Powerwall: {{batteryService.total | round}} V

diff --git a/src/app/battery/battery.service.ts b/src/app/battery/battery.service.ts index 11df0fe..789b85c 100644 --- a/src/app/battery/battery.service.ts +++ b/src/app/battery/battery.service.ts @@ -57,6 +57,12 @@ export class BatteryService { } }); + this.batteries.map((battery, i, arr) => { + if(i % 2 == 1) return battery; + console.log(i, battery.charge); + battery.charge = battery.charge - arr[i + 1].charge; + }); + this.total = this.batteries.reduce((acc, battery) => acc + battery.charge, 0) / 2; console.log(this.batteries)