summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2023-04-04 12:26:20 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2023-04-04 12:26:20 +0200
commit75e0e3a432c91f3e2a6dda83694dddd5831e9f11 (patch)
tree2f70fe5953cb1255a862c3b4130721f83c5baf28
parent581fd2dd4ee6c1838279a476d887bbb5b203faf0 (diff)
downloadnixos-75e0e3a432c91f3e2a6dda83694dddd5831e9f11.tar
nixos-75e0e3a432c91f3e2a6dda83694dddd5831e9f11.tar.gz
nixos-75e0e3a432c91f3e2a6dda83694dddd5831e9f11.tar.bz2
nixos-75e0e3a432c91f3e2a6dda83694dddd5831e9f11.tar.xz
nixos-75e0e3a432c91f3e2a6dda83694dddd5831e9f11.zip
...
-rwxr-xr-xoverlays/worktime/worktime/__main__.py24
1 files 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):
597 for year, offset in leave_budget.items(): 597 for year, offset in leave_budget.items():
598 leave_days = sorted([day for day in worktime.leave_days if day.year == year]) 598 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)] 599 would_be_workdays = [day for day in days if day.year == year and worktime.would_be_workday(day)]
600 table_data += [[year, offset, f"{len(leave_days)}/{len(list(would_be_workdays))}", ','.join(map(lambda d: d.strftime('%m-%d'), leave_days))]] 600 groups = []
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)]]
601 print(tabulate(table_data, tablefmt="plain")) 608 print(tabulate(table_data, tablefmt="plain"))
602 else: 609 else:
603 print(leave_budget[year if year else def_year]) 610 print(leave_budget[year if year else def_year])
@@ -674,15 +681,18 @@ def classification(classification_name, table, **args):
674 else: 681 else:
675 table_data = [] 682 table_data = []
676 for year in sorted(year_classification.keys()): 683 for year in sorted(year_classification.keys()):
677 row_data = [year] 684 row_data = [year, year_offset[year]]
678 count_classified = len([1 for day, classified in year_classification[year].items() if classified]) 685
686 classified = [day for day, classified in year_classification[year].items() if classified]
679 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]) 687 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])
680 row_data.append(year_offset[year])
681 if len(year_classification[year]) != count_would_be_workdays: 688 if len(year_classification[year]) != count_would_be_workdays:
682 row_data.append(f"{count_classified}/{len(year_classification[year])}/{count_would_be_workdays}") 689 row_data.append(f"{len(classified)}/{len(year_classification[year])}/{count_would_be_workdays}")
683 else: 690 else:
684 row_data.append(f"{count_classified}/{len(year_classification[year])}") 691 row_data.append(f"{len(classified)}/{len(year_classification[year])}")
685 row_data.append(','.join(sorted([day.strftime('%m-%d') for day, classified in year_classification[year].items() if classified]))) 692
693 groups = map(lambda kv: kv[1], groupby(classified, lambda v: (v.isocalendar().year, v.isocalendar().week)))
694 row_data.append(', '.join(map(lambda group: ','.join(map(lambda day: day.strftime('%m-%d'), sorted(group))), groups)))
695
686 table_data.append(row_data) 696 table_data.append(row_data)
687 print(tabulate(table_data, tablefmt="plain")) 697 print(tabulate(table_data, tablefmt="plain"))
688 698