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 payroll(self, time1: datetime, time2: datetime, base_rate: float) \ -> list[tuple[int, str, int, float]]: """Return a sorted list of tuples reporting pay earned by each instructor teaching classes that start any time between and , inclusive. The list should be sorted in ascending order of instructor ids.

Each tuple contains 4 elements, in this order: - an instructor's ID, - the instructor's name, - the number of hours worked by the instructor between and , and - the instructor's total wages earned between and . The returned list is sorted by instructor ID.

Both and specify the start time for an hour when an instructor may have taught.

Each instructor earns a per hour plus an additional BONUS_RATE per hour for each certificate they hold.

Precondition: time1 <= time2

>>> ac = Gym('Athletic Centre') >>> diane = Instructor(1, 'Diane') >>> david = Instructor(2, 'David') >>> diane.add_certificate('Cardio 1') True >>> ac.add_instructor(david) True >>> ac.add_instructor(diane) True >>> ac.add_room('Dance Studio', 50) True >>> boot_camp = WorkoutClass('Boot Camp', ['Cardio 1']) >>> ac.add_workout_class(boot_camp) True >>> t1 = datetime(2019, 9, 9, 12, 0) >>> ac.schedule_workout_class(t1, 'Dance Studio', boot_camp.name, ... 1) True >>> t2 = datetime(2019, 9, 10, 12, 0) >>> ac.payroll(t1, t2, 25.0) [(1, 'Diane', 1, 26.5), (2, 'David', 0, 0.0)] """

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_2

Step: 3

blur-text-image_3

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

Students also viewed these Databases questions

Question

Unions tend to oppose pay-for-performance systems.

Answered: 1 week ago