from model.Constant import Constant
from model.Reservation import Reservation
from collections import defaultdict
import streamlit as st
import json
class HtmlOutput:
ROOM_COLUMN_NUMBER = Constant.DAYS_NUM + 1
ROOM_ROW_NUMBER = Constant.DAY_HOURS + 1
# COLOR1 = "#319378"
# COLOR2 = "#CE0000"
CRITERIAS = ('R', 'S', 'L', 'P', 'G')
# CRITERIAS_DESCR = ("Current room has {any}overlapping", "Current room has {any}enough seats",
# "Current room with {any}enough computers if they are required",
# "Professors have {any}overlapping classes", "Student groups has {any}overlapping classes")
PERIODS = (
"","8 - 8h50", "8h50 - 9h40", "9h40 - 10h30", "10h35 - 11h25", "11h25 - 12h15", "12h15 - 13h05", "13h15 - 14h05", "14h05 - 14h55", "14h55 - 15h45", "15h50 - 16h40", "16h40 - 17h30")
WEEK_DAYS = ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday")
@staticmethod
def getCourseClass(cc, criterias, ci):
sb = []
sb.append(" MH: ")
sb.append(cc.Course.Name)
sb.append("
GV: ")
sb.append(cc.Professor.Name)
sb.append("
Room: ")
# sb.append(room.Name)
# sb.append("/".join(map(lambda grp: grp.Name, cc.Groups)),)
if cc.LabRequired:
sb.append("
Lab ")
return sb
@staticmethod
def generateTimeTable(solution, slot_table):
ci = 0
time_table = defaultdict(list)
items = solution.classes.items
ROOM_COLUMN_NUMBER = HtmlOutput.ROOM_COLUMN_NUMBER
getCourseClass = HtmlOutput.getCourseClass
for cc, reservation_index in items():
reservation = Reservation.parse(reservation_index)
# coordinate of time-space slot
dayId = reservation.Day + 1
dur = cc.Duration
periodId = reservation.Time + 1
if dur == 3:
if 3 < periodId <= 6:
periodId = 4
elif 1 <= periodId <= 3:
periodId = 1
else:
periodId = 7
elif dur == 4 or dur == 5:
if periodId <= 6:
periodId = 1
else:
periodId = 7
else:
periodId = 1
roomId = reservation.Room
key = (periodId, roomId)
if key in slot_table:
room_duration = slot_table[key]
else:
room_duration = ROOM_COLUMN_NUMBER * [0]
slot_table[key] = room_duration
room_duration[dayId] = dur
for m in range(1, dur):
next_key = (periodId + m, roomId)
if next_key not in slot_table:
slot_table[next_key] = ROOM_COLUMN_NUMBER * [0]
if slot_table[next_key][dayId] < 1:
slot_table[next_key][dayId] = -1
if key in time_table:
room_schedule = time_table[key]
else:
room_schedule = ROOM_COLUMN_NUMBER * [None]
time_table[key] = room_schedule
room_schedule[dayId] = "".join(getCourseClass(cc, solution.criteria, ci))
ci += len(HtmlOutput.CRITERIAS)
return time_table
@staticmethod
def getHtmlCell(content, rowspan):
if rowspan == 0:
return "
") temp.append(HtmlOutput.PERIODS[periodId]) temp.append(" | \n") continue if room_schedule is None and room_duration is None: continue content = room_schedule[dayId] if room_schedule is not None else None temp.append(HtmlOutput.getHtmlCell(content, room_duration[dayId])) temp.append("
---|