clean code

This commit is contained in:
Florian Bezannier
2021-03-29 16:34:16 +02:00
parent e173f13b4e
commit 70fcd452f1
2 changed files with 10 additions and 7 deletions
+6 -5
View File
@@ -19,6 +19,7 @@ class TripParser:
return TripParser.get_thermal_consumption, self.__is_refuel
if self.car.is_hybrid():
return TripParser.get_hybrid_consumption, self.__is_refuel_or_recharging
raise ValueError("Unknown car type")
@staticmethod
def get_thermal_consumption(start, end):
@@ -43,24 +44,24 @@ class TripParser:
if fuel_consumption < 0:
logger.debugv("refuel detected")
return True
elif TripParser.is_recharging(decharge, fuel_consumption, distance):
if TripParser.is_recharging(decharge, distance):
logger.debugv("charge detected")
return True
return False
def __is_refuel(self, start, end, distance):
decharge, fuel_consumption = self.get_level_consumption(start, end)
fuel_consumption = self.get_level_consumption(start, end)[1]
if fuel_consumption < 0:
logger.debugv("refuel detected")
return True
return False
def __is_recharging(self, start, end, distance):
decharge, fuel_consumption = self.get_level_consumption(start, end)
return TripParser.is_recharging(decharge, fuel_consumption, distance)
decharge = self.get_level_consumption(start, end)[0]
return TripParser.is_recharging(decharge, distance)
@staticmethod
def is_recharging(decharge, _, distance):
def is_recharging(decharge, distance):
# A margin of two is set because battery level can increase with regeneration system or temperature change.
# If distance is bigger than 0 but charge bigger than five there is probably missing point and we assume that
# regeneration/temperature can't increase by 5 percent the battery level
+4 -2
View File
@@ -7,7 +7,7 @@ import requests
from MyLogger import logger
def get_temp(latitude:str, longitude:str, api_key:str) -> float:
def get_temp(latitude: str, longitude: str, api_key: str) -> float:
try:
if not (latitude is None or longitude is None or api_key is None):
weather_rep = requests.get("https://api.openweathermap.org/data/2.5/onecall",
@@ -22,6 +22,8 @@ def get_temp(latitude:str, longitude:str, api_key:str) -> float:
logger.error("Can't connect to openweathermap :%s", traceback.format_exc())
except KeyError:
logger.error("Unable to get temperature from openweathermap :%s", traceback.format_exc())
return None
def rate_limit(limit, every):
def limit_decorator(fn):
@@ -39,4 +41,4 @@ def rate_limit(limit, every):
return wrapper
return limit_decorator
return limit_decorator