group similar entries

This commit is contained in:
bain 2023-03-28 19:47:38 +02:00
parent 00bcc828f4
commit e173325758
Signed by: bain
GPG key ID: 31F0F25E3BED0B9B

View file

@ -124,8 +124,9 @@ def get_toggl_entries(
None,
)
# construct a dict of d["project name"] = [[date, description, duration (hours), wage], ...]
out = defaultdict(list)
# construct a dict of entries d["project name"][(date, description)] = duration
# entries on the same day with the same description get aggregated together
packed = defaultdict(lambda: defaultdict(int))
for entry in reversed(entries):
if not valid_entry(entry):
continue
@ -134,14 +135,15 @@ def get_toggl_entries(
if end <= last_edit:
continue # get better accuracy than toggl lets us in their requests
out[projects[entry["project_id"]]].append(
[
start.astimezone().strftime("%-d. %-m. %Y"),
entry["description"],
round(entry["duration"] / 60 / 60, 2),
HOURLY_WAGE,
]
)
packed[projects[entry["project_id"]]][(start.astimezone().strftime("%-d. %-m. %Y"), entry["description"])] += entry["duration"] / 60 / 60
# unpack into the final output of d["project name"] = [[date, description, duration, hourly_wage], ...]
out = {}
for project, entries in packed.items():
unpacked = []
for metadata, duration in entries.items():
unpacked.append([*metadata, round(duration, 2), HOURLY_WAGE])
out[project] = unpacked
return out, last_entry