Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

BONUS_RATE = 1.50 class WorkoutClass: A workout class that can be offered at a gym. === Public Attributes === name: The name of the workout

BONUS_RATE = 1.50

class WorkoutClass: """A workout class that can be offered at a gym.

=== Public Attributes === name: The name of the workout class.

=== Private Attributes === _required_certificates: The certificates that an instructor must hold to teach this WorkoutClass. """ name: str _required_certificates: list[str]

def __init__(self, name: str, required_certificates: list[str]) -> None: """Initialize a new WorkoutClass called and with the .

>>> workout_class = WorkoutClass('Kickboxing', ['Strength Training']) >>> workout_class.name 'Kickboxing' """ self.name = name self._required_certificates = required_certificates[:]

def get_required_certificates(self) -> list[str]: """Return all the certificates required to teach this WorkoutClass.

>>> workout_class = WorkoutClass('Kickboxing', ['Strength Training']) >>> needed = workout_class.get_required_certificates() >>> needed ['Strength Training'] >>> needed.append('haha') >>> try_again = workout_class.get_required_certificates() >>> try_again ['Strength Training'] """ # Make a copy of the list to avoid aliasing return self._required_certificates[:]

def __eq__(self, other: Any) -> bool: """Return True iff this WorkoutClass is equal to .

Two WorkoutClasses are considered equal if they have the same name and the same required certificates.

>>> workout_class = WorkoutClass('Kickboxing', ['Strength Training']) >>> workout_class2 = WorkoutClass('Kickboxing', ['Strength Training']) >>> workout_class == workout_class2 True >>> d = {1: 17} >>> workout_class == d False """ if not isinstance(other, WorkoutClass): return False return (self.name == other.name and self._required_certificates == other._required_certificates)

class Instructor: """An instructor at a Gym. Each instructor may hold certificates that allows them to teach specific workout classes. === Public Attributes === name: This Instructor's name. === Private Attributes === _id: This Instructor's identifier. _certificates: The certificates held by this Instructor. """ name: str _id: int _certificates: List[str]

def __init__(self, instructor_id: int, instructor_name: str) -> None: """Initialize a new Instructor with an and their . Initially, the instructor holds no certificates. >>> instructor = Instructor(1, 'Matylda') >>> instructor.get_id() 1 >>> instructor.name 'Matylda' """ self._id = instructor_id self.name = instructor_name self._certificates = []

def get_id(self) -> int: """Return the id of this Instructor. >>> instructor = Instructor(1, 'Matylda') >>> instructor.get_id() 1 """ return self._id

def add_certificate(self, certificate: str) -> bool: """Add the to this instructor's list of certificates iff this instructor does not already hold the . Return True iff the was added. >>> instructor = Instructor(1, 'Matylda') >>> instructor.add_certificate('Strength Training') True >>> instructor.add_certificate('Strength Training') False """ if certificate in self._certificates: return False else: self._certificates.append(certificate) return True

def get_num_certificates(self) -> int: """Return the number of certificates held by this instructor. >>> instructor = Instructor(1, 'Matylda') >>> instructor.add_certificate('Strength Training') True >>> instructor.get_num_certificates() 1 """ return len(self._certificates)

def can_teach(self, workout_class: WorkoutClass) -> bool: """Return True iff this instructor has all the required certificates to teach the workout_class. >>> matylda = Instructor(1, 'Matylda') >>> kickboxing = WorkoutClass('Kickboxing', ['Strength Training']) >>> matylda.can_teach(kickboxing) False >>> matylda.add_certificate('Strength Training') True >>> matylda.can_teach(kickboxing) True """ for item in self._certificates: if item not in \ WorkoutClass.get_required_certificates(workout_class): return False return True

def get_certificates(self): """ Return the list of certificates that the instructor has >>> instructor = Instructor(1, 'Matylda') >>> instructor.add_certificate('Strength Training') True >>> instructor.get_certificates() ['Strength Training'] """ return self._certificates

