mirror of
https://github.com/flobz/psa_car_controller.git
synced 2026-08-26 10:17:18 +00:00
improve performance & debug
This commit is contained in:
+2
-2
@@ -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
@@ -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
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user