Use tabulate for output format, add day names and --simple
This commit is contained in:
parent
09ea4ee5ca
commit
7c0ccaf0b6
@ -9,13 +9,16 @@ from collections import OrderedDict, defaultdict
|
||||
from pyscipopt import Model, quicksum
|
||||
from typing import Any, Tuple, TypeVar
|
||||
from dataclasses import dataclass, field
|
||||
from tabulate import tabulate
|
||||
conf = yaml.safe_load(open('config.yaml', 'r'))
|
||||
|
||||
DEFAULT_CONFIG = {
|
||||
"max_load_person": 6
|
||||
"max_load_person": 6,
|
||||
"day_names": [f"dag {str(i)}" for i in range(conf['config']['days'])],
|
||||
}
|
||||
config = DEFAULT_CONFIG | conf['config']
|
||||
config['ignore'].append('')
|
||||
assert(len(config['day_names']) == config['days'])
|
||||
|
||||
QUADRATIC = False
|
||||
|
||||
@ -105,17 +108,26 @@ def set_capabilities(tasks: dict[str, TaskConfig], people: dict[str, Person]):
|
||||
if pers:
|
||||
people[pers.lower()].does.add((day, task))
|
||||
|
||||
def write_tasks(people, tasks, file=sys.stdout):
|
||||
for name, p in people.items():
|
||||
days = [[] for i in range(config['days'])]
|
||||
def write_tasks(people: dict[str, Person], tasks: dict[str, TaskConfig], file=sys.stdout):
|
||||
headers = ["wie"] + config['day_names']
|
||||
if not args.simple:
|
||||
headers += ["workload", "vrolijkheid"]
|
||||
tabl = []
|
||||
for p in people.values():
|
||||
days = [[] for _ in range(config['days'])]
|
||||
for (d,t) in p.does:
|
||||
days[d].append((t, t in p.loves, t in p.hates))
|
||||
if not args.simple:
|
||||
def q(w):
|
||||
return ",".join([t + (" <3" if love else "") + (" :(" if hate else "") for (t,love,hate) in w])
|
||||
days_fmt = " {} ||" * len(days)
|
||||
days_filled = days_fmt.format(*map(q, days))
|
||||
print("| {} ||{} {} || {}".format(name, days_filled, p.vrolijkheid(), p.workload(tasks)), file=file)
|
||||
print("|-")
|
||||
return ",".join([tasks[t].name + (" :)" if love else "") + (" :(" if hate else "") for (t,love,hate) in w])
|
||||
else:
|
||||
def q(w):
|
||||
return ",".join([tasks[t].name for (t,_,_) in w])
|
||||
row = [p.name, *map(q, days)]
|
||||
if not args.simple:
|
||||
row += [p.workload(tasks), p.vrolijkheid()]
|
||||
tabl.append(row)
|
||||
print(tabulate(tabl, headers=headers, tablefmt=args.output_format), file=file)
|
||||
|
||||
def scipsol(people: dict[str, Person], tasks: dict[str, TaskConfig]):
|
||||
max_loads: dict[Tuple[str, int], int] = {}
|
||||
@ -201,7 +213,9 @@ def scipsol(people: dict[str, Person], tasks: dict[str, TaskConfig]):
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-q", "--quadratic", action="store_true")
|
||||
parser.add_argument("--simple", action="store_true", help="hide workload and happiness")
|
||||
parser.add_argument("--max_total_error", type=int, default=None)
|
||||
parser.add_argument("--output-format", default="mediawiki", help="`tabulate` output format")
|
||||
|
||||
args = parser.parse_args()
|
||||
QUADRATIC = args.quadratic
|
||||
|
3
requirements.txt
Normal file
3
requirements.txt
Normal file
@ -0,0 +1,3 @@
|
||||
tabulate~=0.9.0
|
||||
PySCIPOpt~=4.4.0
|
||||
PyYAML~=6.0.1
|
Loading…
Reference in New Issue
Block a user