Compare commits
2 commits
b6a739429c
...
c60bb513bd
Author | SHA1 | Date | |
---|---|---|---|
c60bb513bd | |||
d5d12db1b8 |
3
example_sizes.json
Normal file
3
example_sizes.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
[{"group_id": 11, "group_size": 4},
|
||||||
|
{"group_id": 12, "group_size": 3},
|
||||||
|
{"group_id": 13, "group_size": 2}]
|
27
generate.py
27
generate.py
|
@ -8,7 +8,7 @@ import json
|
||||||
from pprint import pprint as pprint
|
from pprint import pprint as pprint
|
||||||
|
|
||||||
if sys.argv[1] == "help":
|
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)
|
sys.exit(0)
|
||||||
|
|
||||||
def generate_random_set(f, s, g):
|
def generate_random_set(f, s, g):
|
||||||
|
@ -45,20 +45,20 @@ def parse_matchings(matchings):
|
||||||
|
|
||||||
|
|
||||||
class Rules():
|
class Rules():
|
||||||
def __init__(self, json_path):
|
def __init__(self, json_sortings, json_sizes):
|
||||||
self.timetables = []
|
self.timetables = []
|
||||||
self.groups = {}
|
self.groups = {}
|
||||||
self.rankings = []
|
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())
|
data = json.loads(f.read())
|
||||||
|
|
||||||
for d in data:
|
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"]))
|
self.rankings.append((d["group_id"], d["timetable_id"], d["sorting"]))
|
||||||
|
|
||||||
def addTimetable(self, timtableName):
|
def addTimetable(self, timtableName):
|
||||||
|
@ -75,13 +75,13 @@ class Rules():
|
||||||
r+= f"rank('group{g[0]}', 'sched{g[1]}', {g[2]}).\n"
|
r+= f"rank('group{g[0]}', 'sched{g[1]}', {g[2]}).\n"
|
||||||
return r
|
return r
|
||||||
|
|
||||||
rules = Rules(sys.argv[1])
|
rules = Rules(sys.argv[1], sys.argv[2])
|
||||||
for i in range(1,13):
|
for i in range(1,13):
|
||||||
rules.addTimetable(i)
|
rules.addTimetable(i)
|
||||||
|
|
||||||
#print(rules.generateRules())
|
#print(rules.generateRules())
|
||||||
|
|
||||||
max = sys.argv[2]
|
max = sys.argv[3]
|
||||||
|
|
||||||
f = open('.rules.pl', 'w')
|
f = open('.rules.pl', 'w')
|
||||||
base = open('rules.pl', 'r').read()
|
base = open('rules.pl', 'r').read()
|
||||||
|
@ -113,4 +113,9 @@ for r in results["Call"]:
|
||||||
|
|
||||||
matchings = parse_matchings(matchings)
|
matchings = parse_matchings(matchings)
|
||||||
counts = parse_counts(counts)
|
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)
|
Loading…
Reference in a new issue