diff options
author | Gregor Kleen <gkleen@yggdrasil.li> | 2025-01-29 20:33:15 +0100 |
---|---|---|
committer | Gregor Kleen <gkleen@yggdrasil.li> | 2025-01-29 20:33:15 +0100 |
commit | 20168a40bc72096b2abd2b5fceae4a5f8a318cc9 (patch) | |
tree | be041bd1b1e601d2119f910438877376db8914df /overlays | |
parent | edaaa0b3c00322483e42d80a70b34b09527297d5 (diff) | |
download | nixos-20168a40bc72096b2abd2b5fceae4a5f8a318cc9.tar nixos-20168a40bc72096b2abd2b5fceae4a5f8a318cc9.tar.gz nixos-20168a40bc72096b2abd2b5fceae4a5f8a318cc9.tar.bz2 nixos-20168a40bc72096b2abd2b5fceae4a5f8a318cc9.tar.xz nixos-20168a40bc72096b2abd2b5fceae4a5f8a318cc9.zip |
...
Diffstat (limited to 'overlays')
-rwxr-xr-x | overlays/worktime/worktime/__main__.py | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py index 9335afdc..ba6c5ff6 100755 --- a/overlays/worktime/worktime/__main__.py +++ b/overlays/worktime/worktime/__main__.py | |||
@@ -224,6 +224,7 @@ class Worktime(object): | |||
224 | leave_budget = dict() | 224 | leave_budget = dict() |
225 | time_per_day = None | 225 | time_per_day = None |
226 | workdays = None | 226 | workdays = None |
227 | pull_forward = dict() | ||
227 | 228 | ||
228 | @staticmethod | 229 | @staticmethod |
229 | @cache | 230 | @cache |
@@ -391,8 +392,6 @@ class Worktime(object): | |||
391 | if e.errno != 2: | 392 | if e.errno != 2: |
392 | raise e | 393 | raise e |
393 | 394 | ||
394 | pull_forward = dict() | ||
395 | |||
396 | start_day = self.start_date.date() | 395 | start_day = self.start_date.date() |
397 | end_day = self.end_date.date() | 396 | end_day = self.end_date.date() |
398 | 397 | ||
@@ -419,15 +418,15 @@ class Worktime(object): | |||
419 | if not d == datetime.strptime(c, date_format).replace(tzinfo=tzlocal()).date(): break | 418 | if not d == datetime.strptime(c, date_format).replace(tzinfo=tzlocal()).date(): break |
420 | else: | 419 | else: |
421 | if d >= self.end_date.date(): | 420 | if d >= self.end_date.date(): |
422 | pull_forward[d] = min(timedelta(hours = float(hours)), self.time_per_day(d) - (holidays[d] if d in holidays else timedelta())) | 421 | self.pull_forward[d] = min(timedelta(hours = float(hours)), self.time_per_day(d) - (holidays[d] if d in holidays else timedelta())) |
423 | except IOError as e: | 422 | except IOError as e: |
424 | if e.errno != 2: | 423 | if e.errno != 2: |
425 | raise e | 424 | raise e |
426 | 425 | ||
427 | self.days_to_work = dict() | 426 | self.days_to_work = dict() |
428 | 427 | ||
429 | if pull_forward: | 428 | if self.pull_forward: |
430 | end_day = max(end_day, max(list(pull_forward))) | 429 | end_day = max(end_day, max(list(self.pull_forward))) |
431 | 430 | ||
432 | for day in [start_day + timedelta(days = x) for x in range(0, (end_day - start_day).days + 1)]: | 431 | for day in [start_day + timedelta(days = x) for x in range(0, (end_day - start_day).days + 1)]: |
433 | if day.isoweekday() in self.workdays: | 432 | if day.isoweekday() in self.workdays: |
@@ -471,17 +470,17 @@ class Worktime(object): | |||
471 | self.extra_days_to_work[self.now.date()] = timedelta() | 470 | self.extra_days_to_work[self.now.date()] = timedelta() |
472 | 471 | ||
473 | self.time_to_work = sum([self.days_to_work[day] for day in self.days_to_work.keys() if day <= self.end_date.date()], timedelta()) | 472 | self.time_to_work = sum([self.days_to_work[day] for day in self.days_to_work.keys() if day <= self.end_date.date()], timedelta()) |
474 | for day in [d for d in list(pull_forward) if d > self.end_date.date()]: | 473 | for day in [d for d in list(self.pull_forward) if d > self.end_date.date()]: |
475 | days_forward = set([d for d in self.days_to_work.keys() if d >= self.end_date.date() and d < day and (not d in pull_forward or d == self.end_date.date())]) | 474 | days_forward = set([d for d in self.days_to_work.keys() if d >= self.end_date.date() and d < day and (not d in self.pull_forward or d == self.end_date.date())]) |
476 | extra_days_forward = set([d for d in self.extra_days_to_work.keys() if d >= self.end_date.date() and d < day and (not d in pull_forward or d == self.end_date.date())]) | 475 | extra_days_forward = set([d for d in self.extra_days_to_work.keys() if d >= self.end_date.date() and d < day and (not d in self.pull_forward or d == self.end_date.date())]) |
477 | days_forward = days_forward.union(extra_days_forward) | 476 | days_forward = days_forward.union(extra_days_forward) |
478 | 477 | ||
479 | extra_day_time_left = timedelta() | 478 | extra_day_time_left = timedelta() |
480 | for extra_day in extra_days_forward: | 479 | for extra_day in extra_days_forward: |
481 | day_time = max(timedelta(), self.time_per_day(extra_day) - self.extra_days_to_work[extra_day]) | 480 | day_time = max(timedelta(), self.time_per_day(extra_day) - self.extra_days_to_work[extra_day]) |
482 | extra_day_time_left += day_time | 481 | extra_day_time_left += day_time |
483 | extra_day_time = min(extra_day_time_left, pull_forward[day]) | 482 | extra_day_time = min(extra_day_time_left, self.pull_forward[day]) |
484 | time_forward = pull_forward[day] - extra_day_time | 483 | time_forward = self.pull_forward[day] - extra_day_time |
485 | if extra_day_time_left > timedelta(): | 484 | if extra_day_time_left > timedelta(): |
486 | for extra_day in extra_days_forward: | 485 | for extra_day in extra_days_forward: |
487 | day_time = max(timedelta(), self.time_per_day(extra_day) - self.extra_days_to_work[extra_day]) | 486 | day_time = max(timedelta(), self.time_per_day(extra_day) - self.extra_days_to_work[extra_day]) |
@@ -571,7 +570,10 @@ def worktime(pull_forward_cutoff, waybar, **args): | |||
571 | return f"({difference_string})" | 570 | return f"({difference_string})" |
572 | 571 | ||
573 | out_class = "running" if worktime.running_entry else "stopped" | 572 | out_class = "running" if worktime.running_entry else "stopped" |
574 | tooltip = tooltip_timedelta(worktime.time_to_work - worktime.time_worked) | 573 | difference = worktime.time_to_work - worktime.time_worked |
574 | if worktime.running_entry and -min(timedelta(milliseconds=0), difference) > sum(worktime.pull_forward.values(), start=timedelta(milliseconds=0)) or not worktime.running_entry and max(timedelta(milliseconds=0), difference) > worktime.time_per_day(worktime.now.date()) and worktime.now_is_workday: | ||
575 | out_class = "over" | ||
576 | tooltip = tooltip_timedelta(difference) | ||
575 | if worktime.time_pulled_forward >= min(pull_forward_cutoff, timedelta(seconds = 1)): | 577 | if worktime.time_pulled_forward >= min(pull_forward_cutoff, timedelta(seconds = 1)): |
576 | worktime_no_pulled_forward = deepcopy(worktime) | 578 | worktime_no_pulled_forward = deepcopy(worktime) |
577 | worktime_no_pulled_forward.time_to_work -= worktime_no_pulled_forward.time_pulled_forward | 579 | worktime_no_pulled_forward.time_to_work -= worktime_no_pulled_forward.time_pulled_forward |
@@ -593,6 +595,10 @@ def worktime(pull_forward_cutoff, waybar, **args): | |||
593 | else: | 595 | else: |
594 | print(out_text) | 596 | print(out_text) |
595 | 597 | ||
598 | def pull_forward(**args): | ||
599 | worktime = Worktime(**args) | ||
600 | print(tooltip_timedelta(sum(worktime.pull_forward.values(), start=timedelta(milliseconds=0)))) | ||
601 | |||
596 | def time_worked(now, waybar, **args): | 602 | def time_worked(now, waybar, **args): |
597 | then = now.replace(hour = 0, minute = 0, second = 0, microsecond = 0) | 603 | then = now.replace(hour = 0, minute = 0, second = 0, microsecond = 0) |
598 | if now.time() == time(): | 604 | if now.time() == time(): |
@@ -895,6 +901,8 @@ def main(): | |||
895 | classification_parser.add_argument('--table', action = 'store_true') | 901 | classification_parser.add_argument('--table', action = 'store_true') |
896 | classification_parser.add_argument('--table-format', dest='table_format', type=str, default='fancy_grid') | 902 | classification_parser.add_argument('--table-format', dest='table_format', type=str, default='fancy_grid') |
897 | classification_parser.set_defaults(cmd = partial(classification, classification_name=classification_name)) | 903 | classification_parser.set_defaults(cmd = partial(classification, classification_name=classification_name)) |
904 | pull_forward_parser = subparsers.add_parser('pull-forward') | ||
905 | pull_forward_parser.set_defaults(cmd = pull_forward) | ||
898 | parser.set_default_subparser('time_worked') | 906 | parser.set_default_subparser('time_worked') |
899 | args = parser.parse_args() | 907 | args = parser.parse_args() |
900 | 908 | ||