-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathdb.py
58 lines (47 loc) · 1.03 KB
/
db.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
from tinydb import TinyDB, Query
from threading import RLock
from consts import PUMP_LOG
from consts import CHARGE_LOG
from consts import FAN_LOG
from consts import SERVICE_LOG
from datetime import datetime
pumpDB = TinyDB(PUMP_LOG)
fanDB = TinyDB(FAN_LOG)
chargeDB = TinyDB(CHARGE_LOG)
serviceDB = TinyDB(SERVICE_LOG)
rlock = RLock()
def logPumpRun(entry):
with rlock:
pumpDB.insert(entry)
def getLatestPumpRun():
with rlock:
pumpRun = Query()
searchResult = pumpDB.search(pumpRun.event == "Pump Run")
if (len(searchResult) > 0):
return searchResult[-1]
else:
return None
def logFanRun(entry):
with rlock:
fanDB.insert(entry)
def logChargeRun(entry):
with rlock:
chargeDB.insert(entry)
def getRecentPumpRuns():
logs = pumpDB.all()
if (len(logs) > 25):
return logs[-25:]
else:
return logs
def getRecentFanRuns():
logs = fanDB.all()
if (len(logs) > 25):
return logs[-25:]
else:
return logs
def getRecentChargeRuns():
logs = chargeDB.all()
if (len(logs) > 25):
return logs[-25:]
else:
return logs