From f605f26f2f495554fbace1059ebc77a66ad72e8d Mon Sep 17 00:00:00 2001 From: quoije Date: Mon, 1 Apr 2024 20:21:52 -0400 Subject: [PATCH] restructure --- modules/app_obd.py | 5 +++-- modules/app_sql.py | 17 +++++++++++++++++ modules/app_tsv.py | 25 ------------------------- modules/db_notes.tsv | 4 ---- 4 files changed, 20 insertions(+), 31 deletions(-) create mode 100644 modules/app_sql.py delete mode 100644 modules/app_tsv.py delete mode 100644 modules/db_notes.tsv diff --git a/modules/app_obd.py b/modules/app_obd.py index a45d7f3..cef10f7 100644 --- a/modules/app_obd.py +++ b/modules/app_obd.py @@ -1,4 +1,4 @@ -import obd, time, threading, app_gps +import obd, time, threading, app_gps, app_sql from datetime import datetime from app_events import socketio from threading import Thread @@ -66,11 +66,12 @@ def obd_speed(): while loop == True: global speed speed = speed + 1 - time.sleep(1) + time.sleep(10) if response.is_null(): print("No data received. #"+ str(get_speedtime())) print(app_gps.get_gps()) socketio.emit('obd_speed', get_speedtime()) + app_sql.tsv_writer() else: print("Original value:", response.value) print("Value in kph:", response.value.to("kph")) diff --git a/modules/app_sql.py b/modules/app_sql.py new file mode 100644 index 0000000..5a6bb6c --- /dev/null +++ b/modules/app_sql.py @@ -0,0 +1,17 @@ +import csv, os +import app_obd, app_car, app_account, app_gps +from datetime import datetime + +currentday = datetime.today().strftime("%d%m%Y") +currenttime = datetime.now().strftime("%H_%M_%S") +account = app_account.Account +car = app_car.Car +sCarModel = ''.join(letter for letter in car.model if letter.isalnum()) +sql_name = account.name + "_" + sCarModel + "_" + currentday + ".sql" +sql_path = "../db/sql/" + + + +# ## VN, NAME, DATE, TIME, GPS_X, GPS_Y, SPEED, ODOMETER +# (["VN", "NAME", "DATE", "TIME", "GPSX", "GPSY", "SPEED", "ODOMETER"]) +# ([car.model, account.name, currentday, currenttime, GPSX, GPSY, SPEED, ODOMETER]) \ No newline at end of file diff --git a/modules/app_tsv.py b/modules/app_tsv.py deleted file mode 100644 index fb08fff..0000000 --- a/modules/app_tsv.py +++ /dev/null @@ -1,25 +0,0 @@ -import csv, os -import app_obd, app_car, app_account, app_gps -from datetime import datetime - -currentday = datetime.today().strftime("%d%m%Y") -currenttime = datetime.now().strftime("%H_%M_%S") -account = app_account.Account -car = app_car.Car -sCarModel = ''.join(letter for letter in car.model if letter.isalnum()) -tsv_name = account.name + "_" + sCarModel + "_" + currentday + "_" + currenttime + ".tsv" -tsv_path = "../db/tsv/" + tsv_name - -def tsv_writer(bExist): - with open(tsv_path, 'w') as o_file: - ## VN, NAME, DATE, TIME, GPS_X, GPS_Y, SPEED, ODOMETER - writer = csv.writer(o_file, delimiter='\t') - if bExist == False: - writer.writerow(["VN", "NAME", "DATE", "TIME", "GX", "GY", "SPEED", "ODO"]) - else: - writer.writerow([car.model, account.name, currentday, currenttime]) - -if os.path.exists(tsv_path): - tsv_writer(True) -else: - tsv_writer(False) \ No newline at end of file diff --git a/modules/db_notes.tsv b/modules/db_notes.tsv deleted file mode 100644 index 95df430..0000000 --- a/modules/db_notes.tsv +++ /dev/null @@ -1,4 +0,0 @@ -## TSV File to MangoDB -## ACCOUNT_VN_20240401_00_00_00.TSV -## -## VN NAME, DATE, TIME, GPS_X, GPS_Y, SPEED, ODOMETER \ No newline at end of file