From d4da0ee95989c752373ee8889004c6b7135b5414 Mon Sep 17 00:00:00 2001 From: Anja Reusch Date: Sat, 8 Jun 2019 23:02:15 +0200 Subject: [PATCH] generator reads from backup and creates schedule for backup restore in portal --- backup.json | 1 + generate_rules.py | 160 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 backup.json create mode 100644 generate_rules.py diff --git a/backup.json b/backup.json new file mode 100644 index 0000000..987e080 --- /dev/null +++ b/backup.json @@ -0,0 +1 @@ +{"posts":[],"rooms":[{"id":1,"name":"test","places":30,"projector":false,"internet":false,"whiteboard":false,"blackboard":false,"accessible":false,"createdAt":1560014635207,"updateAt":1560018579608},{"id":2,"name":"test2","places":120,"projector":true,"internet":false,"whiteboard":false,"blackboard":false,"accessible":false,"createdAt":1560018419580,"updateAt":1560018560539}],"schedules":[{"id":1,"workGroup":{"id":2,"name":"teset2","description":"","interested":115,"track":null,"projector":false,"resolution":false,"internet":false,"whiteboard":false,"blackboard":false,"accessible":false,"length":50,"language":"GERMAN","leader":["dfsdf"],"constraints":[],"createdAt":1560018635244,"updateAt":1560027050746},"room":{"id":2,"name":"test2","places":120,"projector":true,"internet":false,"whiteboard":false,"blackboard":false,"accessible":false,"createdAt":1560018419580,"updateAt":1560018560539},"day":1,"time":1000,"lockRoom":false,"lockTime":false,"createdAt":1560027295587,"updateAt":1560027295587},{"id":2,"workGroup":{"id":3,"name":"test","description":"","interested":20,"track":null,"projector":true,"resolution":false,"internet":false,"whiteboard":false,"blackboard":false,"accessible":false,"length":110,"language":"GERMAN","leader":["asdasd"],"constraints":[],"createdAt":1560018657977,"updateAt":1560027055351},"room":{"id":2,"name":"test2","places":120,"projector":true,"internet":false,"whiteboard":false,"blackboard":false,"accessible":false,"createdAt":1560018419580,"updateAt":1560018560539},"day":1,"time":1200,"lockRoom":false,"lockTime":false,"createdAt":1560027295597,"updateAt":1560027295597},{"id":3,"workGroup":{"id":4,"name":"testtest","description":"","interested":20,"track":null,"projector":false,"resolution":false,"internet":false,"whiteboard":false,"blackboard":false,"accessible":false,"length":30,"language":"GERMAN","leader":["nulsd"],"constraints":[],"createdAt":1560026986183,"updateAt":1560027058387},"room":{"id":1,"name":"test","places":30,"projector":false,"internet":false,"whiteboard":false,"blackboard":false,"accessible":false,"createdAt":1560014635207,"updateAt":1560018579608},"day":1,"time":1400,"lockRoom":false,"lockTime":false,"createdAt":1560027295600,"updateAt":1560027295600}],"tracks":[],"users":[{"id":1,"username":"admin","password":"$2a$10$TuwJnYxqb/G4Zu5st43FzeM6fYy9vBOcMPR0Fd0IeTePubjW837gW","permissions":["ADMIN"],"createdAt":1560014220841,"updateAt":1560014220841}],"workGroups":[{"id":2,"name":"teset2","description":"","interested":115,"track":null,"projector":false,"resolution":false,"internet":false,"whiteboard":false,"blackboard":false,"accessible":false,"length":50,"language":"GERMAN","leader":["dfsdf"],"constraints":[],"createdAt":1560018635244,"updateAt":1560027050746},{"id":3,"name":"test","description":"","interested":20,"track":null,"projector":true,"resolution":false,"internet":false,"whiteboard":false,"blackboard":false,"accessible":false,"length":110,"language":"GERMAN","leader":["asdasd"],"constraints":[],"createdAt":1560018657977,"updateAt":1560027055351},{"id":4,"name":"testtest","description":"","interested":20,"track":null,"projector":false,"resolution":false,"internet":false,"whiteboard":false,"blackboard":false,"accessible":false,"length":30,"language":"GERMAN","leader":["nulsd"],"constraints":[],"createdAt":1560026986183,"updateAt":1560027058387}]} \ No newline at end of file diff --git a/generate_rules.py b/generate_rules.py new file mode 100644 index 0000000..887918d --- /dev/null +++ b/generate_rules.py @@ -0,0 +1,160 @@ +import json +from math import floor +import subprocess + + +data = json.load(open('backup.json')) + +SLOT_LEN = 120 + +DAYS = 3 +START = 800 +END = 1800 + + +class WorkGroup: + def __init__(self, id, interest, track, projector, reso, length, leaders): + self.id = id # must be int + self.interest = interest + self.track = track if track is not None else 'none' # haben alle aks einen track? + self.projector = 'true' if projector else 'false' + self.reso = 'true' if reso else 'false' + self.length = floor(length/SLOT_LEN) + 1 + self.leaders = leaders + + def __str__(self): + return f'ak({self.id}, {self.interest}, "{self.track}", {self.projector}, {self.reso}, {self.length}).' # TODO Leader + + +class Room: + def __init__(self, id, n_places, projector): # TODO internet, whiteboard & co. + self.id = id # must be int + self.n_places = n_places + self.projector = 'true' if projector else 'false' + + def __str__(self): + return f'room({self.id}, {self.n_places}, {self.projector}).' + + +class Timeslot: + def __init__(self, order, timeslot): + self.begin, self.end, self.day = timeslot + self.id = f'{self.day}#{self.begin}#{self.end}' + self.order = order + # self.begin = begin + # self.end = end + # self.day = day + + def __str__(self): + return f'timeslot("{self.id}", {self.order}, {self.begin}, {self.end}, {self.day}).' + +class Schedule: + def __init__(self, id, workgroup, day, time, room): + self.id = id + self.workgroup = workgroup + self.room = room + self.day = day + self.time = time + + def to_dict(self): + return { + 'id': self.id, + 'workGroup': self.workgroup, + 'room': self.room, + 'time': self.time, + 'day': self.day + } + +workgroups = [] +rooms = [] +id_to_workgroup = {} +id_to_room = {} +for i, workgroup in enumerate(data['workGroups']): + workgroups.append(WorkGroup(workgroup['id'], workgroup['interested'], workgroup['track'], workgroup['projector'], + workgroup['resolution'], workgroup['length'], '')) # TODO add leaders + id_to_workgroup[workgroup['id']] = i + +for i, room in enumerate(data['rooms']): + rooms.append(Room(room['id'], room['places'], room['projector'])) # TODO internet, whiteboard & co. + id_to_room[room['id']] = i + +rules = """ +LENGTH = { schedule(AK,TIMESLOT,ROOM): timeslot(TIMESLOT,_,_,_,_), room(ROOM,_,_) } :- ak(AK,_,_,_,_,LENGTH). + +% forbid 2AKS in the same room at the same time +:- schedule(AK1,TIMESLOT,ROOM), schedule(AK2,TIMESLOT,ROOM), AK1 != AK2. + +% forbid ak with beamer request in room without beamer +:- schedule(AK,_,ROOM), ak(AK,_,_,true,_,_), room(ROOM,_,false). + +% forbid ak in room that is too small +:- schedule(AK,_,ROOM), ak(AK,INTEREST,_,_,_,_), room(ROOM,PLACES,_), PLACES