add support for group sizes and output for the web tool

This commit is contained in:
Jakob Krebs 2020-08-14 09:42:42 +02:00
parent b6a739429c
commit d5d12db1b8
No known key found for this signature in database
GPG key ID: C6C125DA9A8FABAA

View file

@ -8,7 +8,7 @@ import json
from pprint import pprint as pprint
if sys.argv[1] == "help":
print(f"{sys.argv[0]} [input_json_file] [maximum_number of students per group]\n {sys.argv[0]} foo.json 12")
print(f"{sys.argv[0]} [input_json_file] [size file] [maximum_number of students per group]\n {sys.argv[0]} sorting.json size.json 12")
sys.exit(0)
def generate_random_set(f, s, g):
@ -45,20 +45,20 @@ def parse_matchings(matchings):
class Rules():
def __init__(self, json_path):
def __init__(self, json_sortings, json_sizes):
self.timetables = []
self.groups = {}
self.rankings = []
with open(json_sizes, 'r') as f:
sizes = json.loads(f.read())
with open(json_path, 'r') as f:
for s in sizes:
self.groups[s["group_id"]] = s["group_size"]
with open(json_sortings, 'r') as f:
data = json.loads(f.read())
for d in data:
if d["group_id"] not in self.groups:
self.groups[d["group_id"]] = 1
else:
self.groups[d["group_id"]] += 1
self.rankings.append((d["group_id"], d["timetable_id"], d["sorting"]))
def addTimetable(self, timtableName):
@ -75,13 +75,13 @@ class Rules():
r+= f"rank('group{g[0]}', 'sched{g[1]}', {g[2]}).\n"
return r
rules = Rules(sys.argv[1])
rules = Rules(sys.argv[1], sys.argv[2])
for i in range(1,13):
rules.addTimetable(i)
#print(rules.generateRules())
max = sys.argv[2]
max = sys.argv[3]
f = open('.rules.pl', 'w')
base = open('rules.pl', 'r').read()
@ -113,4 +113,9 @@ for r in results["Call"]:
matchings = parse_matchings(matchings)
counts = parse_counts(counts)
pprint(counts)
output = []
for m in matchings:
output.append({"group_id": int(m.replace("group", "")), "timetable_id": int(matchings[m].replace("sched", ""))})
pprint(output)