Commit 901f708b authored by Thomas Lotze's avatar Thomas Lotze
Browse files

re #12: redesign on-terminal project report

parent 90b08603
......@@ -5,27 +5,31 @@ def report(entries):
"""Aggregate an unordered sequence of time tracking entries into a report.
issues = defaultdict(lambda: defaultdict(set))
totals = defaultdict(lambda: defaultdict(float))
times = defaultdict(lambda: defaultdict(lambda: defaultdict(list)))
totals_by_project = defaultdict(float)
totals_by_issue = defaultdict(float)
for entry in entries:
project = entry['project'].name
issue = entry['issue']
issue = (issue.iid, issue)
author = entry['author']
totals[project][author] += entry['hours']
times[project][issue][author].append((entry['date'], entry['hours']))
totals_by_project[project] += entry['hours']
totals_by_issue[issue] += entry['hours']
totals_by_project = {project: sum(data.values())
for project, data in totals.items()}
total = sum(totals_by_project.values())
for project, issues_by_author in sorted(issues.items()):
for project, times_by_issue in sorted(times.items()):
print('{}: {:.2f}'.format(project, totals_by_project[project]))
totals_by_author = totals[project]
for author, issues in sorted(issues_by_author.items()):
issues = sorted(issues, key=lambda issue: issue.iid)
log = ', '.join('#{}'.format(issue.iid) for issue in issues)
print(' {}: {:.2f} ({})'.format(
author, totals_by_author[author], log))
for (_, issue), times_by_author in sorted(times_by_issue.items()):
print('{}#{}: {:.2f} ({})'.format(
4*' ', issue.iid, totals_by_issue[issue], issue.title))
for author, time_log in sorted(times_by_author.items()):
for date, hours in sorted(time_log):
print('{}{}: {:6.2f} ({})'.format(
8*' ', date, hours, author))
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