Question
class WorkoutClass: A workout class that can be offered at a gym. === Private Attributes === _name: The name of this WorkoutClass. _required_certificates: The certificates
class WorkoutClass: """A workout class that can be offered at a gym.
=== Private Attributes === _name: The name of this WorkoutClass. _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
>>> workout_class = WorkoutClass('Kickboxing', ['Strength Training']) >>> workout_class.get_name() 'Kickboxing' """
def get_name(self) -> str: """Return the name of this WorkoutClass.
>>> workout_class = WorkoutClass('Kickboxing', ['Strength Training']) >>> workout_class.get_name() 'Kickboxing' """
def get_required_certificates(self) -> List[str]: """Return all the certificates required to teach this WorkoutClass.
>>> workout_class = WorkoutClass('Kickboxing', ['Strength Training']) >>> workout_class.get_required_certificates() ['Strength Training'] """
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' """
implementation omittted
def get_id(self) -> int: """Return the id of this Instructor.
>>> instructor = Instructor(1, 'Matylda') >>> instructor.get_id() 1 """ implementation omitted
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 """ implementation omitted
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 """ implementation omitted
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 """ implementation omitted
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.
=== Public Attributes === name: The name of the gym.
=== Private Attributes === _instructors: The roster of 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. _rooms: The rooms in this Gym. Each key is the name of a room and its value is its capacity, that is, the number of people who can register for a class in this 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. Each key in the nested dictionary 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 the instructor teaching the class, the workout class itself, and a list of registered clients. Each client is represented by a unique string.
=== Representation Invariants === - Each key in _schedule is for a time that is on the hour. - No instructor is recorded as teaching two workout classes at the same time. - No client is recorded as registered for two workout classes at the same time. - If an instructor is recorded as teaching a workout class, they have the necessary qualifications. - If there are no offerings scheduled at date and time in room then does not occur as a key in _schedule[d] - If there are no offerings at date and time in any room at all, then does not occur as a key in _schedule """ name: str _instructors: Dict[int, Instructor] _workouts: Dict[str, WorkoutClass] _rooms: Dict[str, int] _schedule: Dict[datetime, Dict[str, Tuple[Instructor, WorkoutClass, List[str]]]]
def __init__(self, gym_name: str) -> None: """Initialize a new Gym with that has no instructors, workout classes, rooms, or offerings.
>>> ac = Gym('Athletic Centre') >>> ac.name 'Athletic Centre' """ self.name = gym_name self._instructors = {} self._workouts = {} self._rooms = {} self._schedule = {}
def schedule_workout_class(self, time_point: datetime, room_name: str, workout_name: str, instr_id: int) -> bool: """Add an offering to this Gym at a iff: - the room with is available, - the instructor with is qualified to teach the workout class with , and - the instructor is not teaching another workout class during the same . A room is available iff it does not already have another workout class scheduled at that date and time.
The added offering should start with no registered clients.
Return True iff the offering was added.
Preconditions: - The room has already been added to this Gym. - The Instructor has already been added to this Gym. - The WorkoutClass has already been added to this Gym.
>>> ac = Gym('Athletic Centre') >>> diane = Instructor(1, 'Diane') >>> ac.add_instructor(diane) True >>> diane.add_certificate('Cardio 1') True >>> ac.add_room('Dance Studio', 50) True >>> boot_camp = WorkoutClass('Boot Camp', ['Cardio 1']) >>> ac.add_workout_class(boot_camp) True >>> sep_9_2019_12_00 = datetime(2019, 9, 9, 12, 0) >>> ac.schedule_workout_class(sep_9_2019_12_00, 'Dance Studio',\ boot_camp.get_name(), diane.get_id()) True """ #IMPLEMENT METHOD
def instructor_hours(self, time1: datetime, time2: datetime) -> \ Dict[int, int]: """Return a dictionary reporting the hours worked by instructors between and , inclusive.
Each key is an instructor ID and its value is the total number of hours worked by that instructor between and inclusive. Both and specify the start time for an hour when an instructor may have taught.
Precondition: time1 < time2
>>> ac = Gym('Athletic Centre') >>> diane = Instructor(1, 'Diane') >>> david = Instructor(2, 'David') >>> diane.add_certificate('Cardio 1') True >>> ac.add_instructor(diane) True >>> ac.add_instructor(david) 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.get_name(), ... 1) True >>> t2 = datetime(2019, 9, 10, 12, 0) >>> ac.instructor_hours(t1, t2) == {1: 1, 2: 0} True """
# IMPLEMENT METHOD!
This is a part of a greater assignment that I'm working on and I've tried implementing these methods but I just wanted to see a different, more concise way to implement them! any help is appreciated because my code for these functions is too long. Please help with function schedule_workout_class and instructor_hours
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started