-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodels.py
More file actions
94 lines (80 loc) · 2.41 KB
/
models.py
File metadata and controls
94 lines (80 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"""
This module contains the table model for the logfile as well as
connects to the database.
"""
from os.path import join
from kivy import platform
from peewee import (
BooleanField,
CharField,
DateField,
IntegerField,
Model,
SqliteDatabase,
TimeField,
)
from playhouse.migrate import SqliteMigrator, migrate
# Default file for saving log
db_file = "logfile.db"
settings_file = "settings.ini"
# Since the testing is done on a desktop, the path is written for desktop. Hence, the filename is changed
# to an android-compatible path when the app is actually run on an android phone
if platform == "android":
from android.storage import (
app_storage_path, # This module is only available on android platform
)
storage = app_storage_path()
db_file = join(storage, db_file)
settings_file = join(storage, settings_file)
db = SqliteDatabase(db_file)
class EventLog(Model):
"""Basic Structure of the logfile database table"""
carno = IntegerField()
location = CharField()
date = DateField()
time = TimeField()
rtime = TimeField(null=True)
LL = BooleanField(default=False)
is_rtm = BooleanField(default=False)
class Meta:
database = db
def upload(sheet, name, fl_mode, sync):
log = EventLog.select()
data = list()
data.append(
[
"Car no.",
"Time",
"Restart Time",
"Lifeline",
"Location",
"Date",
"Uploader Name",
"Flight Mode",
"Synced",
]
)
for i in log:
rtime = str(i.rtime) if i.is_rtm else ""
LL = "Yes" if i.LL else "No"
data.append(
[
"" if not i.carno else str(i.carno),
str(i.time),
rtime,
LL,
i.location,
str(i.date),
name,
fl_mode,
sync,
]
)
sheet.append_rows(data)
if db.get_tables() == []: # if the table doesn't exist, then create one
EventLog.create_table()
# Backwards compatibility
cols = [i.name for i in db.get_columns("eventlog")]
if "rtime" in cols:
mg = SqliteMigrator(db)
migrate(mg.alter_column_type("eventlog", "rtime", TimeField(null=True)))