ignore capitalization in names, store original name

This commit is contained in:
Yorick van Pelt 2024-04-15 09:54:15 +02:00
parent 298842222d
commit 9fd67ff514
No known key found for this signature in database
GPG Key ID: D8D3CC6D951384DE

View File

@ -5,7 +5,7 @@ import sys
import yaml import yaml
import re import re
import argparse import argparse
from collections import OrderedDict from collections import OrderedDict, defaultdict
from pyscipopt import Model, quicksum from pyscipopt import Model, quicksum
from typing import Any, Tuple, TypeVar from typing import Any, Tuple, TypeVar
from dataclasses import dataclass, field from dataclasses import dataclass, field
@ -24,10 +24,11 @@ class TaskConfig:
personen: list[str] personen: list[str]
workload: int workload: int
req: list[int] req: list[int]
name: str
hardcode: list[str] | None = None hardcode: list[str] | None = None
lookup: list[str] = field(default_factory=list) 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") X = TypeVar("X")
def index(x: dict[X, Any]) -> dict[X, int]: def index(x: dict[X, Any]) -> dict[X, int]:
return {v: k for k, v in enumerate(x)} 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'])] [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'])) ALL_DAYS: set[int] = set(range(config['days']))
class Person(object): 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.can: set[str] = set()
self.loves: set[str] = set() self.loves: set[str] = set()
self.hates: set[str] = set() self.hates: set[str] = set()
@ -62,17 +64,17 @@ def read_people(conf_ppl) -> dict[str, Person]:
val = {"dagen": ALL_DAYS} val = {"dagen": ALL_DAYS}
if isinstance(x, dict): if isinstance(x, dict):
x,val = x.popitem() x,val = x.popitem()
people[x.lower()] = Person(val) people[x.lower()] = Person(x, val)
return people return people
# deal with loves/hates # deal with loves/hates
def make_task_lut(tasks: dict[str, TaskConfig]): def make_task_lut(tasks: dict[str, TaskConfig]):
task_lut = {} task_lut = defaultdict(set)
for t, taskconf in tasks.items(): for t, taskconf in tasks.items():
for lookup in taskconf.lookup: for lookup in taskconf.lookup:
task_lut[lookup] = t task_lut[lookup] |= {t.lower()}
task_re = re.compile(config['task_re']) task_re = re.compile(config['task_re'])
def lookup_tasks(tasks): 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 return lookup_tasks
def read_prefs(pref_file, tasks, people): def read_prefs(pref_file, tasks, people):
lookup_tasks = make_task_lut(tasks) lookup_tasks = make_task_lut(tasks)