Last active
February 16, 2024 16:29
-
-
Save ShyftXero/9d1cccdecd61a965db27016f300f18a7 to your computer and use it in GitHub Desktop.
Revisions
-
ShyftXero revised this gist
Feb 16, 2024 . No changes.There are no files selected for viewing
-
ShyftXero revised this gist
Feb 15, 2024 . 1 changed file with 11 additions and 12 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,7 +5,7 @@ # relies on https://github.com/ActivityWatch/activitywatch/ "Records what you do so that you can know how you've spent your time." # grown from https://github.com/ActivityWatch/aw-client/blob/master/examples/time_spent_today.py import sys from datetime import date, datetime, time, timedelta, timezone from rich import print import socket from typer import Typer @@ -22,17 +22,15 @@ def win(NUM_DAYS:int=7, EVENING_START:int=17, ACTIVITY_THRESHOLD:int=30, verbose ACTIVITY_THRESHOLD = 30 # min number of seconds of non-afk activity to consider in the calculation of being "at your computer" """ # Set this to your AFK bucket bucket_id = f"aw-watcher-afk_{socket.gethostname()}" td = timedelta(days=NUM_DAYS) daystart = datetime.combine(datetime.now().date() - td, time()) dayend = daystart + td + timedelta(days=1) # to account for today as well min_usage_thresh_td = timedelta(seconds=ACTIVITY_THRESHOLD) awc = aw_client.ActivityWatchClient("afterwork_tracking") raw_events = awc.get_events(bucket_id, start=daystart, end=dayend) raw_events = sorted(raw_events, key=lambda x: x.timestamp.astimezone()) @@ -41,7 +39,7 @@ def win(NUM_DAYS:int=7, EVENING_START:int=17, ACTIVITY_THRESHOLD:int=30, verbose after5_events = list() for e in raw_events: if e.duration < min_usage_thresh_td: continue # skip this event if its duration is less than the threshold. ts = e.timestamp.astimezone() # convert to central time for conginitve ease @@ -64,17 +62,18 @@ def win(NUM_DAYS:int=7, EVENING_START:int=17, ACTIVITY_THRESHOLD:int=30, verbose after5_events_durations = [e.duration for e in after5_events] total_duration = sum(after5_events_durations, timedelta()) print(f"[yellow]{'='*25}[/yellow]") print('[yellow]Daily Summaries[/yellow]') print(f"[yellow]{'='*25}[/yellow]") for k,verbose in daily_sums.items(): print(f'{k} - time spent in evening {verbose}') print(f"[green]{'='*25}[/green]") print('[green]Stats[/green]') print(f"[green]{'='*25}[/green]") print(f"Total time spent on computer after {timedelta(hours=EVENING_START)} in last {NUM_DAYS} days: {total_duration} (HH:MM:SS) where each instance of usage is at least {min_usage_thresh_td} long") print(f'Average amount of time per non-afk instance {total_duration/len(after5_events_durations)}') if __name__ == "__main__": app() -
ShyftXero revised this gist
Feb 15, 2024 . 1 changed file with 14 additions and 8 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -15,11 +15,11 @@ app = Typer() @app.command() def win(NUM_DAYS:int=7, EVENING_START:int=17, ACTIVITY_THRESHOLD:int=30, verbose:bool=False): """ NUM_DAYS = 7 # look back at the last week EVENING_START = 17 # 5pm ACTIVITY_THRESHOLD = 30 # min number of seconds of non-afk activity to consider in the calculation of being "at your computer" """ bucket_id = f"aw-watcher-afk_{socket.gethostname()}" @@ -30,6 +30,7 @@ def win(NUM_DAYS:int=7, EVENING_START:int=17, ACTIVITY_THRESHOLD:int=60): td = timedelta(days=NUM_DAYS) daystart = datetime.combine(datetime.now().date() - td, time()) dayend = daystart + td min_usage_thresh_td = timedelta(seconds=ACTIVITY_THRESHOLD) awc = aw_client.ActivityWatchClient("testclient") raw_events = awc.get_events(bucket_id, start=daystart, end=dayend) @@ -39,18 +40,23 @@ def win(NUM_DAYS:int=7, EVENING_START:int=17, ACTIVITY_THRESHOLD:int=60): daily_sums = dict() after5_events = list() for e in raw_events: if e.duration < min_usage_thresh_td: continue # skip this event if it's less than the threshold. ts = e.timestamp.astimezone() # convert to central time for conginitve ease # after 5pm and active form more than 60 seconds by default if e.data["status"] == "not-afk" and ts.hour >= EVENING_START: after5_events.append(e) # breakpoint() if ts.date() not in daily_sums.keys(): daily_sums[ts.date()] = e.duration if verbose: print('adding new ', e.duration, 'to', ts.date(), 'initiated at', ts,'event id=', e.id) else: if verbose: print('adding additional ', e.duration, 'to', ts.date(), 'initiated at', ts,'event id=', e.id) # print(e.timestamp,'duration', e.duration) daily_sums[ts.date()] += e.duration @@ -60,11 +66,11 @@ def win(NUM_DAYS:int=7, EVENING_START:int=17, ACTIVITY_THRESHOLD:int=60): total_duration = sum(after5_events_durations, timedelta()) print('[yellow]Daily summaries[/yellow]') for k,verbose in daily_sums.items(): print(f'{k} - time spent in evening {verbose}') print('[green]Stats[/green]') print(f"Total time spent on computer after 5pm in last {NUM_DAYS} days: {total_duration} (HH:MM:SS) where each instance of usage is at least {min_usage_thresh_td} long") print(f'Average amount of time per non-afk instance {total_duration/len(after5_events_durations)}') -
ShyftXero revised this gist
Feb 15, 2024 . 1 changed file with 8 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -32,17 +32,17 @@ def win(NUM_DAYS:int=7, EVENING_START:int=17, ACTIVITY_THRESHOLD:int=60): dayend = daystart + td awc = aw_client.ActivityWatchClient("testclient") raw_events = awc.get_events(bucket_id, start=daystart, end=dayend) raw_events = sorted(raw_events, key=lambda x: x.timestamp.astimezone()) # breakpoint() daily_sums = dict() after5_events = list() for e in raw_events: ts = e.timestamp.astimezone() # convert to central time for conginitve ease # after 5pm and active form more than 60 seconds by default if e.data["status"] == "not-afk" and ts.hour >= EVENING_START:# and e.duration >= timedelta(seconds=ACTIVITY_THRESHOLD): after5_events.append(e) # breakpoint() @@ -55,16 +55,15 @@ def win(NUM_DAYS:int=7, EVENING_START:int=17, ACTIVITY_THRESHOLD:int=60): daily_sums[ts.date()] += e.duration # print(e.timestamp,'duration', e.duration) after5_events_durations = [e.duration for e in after5_events] total_duration = sum(after5_events_durations, timedelta()) print('[yellow]Daily summaries[/yellow]') for k,v in daily_sums.items(): print(f'{k} - time spent in evening {v}') print('[green]Stats[/green]') print(f"Total time spent on computer after 5pm in last {NUM_DAYS} days: {total_duration}") print(f'Average amount of time per non-afk instance {total_duration/len(after5_events_durations)}') -
ShyftXero revised this gist
Feb 15, 2024 . 1 changed file with 18 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,20 +8,24 @@ from datetime import datetime, time, timedelta, timezone from rich import print import socket from typer import Typer import aw_client app = Typer() @app.command() def win(NUM_DAYS:int=7, EVENING_START:int=17, ACTIVITY_THRESHOLD:int=60): """ NUM_DAYS = 7 # look back at the last week EVENING_START = 17 # 5pm ACTIVITY_THRESHOLD = 60 # min number of seconds of non-afk activity to consider in the calculation of being "at your computer" """ bucket_id = f"aw-watcher-afk_{socket.gethostname()}" td = timedelta(days=NUM_DAYS) daystart = datetime.combine(datetime.now().date() - td, time()) @@ -38,7 +42,7 @@ ts = e.timestamp.astimezone() # convert to central time for conginitve ease # after 5pm and active form more than 60 seconds by default if e.data["status"] == "not-afk" and ts.hour >= EVENING_START and e.duration >= timedelta(seconds=ACTIVITY_THRESHOLD): after5_events.append(e) # breakpoint() @@ -64,3 +68,8 @@ print(f"Total time spent on computer after 5pm in last {NUM_DAYS} days: {total_duration}") print(f'Average amount of time per non-afk instance {total_duration/len(after5_events_durations)}') if __name__ == "__main__": # Set this to your AFK bucket app() -
ShyftXero created this gist
Feb 15, 2024 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ # 20240215 # shyft # script to prove my wife wrong about how much time I'm spending at my computer in the eventing. # use with caution... may not be worth it to you... # relies on https://github.com/ActivityWatch/activitywatch/ "Records what you do so that you can know how you've spent your time." # grown from https://github.com/ActivityWatch/aw-client/blob/master/examples/time_spent_today.py import sys from datetime import datetime, time, timedelta, timezone from rich import print import socket import aw_client if __name__ == "__main__": # Set this to your AFK bucket bucket_id = f"aw-watcher-afk_{socket.gethostname()}" TARGET_TIME = 17 # 5pm ACTIVITY_THRESHOLD = 60 # mini number of seconds of non-afk activity to consider in the calculation of being "at your computer" try: NUM_DAYS = int(sys.argv[1]) except IndexError as e: NUM_DAYS = 7 td = timedelta(days=NUM_DAYS) daystart = datetime.combine(datetime.now().date() - td, time()) dayend = daystart + td awc = aw_client.ActivityWatchClient("testclient") events = awc.get_events(bucket_id, start=daystart, end=dayend) events = sorted(events, key=lambda x: x.timestamp.astimezone()) # breakpoint() daily_sums = dict() after5_events = list() for e in events: ts = e.timestamp.astimezone() # convert to central time for conginitve ease # after 5pm and active form more than 60 seconds by default if e.data["status"] == "not-afk" and ts.hour >= TARGET_TIME and e.duration >= timedelta(seconds=ACTIVITY_THRESHOLD): after5_events.append(e) # breakpoint() if ts.date() not in daily_sums.keys(): daily_sums[ts.date()] = e.duration print('adding new ', e.duration, 'to', ts.date(), 'initiated at', ts,'event id=', e.id) else: print('adding additional ', e.duration, 'to', ts.date(), 'initiated at', ts,'event id=', e.id) # print(e.timestamp,'duration', e.duration) daily_sums[ts.date()] += e.duration # print(e.timestamp,'duration', e.duration) if e.id == 19390: print(e) after5_events_durations = [e.duration for e in after5_events] total_duration = sum(after5_events_durations, timedelta()) print('[yellow]Daily summarries[/yellow]') for k,v in daily_sums.items(): print(f'{k} - time spent {v}') print(f"Total time spent on computer after 5pm in last {NUM_DAYS} days: {total_duration}") print(f'Average amount of time per non-afk instance {total_duration/len(after5_events_durations)}')