@@ -62,7 +62,7 @@ def _cache_ttl(*args, **kwargs) -> T:
6262
6363
6464@cache_ttl (60 )
65- def get_time (date = None ) -> dict [str , timedelta ]:
65+ def get_time (date = None , top_level_only = True ) -> dict [str , timedelta ]:
6666 """
6767 Returns a dict with the time spent today (or for `date`) for each category.
6868 """
@@ -94,8 +94,6 @@ def get_time(date=None) -> dict[str, timedelta]:
9494 res = aw .query (query , timeperiods )[0 ]
9595 res ["cat_events" ] += [{"data" : {"$category" : ["All" ]}, "duration" : res ["duration" ]}]
9696
97- top_level_only = True
98-
9997 cat_time : dict [str , timedelta ] = defaultdict (timedelta )
10098 for e in res ["cat_events" ]:
10199 if top_level_only :
@@ -319,17 +317,15 @@ def send_checkin(title="Time today", date=None):
319317 Sends a summary notification of the day.
320318 Meant to be sent at a particular time, like at the end of a working day (e.g. 5pm).
321319 """
322- # TODO: make configurable which categories to show
323- categories = list (set (["All" , "Work" , "Uncategorized" ]))
324320 cat_time = get_time (date = date )
325- time_spent = [cat_time .get (c , timedelta ()) for c in categories ]
321+
322+ # get the 4 top categories by time spent.
326323 top_categories = [
327324 (c , to_hms (t ))
328- for c , t in sorted (
329- zip (categories , time_spent ), key = lambda x : x [1 ], reverse = True
330- )
325+ for c , t in sorted (cat_time .items (), key = lambda x : x [1 ], reverse = True )
331326 if t > 0.02 * cat_time ["All" ]
332- ]
327+ ][:4 ]
328+
333329 msg = ""
334330 msg += "\n " .join (f"- { c } : { t } " for c , t in top_categories )
335331 if msg :
0 commit comments