Skip to content

Commit

Permalink
class debug representation
Browse files Browse the repository at this point in the history
  • Loading branch information
lschoonheid committed Jan 18, 2023
1 parent 1c72917 commit 155dea1
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
16 changes: 14 additions & 2 deletions code/algorithms/objective.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from ..classes.schedule import Schedule

from ..classes.student import Student
from ..classes.timeslot import Timeslot

# TODO: #15 Implement objective function which couples a score to a schedule
class Objective:
Expand Down Expand Up @@ -33,16 +33,28 @@ def count_student_doubles(self, student: Student):
moment = (timeslot.day, timeslot.period)
if moment in bookings:
double_bookings += 1
print(f"doubly booked student {student.name}: {moment} twice")
print(f"MALUS: doubly booked student {student.name}: {moment} >1 times")
else:
bookings.add(moment)

return double_bookings

def count_timeslot_overbookings(self, timeslot: Timeslot):
overbookings = len(timeslot.activities) - 1
if overbookings > 0:
bookings = [str(timeslot) for timeslot in timeslot.activities.values()]
print(f"MALUS: Overbooked timeslot: {timeslot} has {bookings}")
return overbookings

def get_score(self):
student_double_bookings = 0
for student in self.schedule.students.values():
student_double_bookings += self.count_student_doubles(student)

timeslot_overbookings = 0
for timeslot in self.schedule.timeslots.values():
timeslot_overbookings += self.count_timeslot_overbookings(timeslot)

self.statistics["student_double_bookings"] = student_double_bookings
self.statistics["timeslot_overbookings"] = timeslot_overbookings
return self.score
3 changes: 3 additions & 0 deletions code/classes/activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@ def __init__(self, uid: int, act_type: str, capacity: int | None) -> None:
self.timeslots: dict[int, Timeslot] = {}
self.students: dict[int, Student] = {}

def __repr__(self) -> str:
return f"{self.act_type} of {str(*(self.courses.values()))}"

def __str__(self) -> str:
return f"{self.act_type} of {str(*(self.courses.values()))}"
7 changes: 6 additions & 1 deletion code/classes/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def __init__(self, uid: int):

def add_neighbor(self, node):
match type(node).__name__:
# case type(self).__name__:
# print("ERROR: Not allowed to connect same-level nodes")
case "Course":
self.courses[node.id] = node
case "Activity":
Expand All @@ -25,5 +27,8 @@ def add_neighbor(self, node):
case _:
print(f"Error: in adding node of type {type(node).__name__}: {node} to {self}")

def __repr__(self) -> str:
return f"{type(self).__name__} {self.id} at {hex(id(self))}"

def __str__(self) -> str:
return f"Node {self.id} at {hex(id(self))}"
return f"{type(self).__name__} {self.id} at {hex(id(self))}"
5 changes: 3 additions & 2 deletions code/classes/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ def __init__(

def __repr__(self) -> str:
"""Output representation of information."""
return f"{self.surname}, {self.name} ({self.std_id}): {self.courses}"
# return f"{self.surname}, {self.name} ({self.std_id}): {self.courses}"
return f"{self.name}"

def __str__(self) -> str:
"""Output name to string."""
return f"{self.surname}, {self.name}"
return f"{self.name} {self.surname}"

0 comments on commit 155dea1

Please sign in to comment.