From 58582ab735a3c88275b4ed68cb6d19f46eae1b95 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Tue, 4 Apr 2023 16:44:09 +0200 Subject: ... --- overlays/worktime/worktime/__main__.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'overlays/worktime') diff --git a/overlays/worktime/worktime/__main__.py b/overlays/worktime/worktime/__main__.py index c91d73aa..19737805 100755 --- a/overlays/worktime/worktime/__main__.py +++ b/overlays/worktime/worktime/__main__.py @@ -175,6 +175,7 @@ class Worktime(object): time_to_work = None force_day_to_work = True leave_days = set() + excused_days = set() leave_budget = dict() time_per_day = None workdays = None @@ -310,8 +311,11 @@ class Worktime(object): if self.end_date.date() < day or day < self.start_date.date(): continue - if excused_kind == 'leave' and self.would_be_workday(day): - self.leave_days.add(day) + if self.would_be_workday(day): + if excused_kind == 'leave': + self.leave_days.add(day) + elif time >= self.time_per_day: + self.excused_days.add(day) holidays[day] = time except IOError as e: if e.errno != 2: @@ -628,6 +632,10 @@ def classification(classification_name, table, **args): date_format = config.get("WORKTIME", {}).get("DateFormat", '%Y-%m-%d') config_dir = BaseDirectory.load_first_config('worktime') days = [worktime.start_date.date() + timedelta(days = x) for x in range(0, (worktime.end_date.date() - worktime.start_date.date()).days + 1)] + classify_excused = config.get("day-classification", {}).get(classification_name, {}).get("classify-excused", False) + classify_non_workdays = config.get("day-classification", {}).get(classification_name, {}).get("classify-non-workdays", classify_excused) + if classify_excused and not classify_non_workdays: + print('classify_excused but not classify_non_workdays', file=stderr) year_classification = defaultdict(dict) year_offset = defaultdict(lambda: 0) @@ -655,13 +663,18 @@ def classification(classification_name, table, **args): fromDay = toDay = parse_single(stripped_line) for day in [fromDay + timedelta(days = x) for x in range(0, (toDay - fromDay).days + 1)]: + if day in extra_classified: + print(f'Conflicting classification: {day}', file=stderr) extra_classified[day] = val except IOError as e: if e.errno != 2: raise e + extra_classified_used = set() for day in days: - if not worktime.is_workday(day, extra=False): + if not classify_excused and worktime.is_workday(day, extra=False) == classify_non_workdays: + continue + if classify_excused and day not in worktime.excused_days: continue classification_days = set() @@ -686,8 +699,11 @@ def classification(classification_name, table, **args): if day in extra_classified: override = extra_classified[day] if override != default_classification: + extra_classified_used.add(day) year_offset[day.year] += 1 if override else -1 year_classification[day.year][day] = override if override is not None else default_classification + if set(extra_classified.keys()) - set(extra_classified_used): + print(f'Unused manual classification(s): {set(extra_classified.keys()) - set(extra_classified_used)}', file=stderr) if not table: print(sum(year_offset.values())) @@ -697,7 +713,7 @@ def classification(classification_name, table, **args): row_data = [year, year_offset[year]] classified = [day for day, classified in year_classification[year].items() if classified] - 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]) + count_would_be_workdays = len([1 for day in days if day.year == year and (classify_excused or (worktime.would_be_workday(day) and day not in worktime.leave_days) != classify_non_workdays) and (not classify_excused or day in worktime.excused_days)]) if len(year_classification[year]) != count_would_be_workdays: row_data.append(f"{len(classified)}/{len(year_classification[year])}/{count_would_be_workdays}") else: -- cgit v1.2.3