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