From 13e6d4ec3d971ee2f21347f0cc66697f8abb15bb Mon Sep 17 00:00:00 2001 From: Florian Bezannier Date: Wed, 23 Dec 2020 16:50:43 +0100 Subject: [PATCH] try new method to update_trips --- web/callback.py | 7 ++----- web/db.py | 7 +++++++ 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/web/callback.py b/web/callback.py index 16b8d7f..e4b384b 100644 --- a/web/callback.py +++ b/web/callback.py @@ -13,7 +13,7 @@ from MyPSACC import MyPSACC from web import figures from web.app import app, dash_app, myp, chc, save_config -from web.db import get_db +import web.db @dash_app.callback(Output('trips_map', 'figure'), @@ -158,7 +158,4 @@ dash_app.layout = dbc.Container(fluid=True, children=[ data_div ]) -conn = get_db() -conn.create_function("update_trips", 0, update_trips) -conn.execute("CREATE TEMP TRIGGER IF NOT EXISTS update_trigger AFTER INSERT ON position BEGIN SELECT update_trips(); END;") -conn.commit() +web.db.update_callback = update_trips \ No newline at end of file diff --git a/web/db.py b/web/db.py index e252e48..c09976f 100644 --- a/web/db.py +++ b/web/db.py @@ -7,11 +7,18 @@ def convert_datetime(st): return datetime.strptime(st.decode("utf-8"), "%Y-%m-%d %H:%M:%S+00:00").replace(tzinfo=pytz.UTC) +def update_callback(): + return + def get_db(): sqlite3.register_converter("DATETIME", convert_datetime) conn = sqlite3.connect('info.db', detect_types=sqlite3.PARSE_DECLTYPES | sqlite3.PARSE_COLNAMES) conn.row_factory = sqlite3.Row conn.execute("CREATE TABLE IF NOT EXISTS position (Timestamp DATETIME PRIMARY KEY, VIN TEXT, longitude REAL, " "latitude REAL, mileage REAL, level INTEGER);") + conn.create_function("update_trips", 0, update_callback) + conn.execute( + "CREATE TEMP TRIGGER IF NOT EXISTS update_trigger AFTER INSERT ON position BEGIN SELECT update_trips(); END;") + conn.commit() conn.commit() return conn