From 9fd67ff514a9530c017124805268d143dac61abd Mon Sep 17 00:00:00 2001 From: Yorick van Pelt Date: Mon, 15 Apr 2024 09:54:15 +0200 Subject: [PATCH] ignore capitalization in names, store original name --- magisch_corvee_script.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/magisch_corvee_script.py b/magisch_corvee_script.py index 24c6236..1b23973 100755 --- a/magisch_corvee_script.py +++ b/magisch_corvee_script.py @@ -5,7 +5,7 @@ import sys import yaml import re import argparse -from collections import OrderedDict +from collections import OrderedDict, defaultdict from pyscipopt import Model, quicksum from typing import Any, Tuple, TypeVar from dataclasses import dataclass, field @@ -24,10 +24,11 @@ class TaskConfig: personen: list[str] workload: int req: list[int] + name: str hardcode: list[str] | None = None lookup: list[str] = field(default_factory=list) -tasks: dict[str, TaskConfig] = OrderedDict({k: TaskConfig(**t) for k, t in conf['tasks'].items()}) +tasks: dict[str, TaskConfig] = OrderedDict({k: TaskConfig(**({"name": k} | t)) for k, t in conf['tasks'].items()}) X = TypeVar("X") def index(x: dict[X, Any]) -> dict[X, int]: return {v: k for k, v in enumerate(x)} @@ -35,7 +36,8 @@ daily_workloads = \ [sum(task.workload * task.req[d] for task in tasks.values()) for d in range(config['days'])] ALL_DAYS: set[int] = set(range(config['days'])) class Person(object): - def __init__(self, conf={"dagen":ALL_DAYS}): + def __init__(self, name: str, conf={"dagen":ALL_DAYS}): + self.name = name self.can: set[str] = set() self.loves: set[str] = set() self.hates: set[str] = set() @@ -62,17 +64,17 @@ def read_people(conf_ppl) -> dict[str, Person]: val = {"dagen": ALL_DAYS} if isinstance(x, dict): x,val = x.popitem() - people[x.lower()] = Person(val) + people[x.lower()] = Person(x, val) return people # deal with loves/hates def make_task_lut(tasks: dict[str, TaskConfig]): - task_lut = {} + task_lut = defaultdict(set) for t, taskconf in tasks.items(): for lookup in taskconf.lookup: - task_lut[lookup] = t + task_lut[lookup] |= {t.lower()} task_re = re.compile(config['task_re']) def lookup_tasks(tasks): - return (task_lut[x] for x in task_re.split(tasks) if x not in config['ignore']) + return set.union(*(task_lut[x.strip()] for x in task_re.split(tasks) if x not in config['ignore'])) return lookup_tasks def read_prefs(pref_file, tasks, people): lookup_tasks = make_task_lut(tasks)