diff --git a/.gitignore b/.gitignore index 0176c31..739c14f 100644 --- a/.gitignore +++ b/.gitignore @@ -143,4 +143,4 @@ info.db otp.bin charge_config1.json config.json -test.json \ No newline at end of file +test.json diff --git a/MyPSACC.py b/MyPSACC.py index d2cbe7a..551b295 100644 --- a/MyPSACC.py +++ b/MyPSACC.py @@ -512,6 +512,14 @@ class MyPSACC: except Exception as e: logger.error(f"Unable to get temperature from openweathermap :{e}") + if level_fuel == 0: # fix fuel level not provided when car is off + try: + level_fuel = conn.execute("SELECT level_fuel FROM position WHERE level_fuel>0 AND VIN=? ORDER BY Timestamp DESC LIMIT 1",(vin,)).fetchone()[0] + logger.info(f"level_fuel fixed with last real value {level_fuel} for {vin}") + except TypeError: + level_fuel = '' + logger.info(f"level_fuel unfixed for {vin}") + conn.execute( "INSERT INTO position(Timestamp,VIN,longitude,latitude,mileage,level,level_fuel,moving,temperature) VALUES(?,?,?,?,?,?,?,?,?)", (date, vin, longitude, latitude, mileage, level, level_fuel, moving, temp)) diff --git a/web/figures.py b/web/figures.py index 52ad244..634d025 100644 --- a/web/figures.py +++ b/web/figures.py @@ -105,12 +105,16 @@ def get_figures(trips: List[Trip], charging: List[dict]): co2_per_kw = charging_data["co2"].sum() / charging_data["kw"].sum() except ZeroDivisionError: co2_per_kw = 0 + except KeyError: # when there is no data yet: + co2_per_kw = 0 co2_per_km = co2_per_kw * kw_per_km / 100 try: charge_speed = 3600 * charging_data["kw"].mean() / \ (charging_data["stop_at"] - charging_data["start_at"]).mean().total_seconds() except TypeError: # when there is no data yet: charge_speed = 0 + except KeyError: # when there is no data yet: + charge_speed = 0 battery_info = html.Div(children=[html.P("Average gC02/kW: {:.1f}".format(co2_per_kw)), html.P("Average gC02/km: {:1f}".format(co2_per_km)), html.P("Average Charge SPEED {:1f} kW/h".format(charge_speed))])