avoid fuel level 0 for hybrid cars + fix empty battery table

This commit is contained in:
jlayec
2021-02-10 21:55:06 +00:00
parent d7adc4ee96
commit d00f23f178
3 changed files with 13 additions and 1 deletions
+1 -1
View File
@@ -143,4 +143,4 @@ info.db
otp.bin
charge_config1.json
config.json
test.json
test.json
+8
View File
@@ -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))
+4
View File
@@ -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))])