fix view charge without trip after

This commit is contained in:
jlayec
2021-05-03 20:09:09 +02:00
committed by Florian BEZANNIER
parent 6ac1377e0c
commit 108d7d6be5
2 changed files with 16 additions and 3 deletions
+9
View File
@@ -140,6 +140,15 @@ class Database:
return None
return res[0]
@staticmethod
def get_range_timestamp():
conn = Database.get_db()
first = conn.execute("SELECT Timestamp FROM position ORDER BY Timestamp limit 1").fetchone()
last = conn.execute("SELECT Timestamp FROM position ORDER BY Timestamp DESC limit 1").fetchone()
if first is None or last is None:
return None, None
return first[0], last[0]
@staticmethod
def set_chargings_price(conn, start_at, price):
if isinstance(start_at, str):
+7 -3
View File
@@ -250,12 +250,14 @@ def update_trips():
chargings = Charging.get_chargings()
except (StopIteration, AssertionError):
logger.debug("No trips yet")
return
# return
# update for slider
global min_date, max_date, min_millis, max_millis, step, marks
try:
min_date = trips[0].start_at
max_date = trips[-1].start_at
# min_date = trips[0].start_at
# max_date = trips[-1].start_at
min_date, max_date = Database.get_range_timestamp()
logger.debug("min_date:%s - max_date:%s",min_date, max_date)
min_millis = figures.unix_time_millis(min_date)
max_millis = figures.unix_time_millis(max_date)
step = (max_millis - min_millis) / 100
@@ -263,6 +265,8 @@ def update_trips():
cached_layout = None # force regenerate layout
except (ValueError, IndexError):
logger.error("update_trips (slider): %s", exc_info=True)
except AttributeError:
logger.debug("position table is probably empty :", exc_info=True)
return