-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
61 lines (41 loc) · 1.63 KB
/
main.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
from tray.firebaseclient import FirebaseClient
from SWA.windowlogger import WindowLogger
from tray.start_tray import Tray
import datetime
import time
import threading
from SWA.analyzer import Analyzer
import os
from queue import Queue
def analyzerTask(q):
SHORTTIMEHISTORYTIME_SECONDS = 10
REFRESH_RATE_SECONDS = 5
ourAnalyzer = Analyzer(REFRESH_RATE_SECONDS, SHORTTIMEHISTORYTIME_SECONDS, q)
def subsystem(q):
#initialze the WindowLogger
windowLogger = WindowLogger(datetime.timedelta(seconds=1))
thread = threading.Thread(target=windowLogger.start)
thread.start()
#iniitalize the ANalyzer
analyzerThread = threading.Thread(target=analyzerTask, args=(q,), kwargs={})
analyzerThread.start()
print("Started window logger and analyzer")
while True:
activeWindowHistory = windowLogger.getActiveWindowHistoryCompacted()
for w in activeWindowHistory:
fb.send_windowlogger_data_to_firestore(w[0], w[1])
for i in range(0, 100, 1):
if(i%10 == 0):
print("Latest activity: ")
with open( os.path.join(os.getcwd(), "log","shortTimeHistory.csv"), 'r') as file:
print(file.read())
time.sleep(2)
if __name__ == '__main__':
# Iniitlaize FirebaseClient
fb = FirebaseClient()
q = Queue()
tray = Tray(q)
worker_thread = threading.Thread(target=subsystem, args=(q,), kwargs={})
worker_thread.daemon = True # Daemonize the thread so it exits when the main program does
worker_thread.start()
tray.start()