ignore capitalization in names, store original name
This commit is contained in:
parent
298842222d
commit
9fd67ff514
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user