-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_sqlite.py
217 lines (175 loc) · 6.82 KB
/
_sqlite.py
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
import sqlite3
import tkinter as tk
import datetime
#import _functionality as _f
##########-----FIRST START-----###########
def firstStart():
conn = sqlite3.connect('_data.db') # ':memory:'
c = conn.cursor()
# Cameras table and initial entries
c.execute("""CREATE TABLE IF NOT EXISTS cameras (
id integer,
name text,
ipcam_streaming_url text)""")
c.execute("""INSERT INTO cameras (id, name, ipcam_streaming_url) VALUES
(1, 'My Camera', '0'),
(2, '', ''),
(3, '', ''),
(4, '', ''),
(5, '', ''),
(6, '', ''),
(7, '', ''),
(8, '', '')
""")
# Visual table and its initial entries
c.execute("""CREATE TABLE IF NOT EXISTS visual (
id integer,
name text,
transparency text,
bgcolor text,
data1 text,
data2 text,
data3 text,
data4 text,
data5 text)""")
c.execute("""INSERT INTO visual (id, name, transparency, bgcolor, data1, data2, data3, data4, data5) VALUES
(1, 'dark_transparent', '0.90', '#3A3939', '', '', '', '', '')
""")
# Sound table and its initial entries
c.execute("""CREATE TABLE IF NOT EXISTS sound (
id integer,
name text,
soundfile text)""")
c.execute("""INSERT INTO sound (id, name, soundfile) VALUES
(1, 'clang', 'alarm.wav')
""")
# ai table and its initial entries
c.execute("""CREATE TABLE IF NOT EXISTS ai (
id integer,
ai_model_type text,
ai_model_file text,
ai_detection_speed text,
ai_minimum_percentage text)""")
c.execute("""INSERT INTO ai (id, ai_model_type, ai_model_file, ai_detection_speed, ai_minimum_percentage) VALUES
(1, 'setModelTypeAsYOLOv3', 'yolo.h5', 'fastest', '50')
""")
conn.commit()
conn.close()
##########-----CAMERAS-----###########
def updateCameras(id, name, ipcam_streaming_url):
conn = sqlite3.connect('_data.db') # ':memory:'
c = conn.cursor()
c.execute("UPDATE cameras SET name = :name, ipcam_streaming_url = :ipcam_streaming_url WHERE id = :id",
{'id': id, 'name': name, 'ipcam_streaming_url': ipcam_streaming_url})
print(str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")) + " - Camera Updated | Id: " + id + " | Camera Name: " + name + " | Address: " + ipcam_streaming_url)
#print(name)
#print(ipcam_streaming_url)
conn.commit()
conn.close()
def getCameras():
conn = sqlite3.connect('_data.db')
c = conn.cursor()
try:
result = c.execute("""SELECT id, name, ipcam_streaming_url FROM cameras""")
#{'id': id}) # WHERE id = :id
getCameras.result = result
except sqlite3.OperationalError:
print("The table does not exist (getCameras)")
except:
print("Wasn't possible to do it (getCameras)")
conn.commit()
# conn.close() # There is no conn.close
##########-----VISUAL-----###########
def updateVisual(name):
if name == "Standard Dark":
name = "Standard Dark"
transparency = "1"
bgcolor = "#3A3939"
elif name == "Standard Bright":
name = "Standard Bright"
transparency = "1"
bgcolor = "#DBD8D8"
elif name == "Dark Transparent":
name = "Dark Transparent"
transparency = "0.90"
bgcolor = "#3A3939"
elif name == "Navy Transparent":
name = "Navy Transparent"
transparency = "0.90"
bgcolor = "#134269"
else:
print("updateVisual: Entered value does not exist.")
conn = sqlite3.connect('_data.db')
c = conn.cursor()
c.execute("UPDATE visual SET name = :name, transparency = :transparency, bgcolor = :bgcolor WHERE id = 1",
{'name': name, 'transparency': transparency, 'bgcolor': bgcolor})
conn.commit()
conn.close()
def getVisual():
conn = sqlite3.connect('_data.db')
c = conn.cursor()
try:
result = c.execute("""SELECT id, name, transparency, bgcolor, data1, data2, data3, data4, data5 FROM visual WHERE id = 1""")
getVisual.result = result
except sqlite3.OperationalError:
print("The table does not exist (getVisual)")
except:
print("Wasn't possible to do it (getVisual)")
conn.commit()
#conn.close() # There is no conn.close
##########-----SOUND-----###########
def updateSound(name):
conn = sqlite3.connect('_data.db')
c = conn.cursor()
c.execute("UPDATE sound SET name = :name, soundfile = :soundfile WHERE id = 1",
{'name': name, 'soundfile': name + '.wav'})
conn.commit()
conn.close()
def getSound():
conn = sqlite3.connect('_data.db')
c = conn.cursor()
try:
result = c.execute("""SELECT id, name, soundfile FROM sound WHERE id = 1""")
getSound.result = result
except sqlite3.OperationalError:
print("The table does not exist (getSound)")
except:
print("Wasn't possible to do it (getSound)")
conn.commit()
#conn.close() # There is no conn.close
def connClose():
conn = sqlite3.connect('_data.db')
conn.close()
##########-----AI-----###########
def updateAI(ai_model, ai_detection_speed, ai_minimum_percentage):
if ai_model == "TinyYOLOv3":
ai_model_type = "setModelTypeAsTinyYOLOv3"
ai_model_file = "yolo-tiny.h5"
elif ai_model == "YOLOv3":
ai_model_type = "setModelTypeAsYOLOv3"
ai_model_file = "yolo.h5"
elif ai_model == "RetinaNet":
ai_model_type = "setModelTypeAsRetinaNet"
ai_model_file = "resnet50_coco_best_v2.0.1.h5"
conn = sqlite3.connect('_data.db')
c = conn.cursor()
c.execute("UPDATE ai SET ai_model_type = :ai_model_type, ai_model_file = :ai_model_file, ai_detection_speed = :ai_detection_speed, ai_minimum_percentage = :ai_minimum_percentage WHERE id = 1",
{'ai_model_type': ai_model_type, 'ai_model_file': ai_model_file, 'ai_detection_speed': ai_detection_speed, 'ai_minimum_percentage': ai_minimum_percentage})
conn.commit()
conn.close()
def getAI():
conn = sqlite3.connect('_data.db')
c = conn.cursor()
try:
result = c.execute("""SELECT id, ai_model_type, ai_model_file, ai_detection_speed, ai_minimum_percentage FROM ai WHERE id = 1""")
getAI.result = result
except sqlite3.OperationalError:
print("The table does not exist (getAI)")
except:
print("Wasn't possible to do it (getAI)")
conn.commit()
#conn.close() # There is no conn.close
#firstStart()
#updateCameras()
#getCameras()
#entryCameras()