From 2959c1046d30b9c16c717ff3aef4d120380d9bd4 Mon Sep 17 00:00:00 2001 From: Florian Bezannier Date: Wed, 21 Apr 2021 14:23:27 +0200 Subject: [PATCH] add total elec consumption --- trip.py | 3 +++ web/figures.py | 28 +++++++++++++++------------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/trip.py b/trip.py index 7e80007..e58a1a8 100644 --- a/trip.py +++ b/trip.py @@ -113,6 +113,9 @@ class Trips(list): "consumption": trip.consumption, "consumption_by_temp": trip.get_temperature()}) return res + def get_distance(self): + return self[-1].mileage - self[0].mileage + def check_and_append(self, trip: Trip): if trip.consumption_km <= trip.car.max_elec_consumption and \ trip.consumption_fuel_km <= trip.car.max_fuel_consumption: diff --git a/web/figures.py b/web/figures.py index 968d69c..9177a98 100644 --- a/web/figures.py +++ b/web/figures.py @@ -121,20 +121,11 @@ def get_figures(trips: Trips, charging: List[dict]): charge_speed = 3600 * charging_data["kw"].mean() / \ (charging_data["stop_at"] - charging_data["start_at"]).mean().total_seconds() price_kw = (charging_data["price"] / charging_data["kw"]).mean() - except (TypeError, KeyError): # when there is no data yet: + total_elec = kw_per_km * trips.get_distance() / 100 + except (TypeError, KeyError, ZeroDivisionError): # when there is no data yet: charge_speed = 0 price_kw = 0 - - battery_info = dash_table.DataTable( - id='battery_info', - sort_action='native', - columns=[{'id': 'name', 'name': ''}, - {'id': 'value', 'name': ''}], - style_header={'display': 'none'}, - style_data={'border': '0px'}, - data=[{"name": "Average emission:", "value": "{:.1f} g/km".format(co2_per_km)}, - {"name": " ", "value:": "{:.1f} g/kWh".format(co2_per_kw)}, - {"name": "Average charge speed:", "value": "{:.3f} kW".format(charge_speed)}]) + total_elec = 0 battery_info = html.Div(children=[ html.Tr( [ @@ -161,7 +152,18 @@ def get_figures(trips: Trips, charging: List[dict]): ), html.Tr( [ - "{:.2f} {}/kW".format(price_kw, ElecPrice.currency), + "{:.2f} {}/kWh".format(price_kw, ElecPrice.currency), + ] + ), + html.Tr( + [ + html.Td('Electricity consumption:', rowSpan=2), + html.Td("{:.0f} kWh".format(total_elec)), + ] + ), + html.Tr( + [ + "{:.0f} {}".format(total_elec*price_kw, ElecPrice.currency), ] ), ])