From 75e0e3a432c91f3e2a6dda83694dddd5831e9f11 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 4 Apr 2023 12:26:20 +0200 Subject: ... --- overlays/worktime/worktime/__main__.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py index 8ee67c6d..fa357d09 100755 --- a/overlays/worktime/worktime/__main__.py +++ b/overlays/worktime/worktime/__main__.py @@ -597,7 +597,14 @@ def leave(year, table, **args): for year, offset in leave_budget.items(): leave_days = sorted([day for day in worktime.leave_days if day.year == year]) would_be_workdays = [day for day in days if day.year == year and worktime.would_be_workday(day)] - table_data += [[year, offset, f"{len(leave_days)}/{len(list(would_be_workdays))}", ','.join(map(lambda d: d.strftime('%m-%d'), leave_days))]] + groups = [] + for _, group in groupby(enumerate(leave_days), lambda kv: kv[0] - worktime.ordinal_workday(kv[1])): + group = list(map(lambda kv: kv[1], group)) + if len(group) > 1: + groups.append(group[0].strftime('%m-%d') + '--' + group[-1].strftime('%m-%d')) + else: + groups.append(group[0].strftime('%m-%d')) + table_data += [[year, offset, f"{len(leave_days)}/{len(list(would_be_workdays))}", ','.join(groups)]] print(tabulate(table_data, tablefmt="plain")) else: print(leave_budget[year if year else def_year]) @@ -674,15 +681,18 @@ def classification(classification_name, table, **args): else: table_data = [] for year in sorted(year_classification.keys()): - row_data = [year] - count_classified = len([1 for day, classified in year_classification[year].items() if classified]) + row_data = [year, year_offset[year]] + + classified = [day for day, classified in year_classification[year].items() if classified] count_would_be_workdays = len([1 for day in days if day.year == year and worktime.would_be_workday(day) and day not in worktime.leave_days]) - row_data.append(year_offset[year]) if len(year_classification[year]) != count_would_be_workdays: - row_data.append(f"{count_classified}/{len(year_classification[year])}/{count_would_be_workdays}") + row_data.append(f"{len(classified)}/{len(year_classification[year])}/{count_would_be_workdays}") else: - row_data.append(f"{count_classified}/{len(year_classification[year])}") - row_data.append(','.join(sorted([day.strftime('%m-%d') for day, classified in year_classification[year].items() if classified]))) + row_data.append(f"{len(classified)}/{len(year_classification[year])}") + + groups = map(lambda kv: kv[1], groupby(classified, lambda v: (v.isocalendar().year, v.isocalendar().week))) + row_data.append(', '.join(map(lambda group: ','.join(map(lambda day: day.strftime('%m-%d'), sorted(group))), groups))) + table_data.append(row_data) print(tabulate(table_data, tablefmt="plain")) -- cgit v1.2.3