diff options
author | 2022-07-19 20:17:43 +0530 | |
---|---|---|
committer | 2022-07-19 20:17:43 +0530 | |
commit | e30c4bdfcae8b0e826c7a8a100526fe95845a933 (patch) | |
tree | 5bff08c93679a6bcbd5e9dd03fe9f221e60edfa8 /src/Watcher | |
parent | dbf80bf782b60db15e964b42bbe0d800fdad7626 (diff) | |
download | shopno-os-log-sync-e30c4bdfcae8b0e826c7a8a100526fe95845a933.tar.gz shopno-os-log-sync-e30c4bdfcae8b0e826c7a8a100526fe95845a933.zip |
Adding option of custom date and custom week to get users usage
Diffstat (limited to 'src/Watcher')
-rwxr-xr-x | src/Watcher/analysis.py | 30 | ||||
-rwxr-xr-x | src/Watcher/commands.py | 45 |
2 files changed, 53 insertions, 22 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") diff --git a/src/Watcher/commands.py b/src/Watcher/commands.py index dd1d2c4..5e6826e 100755 --- a/src/Watcher/commands.py +++ b/src/Watcher/commands.py @@ -34,20 +34,33 @@ class Color: def UNDERLINE(text): return '\033[4m' + text + '\033[0m' - -def daily_summary(): - date = get_date() +def daily_summary(date = get_date()): window_opened, time_spent = anls.extract_data(date) Total_screen_time = "00:00:00" for x,y in anls.final_report(window_opened, time_spent).items(): Total_screen_time = to.time_addition(y, Total_screen_time) - if len(to.format_time(Total_screen_time)) == 3: - print(Color.YELLOW("\n Today's Screen-Time\t\t ") + Color.BLUE(f'{to.format_time(Total_screen_time):>16}')) - elif len(to.format_time(Total_screen_time)) == 7: - print(Color.YELLOW("\n Today's Screen-Time\t\t ") + Color.BLUE(f'{to.format_time(Total_screen_time):>11}')) - elif len(to.format_time(Total_screen_time)) == 11: + if date == get_date(): + if len(to.format_time(Total_screen_time)) == 3: + print(Color.YELLOW("\n Today's Screen-Time\t\t ") + Color.BLUE(f'{to.format_time(Total_screen_time):>16}')) + elif len(to.format_time(Total_screen_time)) == 7: + print(Color.YELLOW("\n Today's Screen-Time\t\t ") + Color.BLUE(f'{to.format_time(Total_screen_time):>11}')) + elif len(to.format_time(Total_screen_time)) == 11: print(Color.YELLOW("\n Today's Screen-Time\t\t ") + Color.BLUE(to.format_time(Total_screen_time))) + elif date == os.popen("""date -d "1 day ago" '+%Y-%m-%d'""").read()[:-1]: + if len(to.format_time(Total_screen_time)) == 3: + print(Color.YELLOW("\n Yestarday's Screen-Time\t ") + Color.BLUE(f'{to.format_time(Total_screen_time):>16}')) + elif len(to.format_time(Total_screen_time)) == 7: + print(Color.YELLOW("\n Yestarday's Screen-Time\t ") + Color.BLUE(f'{to.format_time(Total_screen_time):>11}')) + elif len(to.format_time(Total_screen_time)) == 11: + print(Color.YELLOW("\n Yestarday's Screen-Time\t ") + Color.BLUE(to.format_time(Total_screen_time))) + else: + if len(to.format_time(Total_screen_time)) == 3: + print(Color.YELLOW("\n "+date+"'s Screen-Time\t ") + Color.BLUE(f'{to.format_time(Total_screen_time):>6}')) + elif len(to.format_time(Total_screen_time)) == 7: + print(Color.YELLOW("\n "+ date+ "'s Screen-Time\t ") + Color.BLUE(f'{to.format_time(Total_screen_time):>1}')) + elif len(to.format_time(Total_screen_time)) == 11: + print(Color.YELLOW("\n "+date+"'s Screen-Time\t ") + Color.BLUE(to.format_time(Total_screen_time))) print(" ────────────────────────────────────────────────") print(Color.RED(f'{" App Usages":>29}')) @@ -58,10 +71,9 @@ def daily_summary(): x = "Home-Screen" print(" " + Color.GREEN(f'{x:<22}') + '\t ',f'{to.format_time(y):>12}') -def week_summary(): - W_Y = os.popen('''date +"W%V-%Y"''').read()[0:-1] +def week_summary(week = os.popen('''date +"W%V-%Y"''').read()[:-1]): user = os.getlogin() - filename = "/home/"+user+"/.cache/Watcher/Analysis/"+W_Y+".csv" + filename = "/home/"+user+"/.cache/Watcher/Analysis/"+week+".csv" with open(filename, 'r') as file: csvreader = csv.reader(file, delimiter='\t') week_overview = dict() @@ -76,7 +88,12 @@ def week_summary(): for x, y in week_overview.items(): week_screen_time = to.time_addition(y, week_screen_time) - print(Color.PURPLE("\n Week's screen-time\t\t ") + Color.BLUE(to.format_time(week_screen_time))) + if week == os.popen('''date +"W%V-%Y"''').read()[:-1]: + print(Color.PURPLE("\n Week's screen-time\t\t ") + Color.BLUE(to.format_time(week_screen_time))) + else: + print(Color.PURPLE("\n "+week[1:3]+ "th week of\t ") + Color.BLUE(to.format_time(week_screen_time))) + print(Color.PURPLE(" "+week[4:] +" screen-time\t ")) + print(" ────────────────────────────────────────────────") for x, y in week_overview.items(): @@ -91,5 +108,7 @@ def week_summary(): x = "Home-Screen" print(" " + Color.GREEN(f'{x:<22}') + '\t ',f'{to.format_time(y):>12}') +#testing if __name__ == "__main__": - week_summary() + week_summary("W27-2022") + #daily_summary("2022-07-18") |