improve performance & debug

This commit is contained in:
Florian Bezannier
2021-04-30 10:26:55 +02:00
parent 86cb20f9e6
commit 5f75d3fb30
16 changed files with 117 additions and 121 deletions
+2 -2
View File
@@ -42,7 +42,7 @@ class Car:
if self.status is not None:
return self.status
logger.error("status of %s is None", self.vin)
raise ValueError("status of %s is None")
raise ValueError("status of {} is None".format(self.vin))
@classmethod
def from_json(cls, data: dict):
@@ -82,7 +82,7 @@ class Car:
class Cars(list):
def __init__(self, *args):
list.__init__(self, *args)
self.config_filename = "../cars.json"
self.config_filename = "cars.json"
def get_car_by_vin(self, vin) -> Car:
for car in self:
+2 -3
View File
@@ -1,4 +1,3 @@
import traceback
from datetime import datetime
from sqlite3 import IntegrityError
@@ -11,7 +10,7 @@ from web.db import Database
class Charging:
elec_price: ElecPrice = None
elec_price: ElecPrice = ElecPrice(None)
@staticmethod
def get_chargings(mini=None, maxi=None) -> List[dict]:
@@ -78,6 +77,6 @@ class Charging:
Charging.update_chargings(conn, start_at, charge_date, level, co2_per_kw, consumption_kw, car.vin)
except TypeError:
logger.debug("battery table is probably empty : %s", traceback.format_exc())
logger.debug("battery table is probably empty :", exc_info=True)
conn.commit()
conn.close()
+9 -8
View File
@@ -54,14 +54,15 @@ class ElecPrice:
def get_price(self, start, end, consumption):
prices = []
date = start
while date < end:
prices.append(self.get_instant_price(date))
date = date + timedelta(minutes=30)
try:
res = round(consumption * mean(prices), 2)
except TypeError:
logger.error("Can't get_price of charge, check config")
res = None
res = None
if not (start is None or end is None):
while date < end:
prices.append(self.get_instant_price(date))
date = date + timedelta(minutes=30)
try:
res = round(consumption * mean(prices), 2)
except TypeError:
logger.error("Can't get_price of charge, check config")
return res
def is_enable(self):