Skip to content

Commit

Permalink
fix: output all + top 3 top-level categories in checkin (instead of h…
Browse files Browse the repository at this point in the history
…ardcoded)
  • Loading branch information
ErikBjare committed Nov 30, 2023
1 parent c640ee3 commit de461a9
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions aw_notify/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _cache_ttl(*args, **kwargs) -> T:


@cache_ttl(60)
def get_time(date=None) -> dict[str, timedelta]:
def get_time(date=None, top_level_only=True) -> dict[str, timedelta]:
"""
Returns a dict with the time spent today (or for `date`) for each category.
"""
Expand Down Expand Up @@ -94,8 +94,6 @@ def get_time(date=None) -> dict[str, timedelta]:
res = aw.query(query, timeperiods)[0]
res["cat_events"] += [{"data": {"$category": ["All"]}, "duration": res["duration"]}]

top_level_only = True

cat_time: dict[str, timedelta] = defaultdict(timedelta)
for e in res["cat_events"]:
if top_level_only:
Expand Down Expand Up @@ -319,17 +317,15 @@ def send_checkin(title="Time today", date=None):
Sends a summary notification of the day.
Meant to be sent at a particular time, like at the end of a working day (e.g. 5pm).
"""
# TODO: make configurable which categories to show
categories = list(set(["All", "Work", "Uncategorized"]))
cat_time = get_time(date=date)
time_spent = [cat_time.get(c, timedelta()) for c in categories]

# get the 4 top categories by time spent.
top_categories = [
(c, to_hms(t))
for c, t in sorted(
zip(categories, time_spent), key=lambda x: x[1], reverse=True
)
for c, t in sorted(cat_time.items(), key=lambda x: x[1], reverse=True)
if t > 0.02 * cat_time["All"]
]
][:4]

msg = ""
msg += "\n".join(f"- {c}: {t}" for c, t in top_categories)
if msg:
Expand Down

0 comments on commit de461a9

Please sign in to comment.