mirror of
https://github.com/flobz/psa_car_controller.git
synced 2026-08-26 10:17:18 +00:00
update trips automatically
This commit is contained in:
+2
-1
@@ -405,7 +405,8 @@ class MyPSACC:
|
||||
def set_record(self, value: bool):
|
||||
self._record_enabled = value
|
||||
|
||||
def record_position(self, vin, res: psac.models.status.Status):
|
||||
@staticmethod
|
||||
def record_position(vin, res: psac.models.status.Status):
|
||||
conn = sqlite3.connect('info.db')
|
||||
conn.execute(
|
||||
"CREATE TABLE IF NOT EXISTS position (Timestamp DATETIME PRIMARY KEY, VIN TEXT, longitude REAL, latitude REAL, mileage REAL, level INTEGER);")
|
||||
|
||||
+14
-2
@@ -1,4 +1,5 @@
|
||||
import json
|
||||
import sqlite3
|
||||
import traceback
|
||||
from datetime import datetime, timezone
|
||||
import dash_bootstrap_components as dbc
|
||||
@@ -33,7 +34,7 @@ def display_value(value):
|
||||
|
||||
|
||||
@app.route('/getvehicles')
|
||||
def getvehicules():
|
||||
def get_vehicules():
|
||||
return jsonify(myp.getVIN())
|
||||
|
||||
|
||||
@@ -102,9 +103,16 @@ def after_request(response):
|
||||
header['Access-Control-Allow-Origin'] = '*'
|
||||
return response
|
||||
|
||||
def update_trips():
|
||||
global trips
|
||||
logger.info("update_trips")
|
||||
try:
|
||||
trips = MyPSACC.get_trips()
|
||||
except:
|
||||
logger.error("update_trips: "+traceback.format_exc())
|
||||
|
||||
try:
|
||||
trips = MyPSACC.get_trips()
|
||||
update_trips()
|
||||
min_date = trips[0].start_at
|
||||
max_date = trips[-1].start_at
|
||||
min_millis = figures.unix_time_millis(min_date)
|
||||
@@ -146,3 +154,7 @@ dash_app.layout = dbc.Container(fluid=True, children=[
|
||||
html.H1('My car info'),
|
||||
data_div
|
||||
])
|
||||
conn = sqlite3.connect('info.db')
|
||||
conn.create_function("update_trips",0,update_trips)
|
||||
conn.execute("CREATE TRIGGER IF NOT EXISTS update_trigger AFTER INSERT ON position BEGIN SELECT update_trips(); END;")
|
||||
conn.commit()
|
||||
|
||||
Reference in New Issue
Block a user