aboutsummaryrefslogtreecommitdiff
path: root/src/Watcher/analysis.py
diff options
context:
space:
mode:
authorLibravatar Vaishnav Deore <86405648+Waishnav@users.noreply.github.com>2022-11-14 20:18:17 +0530
committerLibravatar GitHub <noreply@github.com>2022-11-14 20:18:17 +0530
commit20fd09803001a7e6371360afedb3091dd9242d07 (patch)
tree3b46618374f8c6bb4dec0682ecdd65176a1c260c /src/Watcher/analysis.py
parentca1d6e1cacb4b5e3106f556f99687bc3df5af86b (diff)
parent212a5aaf5c1b2b2b956d75c4ba66c95222e31683 (diff)
downloadshopno-os-log-sync-20fd09803001a7e6371360afedb3091dd9242d07.tar.gz
shopno-os-log-sync-20fd09803001a7e6371360afedb3091dd9242d07.zip
Merge pull request #38 from Waishnav/v2.0
v2.0 ready to use
Diffstat (limited to 'src/Watcher/analysis.py')
-rwxr-xr-xsrc/Watcher/analysis.py70
1 files changed, 27 insertions, 43 deletions
diff --git a/src/Watcher/analysis.py b/src/Watcher/analysis.py
index 6e26d29..0e917f8 100755
--- a/src/Watcher/analysis.py
+++ b/src/Watcher/analysis.py
@@ -4,45 +4,26 @@ from watch_log import get_date
import datetime
import time_operations as to
-def extract_data(date):
- user = os.getlogin()
- path = "/home/" + user +"/.cache/Watcher/raw_data/"
+# creating dictionary to store time spend on each applicaitons on that particular day
+def final_report(date):
+ path = "/home/" + os.getlogin() +"/.cache/Watcher/daily_data/"
filename = path + date + ".csv"
- l = list() # l = list of (app_name, time spent on app on that session)
- d = dict()
-
- if os.path.isfile(filename):
- with open(filename, 'r') as file:
- reader = csv.reader(file)
- for row in reader:
- for column in row:
- l.append([column[18::],column[9:17]])
- d.update({column[18::]: "O"})
- else:
- None
-
- d = list(d) # list of app opened on that day
- return d, l
-
-# creating dictionary to store time spend on each applicaitons on that particular day
-def final_report(window_opened, time_spent):
report = dict()
-
- for i in window_opened: # i is applications name
- time = '00:00:00'
- for j in time_spent: # j is list of applicaions_name and time_spent in particular session
- if i == j[0]:
- time = to.time_addition(j[1], time)
- report.update({i:time})
+ if os.path.isfile(filename):
+ with open(filename, 'r') as f:
+ raw_data = f.readlines()
+ for x in raw_data:
+ x = x.split('\t')
+ a = {x[1][:-1]:x[0]}
+ report.update(a)
#print(report)
- if "User-logged-in" in report.keys():
- report.pop("User-logged-in")
- if "AFK" in report.keys():
- report.pop("AFK")
if "Unknown" in report.keys():
report.pop("Unknown")
+ return report
+
+def sort_data(report):
# sort report dictonary in decreasing order of Usages
sorted_values = []
for x,y in report.items():
@@ -55,9 +36,11 @@ def final_report(window_opened, time_spent):
for x, y in report.items():
if to.convert_into_sec(y) == i:
sorted_report.update({x:y})
-
+ del report
+ del sorted_values
return sorted_report
+
def get_sunday_of_week(week):
year = int(week[4:])
week = int(week[1:3])
@@ -84,28 +67,29 @@ def weekly_logs(week = str(os.popen('''date +"W%V-%Y"''').read()[0:-1])):
filename = "/home/"+user+"/.cache/Watcher/Analysis/"+week+".csv"
with open(filename, "w") as csvfile:
csvwriter = csv.writer(csvfile, delimiter='\t')
- #csvwriter.writerow(["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"])
if os.popen('''date +"W%V-%Y"''').read()[0:-1] == week:
dates = week_dates()
else:
dates = week_dates(get_sunday_of_week(week))
- window_opened = list()
- time_spent = list()
for i in dates:
- window_opened, time_spent = extract_data(i)
Total_screen_time = "00:00:00"
- for x, y in final_report(window_opened, time_spent).items():
+ for x, y in final_report(i).items():
Total_screen_time = to.time_addition(y, Total_screen_time)
-
csvwriter.writerow([weekday_from_date(i), Total_screen_time])
+ all_data = dict()
for i in dates:
- x, y = extract_data(str(i))
- window_opened += x
- time_spent += y
- for x, y in final_report(window_opened, time_spent).items():
+ for x, y in final_report(i).items():
+ usage = all_data.get(x)
+ if usage == None:
+ usage = "00:00:00"
+ y = to.time_addition(usage, y)
+ all_data.update({x:y})
+
+ all_data = sort_data(all_data)
+ for x, y in all_data.items():
csvwriter.writerow([y, x])
#testing