diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2023-04-04 16:18:33 +0200 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2023-04-04 16:18:33 +0200 |
commit | b2d3ccf45e4fd4f67ad9fc41538ec2d9a7423178 (patch) | |
tree | ea4b0df5ac80cb3df46f68a03fd5e0bfd05b003f /overlays/worktime | |
parent | 75e0e3a432c91f3e2a6dda83694dddd5831e9f11 (diff) | |
download | nixos-b2d3ccf45e4fd4f67ad9fc41538ec2d9a7423178.tar nixos-b2d3ccf45e4fd4f67ad9fc41538ec2d9a7423178.tar.gz nixos-b2d3ccf45e4fd4f67ad9fc41538ec2d9a7423178.tar.bz2 nixos-b2d3ccf45e4fd4f67ad9fc41538ec2d9a7423178.tar.xz nixos-b2d3ccf45e4fd4f67ad9fc41538ec2d9a7423178.zip |
...
Diffstat (limited to 'overlays/worktime')
-rwxr-xr-x | overlays/worktime/worktime/__main__.py | 32 |
1 files changed, 22 insertions, 10 deletions
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): | |||
424 | 424 | ||
425 | self.time_worked += api.get_billable_hours(self.start_date, self.now, rounding = config.get("WORKTIME", {}).get("rounding", True)) | 425 | self.time_worked += api.get_billable_hours(self.start_date, self.now, rounding = config.get("WORKTIME", {}).get("rounding", True)) |
426 | 426 | ||
427 | def format_days(worktime, days, date_format=None): | ||
428 | if not date_format: | ||
429 | config = Worktime.config() | ||
430 | date_format = config.get("WORKTIME", {}).get("DateFormat", '%Y-%m-%d') | ||
431 | |||
432 | groups = list(map(lambda kv: list(kv[1]), groupby( | ||
433 | map( | ||
434 | lambda kv: list(map(lambda t: t[1], kv[1])), | ||
435 | groupby(enumerate(days), lambda kv: kv[0] - worktime.ordinal_workday(kv[1])) | ||
436 | ), | ||
437 | lambda days: frozenset(map(lambda day: (day.isocalendar().year, day.isocalendar().week), days)) | ||
438 | ))) | ||
439 | def format_group(group): | ||
440 | if len(group) > 1: | ||
441 | return group[0].strftime(date_format) + '--' + group[-1].strftime(date_format) | ||
442 | else: | ||
443 | return group[0].strftime(date_format) | ||
444 | return ', '.join(map(lambda group: ','.join(map(format_group, group)), groups)) | ||
445 | |||
446 | |||
427 | def worktime(**args): | 447 | def worktime(**args): |
428 | worktime = Worktime(**args) | 448 | worktime = Worktime(**args) |
429 | 449 | ||
@@ -597,14 +617,7 @@ def leave(year, table, **args): | |||
597 | for year, offset in leave_budget.items(): | 617 | for year, offset in leave_budget.items(): |
598 | leave_days = sorted([day for day in worktime.leave_days if day.year == year]) | 618 | leave_days = sorted([day for day in worktime.leave_days if day.year == year]) |
599 | would_be_workdays = [day for day in days if day.year == year and worktime.would_be_workday(day)] | 619 | would_be_workdays = [day for day in days if day.year == year and worktime.would_be_workday(day)] |
600 | groups = [] | 620 | table_data += [[year, offset, f"{len(leave_days)}/{len(list(would_be_workdays))}", format_days(worktime, leave_days, date_format='%m-%d')]] |
601 | for _, group in groupby(enumerate(leave_days), lambda kv: kv[0] - worktime.ordinal_workday(kv[1])): | ||
602 | group = list(map(lambda kv: kv[1], group)) | ||
603 | if len(group) > 1: | ||
604 | groups.append(group[0].strftime('%m-%d') + '--' + group[-1].strftime('%m-%d')) | ||
605 | else: | ||
606 | groups.append(group[0].strftime('%m-%d')) | ||
607 | table_data += [[year, offset, f"{len(leave_days)}/{len(list(would_be_workdays))}", ','.join(groups)]] | ||
608 | print(tabulate(table_data, tablefmt="plain")) | 621 | print(tabulate(table_data, tablefmt="plain")) |
609 | else: | 622 | else: |
610 | print(leave_budget[year if year else def_year]) | 623 | print(leave_budget[year if year else def_year]) |
@@ -690,8 +703,7 @@ def classification(classification_name, table, **args): | |||
690 | else: | 703 | else: |
691 | row_data.append(f"{len(classified)}/{len(year_classification[year])}") | 704 | row_data.append(f"{len(classified)}/{len(year_classification[year])}") |
692 | 705 | ||
693 | groups = map(lambda kv: kv[1], groupby(classified, lambda v: (v.isocalendar().year, v.isocalendar().week))) | 706 | row_data.append(format_days(worktime, classified, date_format='%m-%d')) |
694 | row_data.append(', '.join(map(lambda group: ','.join(map(lambda day: day.strftime('%m-%d'), sorted(group))), groups))) | ||
695 | 707 | ||
696 | table_data.append(row_data) | 708 | table_data.append(row_data) |
697 | print(tabulate(table_data, tablefmt="plain")) | 709 | print(tabulate(table_data, tablefmt="plain")) |