diff options
author | 2022-03-12 22:38:01 +0530 | |
---|---|---|
committer | 2022-03-12 22:38:01 +0530 | |
commit | 6352e4288ab5489c57ead68b97e3fc1f60bc6097 (patch) | |
tree | 3c0d76c049a0dfbca55d3917ce824510a72cf321 /src/Watcher/week_analysis.py | |
parent | 5ff9b08a4230210572c4b02dfc784c31c1986dea (diff) | |
download | shopno-os-log-sync-6352e4288ab5489c57ead68b97e3fc1f60bc6097.tar.gz shopno-os-log-sync-6352e4288ab5489c57ead68b97e3fc1f60bc6097.zip |
completed week overview feature
Diffstat (limited to 'src/Watcher/week_analysis.py')
-rwxr-xr-x | src/Watcher/week_analysis.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/Watcher/week_analysis.py b/src/Watcher/week_analysis.py new file mode 100755 index 0000000..1f064b2 --- /dev/null +++ b/src/Watcher/week_analysis.py @@ -0,0 +1,46 @@ +import os +import csv +import datetime +import report_creation as rc +import time_operations as to + +def get_dates(): + theday = datetime.date.today() + weekday = theday.isoweekday() - 1 + # The start of the week + start = theday - datetime.timedelta(days=weekday) + # build a simple range + dates = [start + datetime.timedelta(days=d) for d in range(weekday+1)] + dates = [str(d) for d in dates] + + return dates + +def weekday_from_date(date): + day = os.popen('''date -d "'''+ date + '''" +%a''').read() + return day[0:-1] + +W_Y = os.popen('''date +"W%U-%Y"''').read()[0:-1] +user = os.getlogin() +filename = "/home/"+user+"/.cache/Watcher/Analysis/"+W_Y+".csv" +with open(filename, "w") as csvfile: + csvwriter = csv.writer(csvfile, delimiter='\t') + #csvwriter.writerow(["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]) + dates = get_dates() + + window_opened = list() + time_spent = list() + for i in dates: + window_opened, time_spent = rc.extract_data(i) + Total_screen_time = "00:00:00" + for x, y in rc.final_report(window_opened, time_spent).items(): + Total_screen_time = to.time_addition(y, Total_screen_time) + + csvwriter.writerow([weekday_from_date(i), Total_screen_time]) + + for i in dates: + x, y = rc.extract_data(str(i)) + window_opened += x # smth is wrong here + time_spent += y + for x, y in rc.final_report(window_opened, time_spent).items(): + csvwriter.writerow([y, x]) + |