From b2d3ccf45e4fd4f67ad9fc41538ec2d9a7423178 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 4 Apr 2023 16:18:33 +0200 Subject: ... --- overlays/worktime/worktime/__main__.py | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'overlays') diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py index fa357d09..c91d73aa 100755 --- a/overlays/worktime/worktime/__main__.py +++ b/overlays/worktime/worktime/__main__.py @@ -424,6 +424,26 @@ class Worktime(object): self.time_worked += api.get_billable_hours(self.start_date, self.now, rounding = config.get("WORKTIME", {}).get("rounding", True)) +def format_days(worktime, days, date_format=None): + if not date_format: + config = Worktime.config() + date_format = config.get("WORKTIME", {}).get("DateFormat", '%Y-%m-%d') + + groups = list(map(lambda kv: list(kv[1]), groupby( + map( + lambda kv: list(map(lambda t: t[1], kv[1])), + groupby(enumerate(days), lambda kv: kv[0] - worktime.ordinal_workday(kv[1])) + ), + lambda days: frozenset(map(lambda day: (day.isocalendar().year, day.isocalendar().week), days)) + ))) + def format_group(group): + if len(group) > 1: + return group[0].strftime(date_format) + '--' + group[-1].strftime(date_format) + else: + return group[0].strftime(date_format) + return ', '.join(map(lambda group: ','.join(map(format_group, group)), groups)) + + def worktime(**args): worktime = Worktime(**args) @@ -597,14 +617,7 @@ 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)] - 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)]] + table_data += [[year, offset, f"{len(leave_days)}/{len(list(would_be_workdays))}", format_days(worktime, leave_days, date_format='%m-%d')]] print(tabulate(table_data, tablefmt="plain")) else: print(leave_budget[year if year else def_year]) @@ -690,8 +703,7 @@ def classification(classification_name, table, **args): else: 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))) + row_data.append(format_days(worktime, classified, date_format='%m-%d')) table_data.append(row_data) print(tabulate(table_data, tablefmt="plain")) -- cgit v1.2.3