class Gym: """A gym that hosts workout classes taught by instructors.

All offerings of workout classes start on the hour and are 1 hour long. If a class starts at 7:00 pm, for example, we say that the class is "at" the timepoint 7:00, or just at 7:00.

=== Public Attributes === name: The name of the gym.

=== Private Attributes === _instructors: The instructors who work at this Gym. Each key is an instructor's ID and its value is the Instructor object representing them. _workouts: The workout classes that are taught at this Gym. Each key is the name of a workout class and its value is the WorkoutClass object representing it. _room_capacities: The rooms and capacities in this Gym. Each key is the name of a room and its value is the room's capacity, that is, the number of people who can register for a class in the room. _schedule: The schedule of classes offered at this gym. Each key is a date and time and its value is a nested dictionary describing all offerings that start then. In the nested dictionary, each key is the name of a room that has an offering scheduled then, and its value is a tuple describing the offering. The tuple elements record, in order: - the instructor teaching the class, - the workout class itself, and - a list of registered clients. Each client is represented in the list by a unique string.

=== Representation Invariants === - All instructors in _schedule are in _instructors (the reverse is not necessarily true). - All workout classes in _schedule are in _workouts (the reverse is not necessarily true). - All rooms recorded in _schedule are also recorded in _room_capacities (the reverse is not necessarily true). - Two workout classes cannot be scheduled at the same time in the same room. - No instructor is scheduled to teach two workout classes at the same time. I.e., there does not exist timepoint t, and rooms r1 and r2 such that _schedule[t][r1][0] == _schedule[t][r2][0] - No client can take two workout classes at the same time. I.e., there does not exist timepoint t, and rooms r1 and r2 such that c in _schedule[t][r1][2] and c in _schedule[t][r2][2] - If an instructor is scheduled to teach a workout class, they have the necessary qualifications. - If there are no offerings scheduled at date and time , then does not occur as a key in _schedule. - If there are no offerings scheduled at date and time in room then does not occur as a key in _schedule[d] - Each list of registered clients for an offering is ordered with the most recently registered client at the end of the list. """ name: str _instructors: dict[int, Instructor] _workouts: dict[str, WorkoutClass] _room_capacities: dict[str, int] _schedule: dict[datetime, dict[str, tuple[Instructor, WorkoutClass, list[str]]]]

FUNCTIONS TO COMPLETE

def to_schedule_list(self, week: datetime = None) \ -> list[dict[str, str | int]]: """Return a list of dictionaries for the Gym's entire schedule, with each dictionary representing a workout offered (in the format specified by the docstring for offerings_at).

The dictionaries should be in the list in ascending order by their date and time (not the string representation of the date and time). Offerings occurring at exactly the same date and time should be in alphabetical order based on their room names.

If is specified, only return the events that occur between the date interval (between a Monday 0:00 and Sunday 23:59) that contains .

Hint: The helper function can be used to determine if one datetime object is in the same week as another.

>>> ac = Gym('Athletic Centre') >>> diane1 = Instructor(1, 'Diane') >>> diane1.add_certificate('Cardio 1') True >>> diane2 = Instructor(2, 'Diane') >>> david = Instructor(3, 'David') >>> david.add_certificate('Strength Training') True >>> ac.add_instructor(diane1) True >>> ac.add_instructor(diane2) True >>> ac.add_instructor(david) True >>> ac.add_room('Studio 1', 20) True >>> boot_camp = WorkoutClass('Boot Camp', ['Cardio 1']) >>> ac.add_workout_class(boot_camp) True >>> kickboxing = WorkoutClass('KickBoxing', ['Strength Training']) >>> ac.add_workout_class(kickboxing) True >>> t1 = datetime(2022, 9, 9, 12, 0) >>> ac.schedule_workout_class(t1, 'Studio 1', boot_camp.name, 1) True >>> t2 = datetime(2022, 9, 8, 13, 0) >>> ac.schedule_workout_class(t2, 'Studio 1', kickboxing.name, 3) True >>> ac.to_schedule_list() == [ ... { 'Date': 'Thursday, 2022-09-08', 'Time': '13:00', ... 'Class': 'KickBoxing', 'Room': 'Studio 1', 'Registered': 0, ... 'Available': 20, 'Instructor': 'David' }, ... { 'Date': 'Friday, 2022-09-09', 'Time': '12:00', ... 'Class': 'Boot Camp', 'Room': 'Studio 1', 'Registered': 0, ... 'Available': 20, 'Instructor': 'Diane (1)' }, ... ] True """

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions