Question: BONUS_RATE = 1.50 class WorkoutClass: A workout class that can be offered at a gym. === Private Attributes === _name: The name of this WorkoutClass.
BONUS_RATE = 1.50
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' """ self._name = name self._required_certificates = required_certificates[:]
def get_name(self) -> str: """Return the name of this WorkoutClass.
>>> workout_class = WorkoutClass('Kickboxing', ['Strength Training']) >>> workout_class.get_name() 'Kickboxing' """ return self._name
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'] """ return self._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
>>> instructor = Instructor(1, 'Matylda') >>> instructor.get_id() 1 >>> instructor.name 'Matylda' """ # TODO: implement this method! pass
def get_id(self) -> int: """Return the id of this Instructor.
>>> instructor = Instructor(1, 'Matylda') >>> instructor.get_id() 1 """ # TODO: implement this method! pass
def add_certificate(self, certificate: str) -> bool: """Add the
Return True iff the
>>> instructor = Instructor(1, 'Matylda') >>> instructor.add_certificate('Strength Training') True >>> instructor.add_certificate('Strength Training') False """ # TODO: implement this method! pass
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 """ # TODO: implement this method! pass
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 """ # TODO: implement this method! pass
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
def __init__(self, gym_name: str) -> None: """Initialize a new Gym with
>>> ac = Gym('Athletic Centre') >>> ac.name 'Athletic Centre' """ self.name = gym_name self._instructors = {} self._workouts = {} self._rooms = {} self._schedule = {}
def add_instructor(self, instructor: Instructor) -> bool: """Add a new
Return True iff the instructor was added.
>>> ac = Gym('Athletic Centre') >>> diane = Instructor(1, 'Diane') >>> ac.add_instructor(diane) True """ # TODO: implement this method! pass
def add_workout_class(self, workout_class: WorkoutClass) -> bool: """Add a
Return True iff the workout class was added.
>>> ac = Gym('Athletic Centre') >>> kickboxing = WorkoutClass('Kickboxing', ['Strength Training']) >>> ac.add_workout_class(kickboxing) True """ # TODO: implement this method! pass
def add_room(self, name: str, capacity: int) -> bool: """Add a room with a
Return True iff the room was added.
>>> ac = Gym('Athletic Centre') >>> ac.add_room('Dance Studio', 50) True """ # TODO: implement this method! pass
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
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 """ # TODO: implement this method! pass
def register(self, time_point: datetime, client: str, workout_name: str) \ -> bool: """Add
If the WorkoutClass is being offered in more than one room at
Return True iff the client was added.
Precondition: the WorkoutClass with
>>> ac = Gym('Athletic Centre') >>> diane = Instructor(1, 'Diane') >>> diane.add_certificate('Cardio 1') 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 >>> 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 >>> ac.register(sep_9_2019_12_00, 'Philip', 'Boot Camp') True >>> ac.register(sep_9_2019_12_00, 'Philip', 'Boot Camp') False """ # TODO: implement this method! pass
def offerings_at(self, time_point: datetime) -> List[Tuple[str, str, str]]: """Return all the offerings that start at
Return a list of 3-element tuples containing: the instructor's name, the workout class's name, and the room's name. If there are no offerings at
The order of the elements in the returned list does not matter.
>>> ac = Gym('Athletic Centre') >>> diane = Instructor(1, 'Diane') >>> diane.add_certificate('Cardio 1') 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.get_name(), diane.get_id()) True >>> ('Diane', 'Boot Camp', 'Dance Studio') in ac.offerings_at(t1) True """ # TODO: implement this method! pass
def instructor_hours(self, time1: datetime, time2: datetime) -> \ Dict[int, int]: """Return a dictionary reporting the hours worked by instructors between
Each key is an instructor ID and its value is the total number of hours worked by that instructor between
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 """ # TODO: implement this method! pass
def payroll(self, time1: datetime, time2: datetime, base_rate: float) \ -> List[Tuple[int, str, int, float]]: """Return a sorted list of tuples reporting the total wages earned by instructors between
Each tuple contains 4 elements, in this order: - the instructor's ID, - the instructor's name, - the number of hours worked by the instructor between
Both
Each instructor earns a
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.payroll(t1, t2, 25.0) [(1, 'Diane', 1, 26.5), (2, 'David', 0, 0.0)] """ # TODO: implement this method! pass
def parse_instructor(file: TextIO, header: str) -> Instructor: """Return a new Instructor based on the data found in the file and the header.
Precondition: header has the format 'Instructor
# Create a new instructor object. instr = Instructor(instr_id, name)
# Add any certificates that the instructor holds. line = file.readline().strip() while line != '': certificate = line.strip() instr.add_certificate(certificate)
line = file.readline().strip()
return instr
def parse_workout_class(file: TextIO, header: str) -> WorkoutClass: """Return a new WorkoutClass based on the data found in the file and the header.
Precondition: header has the format 'Class
required_certificates = [] line = file.readline().strip() while line != '': required_certificates.append(line.strip())
line = file.readline().strip()
return WorkoutClass(name, required_certificates)
def parse_room(file: TextIO, header: str) -> Tuple[str, int]: """Return a new Room based on the data found in the file and the header.
Precondition: header has the format 'Room
# Ignore the full name. file.readline() # Parse the capacity. capacity = int(file.readline().strip())
return room_name, capacity
def parse_offerings(file: TextIO, header: str) -> \ Tuple[datetime, List[Tuple[int, str, str]]]: """Return a tuple where the first element is a datetime for when the offerings are scheduled. The second element is a list of all offerings. Each offering is a tuple with three elements: the instructor ID, the workout class name, and the room name in that order.
Precondition: header has the format 'Offerings
offerings = [] line = file.readline().strip() while line != '': elements = line.split(sep=',')
instr_id = int(elements[0].strip()) workout_name = elements[1].strip() room_id = elements[2].strip() offerings.append((instr_id, workout_name, room_id))
line = file.readline().strip()
return when, offerings
def parse_registrations(file: TextIO, header: str) -> \ Tuple[datetime, List[Tuple[str, str]]]: """Return a tuple where the first element is a datetime for the offering being registered for. The second element is a list of tuples where, for each tuple, the first element is the name of the client and the second element is the name of the workout class the client is registering for.
Precondition: header has the format 'Registrations
registrations = [] line = file.readline().strip() while line != '': elements = line.split(sep=',')
name = elements[0].strip() workout_class = elements[1].strip() registrations.append((name, workout_class))
line = file.readline().strip()
return when, registrations
def load_data(file_name: str, gym_name: str) -> Gym: """Return a new Gym based on the contents of the file being read.
Precondition: Assumes that the file
with open(file_name, 'r') as f: line = f.readline().strip()
while line != '': if line.startswith('Instructor'): instr = parse_instructor(f, line) new_gym.add_instructor(instr) elif line.startswith('Class'): workout_class = parse_workout_class(f, line) new_gym.add_workout_class(workout_class) elif line.startswith('Room'): room_name, room_capacity = parse_room(f, line) new_gym.add_room(room_name, room_capacity)
# ignore the next line f.readline() elif line.startswith('Offerings'): when, offerings = parse_offerings(f, line)
for o in offerings: new_gym.schedule_workout_class(when, o[2], o[1], o[0]) elif line.startswith('Registrations'): when, registrations = parse_registrations(f, line)
for r in registrations: new_gym.register(when, r[0], r[1])
line = f.readline().strip()
return new_gym
if __name__ == '__main__': import python_ta python_ta.check_all(config={ 'allowed-io': ['load_data'], 'allowed-import-modules': ['doctest', 'python_ta', 'typing', 'datetime'], 'max-attributes': 15, })
import doctest doctest.testmod()
# Example: reading data about a Gym from a file. # ac = load_data('athletic-centre.txt', 'Athletic Centre')
plz use python, i copied in all class and test things what need to do is TODO part. It seems easy but im confused about programs ,thx
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
