summaryrefslogtreecommitdiff
path: root/overlays
diff options
context:
space:
mode:
authorGregor Kleen <gkleen@yggdrasil.li>2023-04-04 17:14:12 +0200
committerGregor Kleen <gkleen@yggdrasil.li>2023-04-04 17:14:12 +0200
commit9c67ce4623ae1f2bf9a9d71de781c12054c1001c (patch)
treebf2eb5be8117a6ae158a0a713c943788ace97bad /overlays
parent58582ab735a3c88275b4ed68cb6d19f46eae1b95 (diff)
downloadnixos-9c67ce4623ae1f2bf9a9d71de781c12054c1001c.tar
nixos-9c67ce4623ae1f2bf9a9d71de781c12054c1001c.tar.gz
nixos-9c67ce4623ae1f2bf9a9d71de781c12054c1001c.tar.bz2
nixos-9c67ce4623ae1f2bf9a9d71de781c12054c1001c.tar.xz
nixos-9c67ce4623ae1f2bf9a9d71de781c12054c1001c.zip
...
Diffstat (limited to 'overlays')
-rwxr-xr-xoverlays/worktime/worktime/__main__.py32
1 files changed, 20 insertions, 12 deletions
diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py
index 19737805..84c8a8e2 100755
--- a/overlays/worktime/worktime/__main__.py
+++ b/overlays/worktime/worktime/__main__.py
@@ -442,7 +442,7 @@ def format_days(worktime, days, date_format=None):
442 ))) 442 )))
443 def format_group(group): 443 def format_group(group):
444 if len(group) > 1: 444 if len(group) > 1:
445 return group[0].strftime(date_format) + '--' + group[-1].strftime(date_format) 445 return group[0].strftime(date_format) + '' + group[-1].strftime(date_format)
446 else: 446 else:
447 return group[0].strftime(date_format) 447 return group[0].strftime(date_format)
448 return ', '.join(map(lambda group: ','.join(map(format_group, group)), groups)) 448 return ', '.join(map(lambda group: ','.join(map(format_group, group)), groups))
@@ -551,7 +551,7 @@ def diff(now, **args):
551 551
552 print(now.time_to_work - then.time_to_work) 552 print(now.time_to_work - then.time_to_work)
553 553
554def holidays(year, **args): 554def holidays(year, table_format, **args):
555 config = Worktime.config() 555 config = Worktime.config()
556 date_format = config.get("WORKTIME", {}).get("DateFormat", '%Y-%m-%d') 556 date_format = config.get("WORKTIME", {}).get("DateFormat", '%Y-%m-%d')
557 557
@@ -561,9 +561,9 @@ def holidays(year, **args):
561 for k, v in holidays.items(): 561 for k, v in holidays.items():
562 kstr = k.strftime(date_format) 562 kstr = k.strftime(date_format)
563 table_data += [[kstr, v]] 563 table_data += [[kstr, v]]
564 print(tabulate(table_data, tablefmt="plain")) 564 print(tabulate(table_data, tablefmt=table_format, headers=["Date", "Proportion"] if table_format != 'plain' else None))
565 565
566def leave(year, table, **args): 566def leave(year, table, table_format, **args):
567 def_year = datetime.now(tzlocal()).year 567 def_year = datetime.now(tzlocal()).year
568 worktime = Worktime(**dict(**args, end_datetime = datetime(year = (year if year else def_year) + 1, month = 1, day = 1, tzinfo=tzlocal()) - timedelta(microseconds=1))) 568 worktime = Worktime(**dict(**args, end_datetime = datetime(year = (year if year else def_year) + 1, month = 1, day = 1, tzinfo=tzlocal()) - timedelta(microseconds=1)))
569 config = Worktime.config() 569 config = Worktime.config()
@@ -611,22 +611,22 @@ def leave(year, table, **args):
611 611
612 next_count = count + len(group) 612 next_count = count + len(group)
613 if len(group) > 1: 613 if len(group) > 1:
614 table_data.append([count, group[0].strftime('%m-%d') + '--' + group[-1].strftime('%m-%d'), len(group), sum(year_leave_budget.values())]) 614 table_data.append([count, group[0].strftime('%m–%d') + '…' + group[-1].strftime('%m–%d'), len(group), sum(year_leave_budget.values())])
615 else: 615 else:
616 table_data.append([count, group[0].strftime('%m-%d'), len(group), sum(year_leave_budget.values())]) 616 table_data.append([count, group[0].strftime('%m%d'), len(group), sum(year_leave_budget.values())])
617 count = next_count 617 count = next_count
618 print(tabulate(table_data, tablefmt="plain")) 618 print(tabulate(table_data, tablefmt=table_format, headers=["Running Count", "Leave Days", "# of Leave Days", "# of Leave Days Left"] if table_format != 'plain' else None))
619 elif table: 619 elif table:
620 table_data = [] 620 table_data = []
621 for year, offset in leave_budget.items(): 621 for year, offset in leave_budget.items():
622 leave_days = sorted([day for day in worktime.leave_days if day.year == year]) 622 leave_days = sorted([day for day in worktime.leave_days if day.year == year])
623 would_be_workdays = [day for day in days if day.year == year and worktime.would_be_workday(day)] 623 would_be_workdays = [day for day in days if day.year == year and worktime.would_be_workday(day)]
624 table_data += [[year, offset, f"{len(leave_days)}/{len(list(would_be_workdays))}", format_days(worktime, leave_days, date_format='%m-%d')]] 624 table_data += [[year, offset, f"{len(leave_days)}/{len(list(would_be_workdays))}", format_days(worktime, leave_days, date_format='%m–%d')]]
625 print(tabulate(table_data, tablefmt="plain")) 625 print(tabulate(table_data, tablefmt=table_format, headers=["Year", "Δ of Leave Days", " # of Leave Days\n/ Pot. Workdays", "Leave Days"] if table_format != 'plain' else None))
626 else: 626 else:
627 print(leave_budget[year if year else def_year]) 627 print(leave_budget[year if year else def_year])
628 628
629def classification(classification_name, table, **args): 629def classification(classification_name, table, table_format, **args):
630 worktime = Worktime(**args) 630 worktime = Worktime(**args)
631 config = Worktime.config() 631 config = Worktime.config()
632 date_format = config.get("WORKTIME", {}).get("DateFormat", '%Y-%m-%d') 632 date_format = config.get("WORKTIME", {}).get("DateFormat", '%Y-%m-%d')
@@ -719,10 +719,15 @@ def classification(classification_name, table, **args):
719 else: 719 else:
720 row_data.append(f"{len(classified)}/{len(year_classification[year])}") 720 row_data.append(f"{len(classified)}/{len(year_classification[year])}")
721 721
722 row_data.append(format_days(worktime, classified, date_format='%m-%d')) 722 row_data.append(format_days(worktime, classified, date_format='%m%d'))
723 723
724 table_data.append(row_data) 724 table_data.append(row_data)
725 print(tabulate(table_data, tablefmt="plain")) 725 print(tabulate(
726 table_data,
727 tablefmt=table_format,
728 headers=["Year", "Running Difference", f" # of {classification_name.title()} Days\n / # of Classified Days\n(/ # of Pot. Classifiable Days)", f"{classification_name.title()} Days"] if table_format != 'plain' else None,
729 maxcolwidths=[None, None, None, 50] if table_format != 'plain' else None
730 ))
726 731
727def main(): 732def main():
728 config = Worktime.config() 733 config = Worktime.config()
@@ -739,15 +744,18 @@ def main():
739 diff_parser = subparsers.add_parser('diff') 744 diff_parser = subparsers.add_parser('diff')
740 diff_parser.set_defaults(cmd = diff) 745 diff_parser.set_defaults(cmd = diff)
741 holidays_parser = subparsers.add_parser('holidays') 746 holidays_parser = subparsers.add_parser('holidays')
747 holidays_parser.add_argument('--table-format', dest='table_format', type=str, default='fancy_grid')
742 holidays_parser.add_argument('year', metavar = 'YEAR', type = int, help = 'Year to evaluate holidays for (default: current year)', default = datetime.now(tzlocal()).year, nargs='?') 748 holidays_parser.add_argument('year', metavar = 'YEAR', type = int, help = 'Year to evaluate holidays for (default: current year)', default = datetime.now(tzlocal()).year, nargs='?')
743 holidays_parser.set_defaults(cmd = holidays) 749 holidays_parser.set_defaults(cmd = holidays)
744 leave_parser = subparsers.add_parser('leave') 750 leave_parser = subparsers.add_parser('leave')
745 leave_parser.add_argument('year', metavar = 'YEAR', type = int, help = 'Year to evaluate leave days for (default: current year)', default = None, nargs='?') 751 leave_parser.add_argument('year', metavar = 'YEAR', type = int, help = 'Year to evaluate leave days for (default: current year)', default = None, nargs='?')
746 leave_parser.add_argument('--table', action = 'store_true') 752 leave_parser.add_argument('--table', action = 'store_true')
753 leave_parser.add_argument('--table-format', dest='table_format', type=str, default='fancy_grid')
747 leave_parser.set_defaults(cmd = leave) 754 leave_parser.set_defaults(cmd = leave)
748 for classification_name in config.get('day-classification', {}).keys(): 755 for classification_name in config.get('day-classification', {}).keys():
749 classification_parser = subparsers.add_parser(classification_name) 756 classification_parser = subparsers.add_parser(classification_name)
750 classification_parser.add_argument('--table', action = 'store_true') 757 classification_parser.add_argument('--table', action = 'store_true')
758 classification_parser.add_argument('--table-format', dest='table_format', type=str, default='fancy_grid')
751 classification_parser.set_defaults(cmd = partial(classification, classification_name=classification_name)) 759 classification_parser.set_defaults(cmd = partial(classification, classification_name=classification_name))
752 args = parser.parse_args() 760 args = parser.parse_args()
753 761