Commit 547b09d5 authored by Thomas Lotze's avatar Thomas Lotze

re #19: fix accessing subtotals in report

parent 9170e613
......@@ -6,6 +6,15 @@ from gitlab.v4.objects import ProjectMergeRequest
def report(entries):
"""Aggregate an unordered sequence of time tracking entries into a report.
# When aggregating things by item, we cannot simply use the item as a dict
# key: Both issues and merge requests just use their iid as a hash and
# those number sets do overlap, so mixing them as keys in the same dict
# potentially loses data. Therefore, we use a tuple as item key, including
# an indicator of the item's type. At the same time we take a short cut
# and choose the tuple such that it makes for a meaningful sort key.
# Projects don't have this problem but treating them similarly rather than
# using a key parameter when sorting makes for simpler sorting of dict
# items and some kind of consistency. Not sure this is good style, though.
times = defaultdict(lambda: defaultdict(lambda: defaultdict(list)))
totals_by_project = defaultdict(float)
......@@ -24,15 +33,17 @@ def report(entries):
total = sum(totals_by_project.values())
for (_, project), times_by_item in sorted(times.items()):
for project_key, times_by_item in sorted(times.items()):
project = project_key[-1]
print('{}: {:.2f}'.format(
project.name_with_namespace, totals_by_project[project]))
project.name_with_namespace, totals_by_project[project_key]))
for (_, _, item), times_by_author in sorted(times_by_item.items()):
for item_key, times_by_author in sorted(times_by_item.items()):
item = item_key[-1]
print('{}{}: {:.2f} ({})'.format(
4*' ',
for author, time_log in sorted(times_by_author.items()):
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment