aboutsummaryrefslogtreecommitdiff
path: root/src/Watcher/analysis.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/Watcher/analysis.py')
-rwxr-xr-xsrc/Watcher/analysis.py30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/Watcher/analysis.py b/src/Watcher/analysis.py
index 87acda3..d37010c 100755
--- a/src/Watcher/analysis.py
+++ b/src/Watcher/analysis.py
@@ -58,30 +58,38 @@ def final_report(window_opened, time_spent):
return sorted_report
-# getting dates of the week for week summary
-def get_dates():
- theday = datetime.date.today()
+def get_sunday_of_week(week):
+ year = int(week[4:])
+ week = int(week[1:3])
+ first = datetime.date(year, 1, 1)
+ base = 1 if first.isocalendar()[1] == 1 else 8
+ return first + datetime.timedelta(days=base - first.isocalendar()[2] + 7 * (week - 1)) + datetime.timedelta(days=6.9)
+
+# getting dates of particular week for week summary
+def get_dates(theday=datetime.date.today()):
weekday = theday.isoweekday() - 1
- # The start of the week
+ # The start of the week (Monday)
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]
-def weeklly_logs():
- W_Y = os.popen('''date +"W%V-%Y"''').read()[0:-1]
+def weekly_logs(week = str(os.popen('''date +"w%v-%y"''').read()[0:-1])):
user = os.getlogin()
- filename = "/home/"+user+"/.cache/Watcher/Analysis/"+W_Y+".csv"
+ 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"])
- dates = get_dates()
+
+ if os.popen('''date +"w%v-%y"''').read()[0:-1] == week:
+ dates = get_date()
+ else:
+ dates = get_dates(get_sunday_of_week(week))
window_opened = list()
time_spent = list()
@@ -100,3 +108,7 @@ def weeklly_logs():
for x, y in final_report(window_opened, time_spent).items():
csvwriter.writerow([y, x])
+#testing
+if __name__ == "__main__":
+ print(get_dates(get_sunday_of_week("W27-2022")))
+ weekly_logs("W27-2022")