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 | |
parent | 75e0e3a432c91f3e2a6dda83694dddd5831e9f11 (diff) | |
download | nixos-b2d3ccf45e4fd4f67ad9fc41538ec2d9a7423178.tar nixos-b2d3ccf45e4fd4f67ad9fc41538ec2d9a7423178.tar.gz nixos-b2d3ccf45e4fd4f67ad9fc41538ec2d9a7423178.tar.bz2 nixos-b2d3ccf45e4fd4f67ad9fc41538ec2d9a7423178.tar.xz nixos-b2d3ccf45e4fd4f67ad9fc41538ec2d9a7423178.zip |
...
-rw-r--r-- | flake.lock | 21 | ||||
-rw-r--r-- | flake.nix | 2 | ||||
-rwxr-xr-x | overlays/worktime/worktime/__main__.py | 32 |
3 files changed, 27 insertions, 28 deletions
@@ -25,7 +25,6 @@ | |||
25 | }, | 25 | }, |
26 | "ca-util": { | 26 | "ca-util": { |
27 | "inputs": { | 27 | "inputs": { |
28 | "leapseconds": "leapseconds", | ||
29 | "mach-nix": [ | 28 | "mach-nix": [ |
30 | "mach-nix" | 29 | "mach-nix" |
31 | ], | 30 | ], |
@@ -37,16 +36,16 @@ | |||
37 | ] | 36 | ] |
38 | }, | 37 | }, |
39 | "locked": { | 38 | "locked": { |
40 | "lastModified": 1680595497, | 39 | "lastModified": 1680609133, |
41 | "narHash": "sha256-JequPwdfjSFlX4XY5hz5CZ0KVPFJ99c85eacSyZ3VpU=", | 40 | "narHash": "sha256-1XpMskoVuRaQ0m+sezbsLXyrZjRNWNZTFbZyRN5R90w=", |
42 | "owner": "gkleen", | 41 | "owner": "gkleen", |
43 | "repo": "ca", | 42 | "repo": "ca", |
44 | "rev": "0634fa9f9a0e01e26d860ad02324c1afbd3a6c1f", | 43 | "rev": "2fec64bb3e069eb97ab7569c4e2e8cd761452f34", |
45 | "type": "gitlab" | 44 | "type": "gitlab" |
46 | }, | 45 | }, |
47 | "original": { | 46 | "original": { |
48 | "owner": "gkleen", | 47 | "owner": "gkleen", |
49 | "ref": "v2.0.2", | 48 | "ref": "v2.0.3", |
50 | "repo": "ca", | 49 | "repo": "ca", |
51 | "type": "gitlab" | 50 | "type": "gitlab" |
52 | } | 51 | } |
@@ -222,18 +221,6 @@ | |||
222 | "type": "github" | 221 | "type": "github" |
223 | } | 222 | } |
224 | }, | 223 | }, |
225 | "leapseconds": { | ||
226 | "flake": false, | ||
227 | "locked": { | ||
228 | "narHash": "sha256-Me9RN6L5jCnhL17bl4I77dRbG5r7/1n/BCUBDSt1R4A=", | ||
229 | "type": "file", | ||
230 | "url": "https://www.ietf.org/timezones/data/leap-seconds.list" | ||
231 | }, | ||
232 | "original": { | ||
233 | "type": "file", | ||
234 | "url": "https://www.ietf.org/timezones/data/leap-seconds.list" | ||
235 | } | ||
236 | }, | ||
237 | "mach-nix": { | 224 | "mach-nix": { |
238 | "inputs": { | 225 | "inputs": { |
239 | "flake-utils": [ | 226 | "flake-utils": [ |
@@ -111,7 +111,7 @@ | |||
111 | type = "gitlab"; | 111 | type = "gitlab"; |
112 | owner = "gkleen"; | 112 | owner = "gkleen"; |
113 | repo = "ca"; | 113 | repo = "ca"; |
114 | ref = "v2.0.2"; | 114 | ref = "v2.0.3"; |
115 | inputs = { | 115 | inputs = { |
116 | nixpkgs.follows = "nixpkgs"; | 116 | nixpkgs.follows = "nixpkgs"; |
117 | mach-nix.follows = "mach-nix"; | 117 | mach-nix.follows = "mach-nix"; |
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")) |