Menu

(Solved) : Bonusrate 150 Class Workoutclass Workout Class Offered Gym Private Attributes Name Name Wo Q43991714 . . .

BONUS_RATE = 1.50

class WorkoutClass:
    “””A workout class that can be offered at agym.

    === Private Attributes ===
    _name: The name of this WorkoutClass.
    _required_certificates: The certificates that aninstructor must hold to
        teach thisWorkoutClass.
    “””
    _name: str
    _required_certificates: List[str]

    def __init__(self, name: str,required_certificates: List[str]) -> None:
        “””Initialize a newWorkoutClass called <name> and with the
       <required_certificates>.

       >>> workout_class = WorkoutClass(‘Kickboxing’, [‘StrengthTraining’])
        >>>workout_class.get_name()
        ‘Kickboxing’
        “””
        self._name = name
       self._required_certificates = required_certificates[:]

    def get_name(self) -> str:
        “””Return the name ofthis WorkoutClass.

       >>> workout_class = WorkoutClass(‘Kickboxing’, [‘StrengthTraining’])
        >>>workout_class.get_name()
        ‘Kickboxing’
        “””
        return self._name

    def get_required_certificates(self)-> List[str]:
        “””Return all thecertificates required to teach this WorkoutClass.

       >>> workout_class = WorkoutClass(‘Kickboxing’, [‘StrengthTraining’])
        >>>workout_class.get_required_certificates()
        [‘StrengthTraining’]
        “””
        returnself._required_certificates[:]

class Instructor:
    “””An instructor at a Gym.

    Each instructor may holdcertificates 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 thisInstructor.
    “””
    name: str
    _id: int
    _certificates: List[str]

    def __init__(self, instructor_id:int, instructor_name: str) -> None:
        “””Initialize a newInstructor with an <instructor_id> and their
        <instructor_name>.Initially, the instructor holds no certificates.

       >>> instructor = Instructor(1, ‘Matylda’)
        >>>instructor.get_id()
        1
        >>>instructor.name
        ‘Matylda’
        “””
        # TODO: implement thismethod!
        pass

    def get_id(self) -> int:
        “””Return the id of thisInstructor.

       >>> instructor = Instructor(1, ‘Matylda’)
        >>>instructor.get_id()
        1
        “””
        # TODO: implement thismethod!
        pass

    def add_certificate(self,certificate: str) -> bool:
        “””Add the<certificate> to this instructor’s list of certificatesiff
        this instructor does notalready hold the <certificate>.

        Return Trueiff the <certificate> was added.

       >>> instructor = Instructor(1, ‘Matylda’)
        >>>instructor.add_certificate(‘Strength Training’)
        True
        >>>instructor.add_certificate(‘Strength Training’)
        False
        “””
        # TODO: implement thismethod!
        pass

    def get_num_certificates(self)-> int:
        “””Return the number ofcertificates held by this instructor.

       >>> instructor = Instructor(1, ‘Matylda’)
        >>>instructor.add_certificate(‘Strength Training’)
        True
        >>>instructor.get_num_certificates()
        1
        “””
        # TODO: implement thismethod!
        pass

    def can_teach(self, workout_class:WorkoutClass) -> bool:
        “””Return True iff thisinstructor has all the required certificates to
        teach theworkout_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 thismethod!
        pass

class Gym:
    “””A gym that hosts workout classes taught byinstructors.

    All offerings of workout classesstart on the hour and are 1 hour long.

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

    === Private Attributes ===
    _instructors: The roster of instructors who workat this Gym.
        Each key is aninstructor’s ID and its value is the Instructor object
        representing them.
    _workouts: The workout classes that are taughtat this Gym.
        Each key is the name ofa workout class and its value is the
        WorkoutClass objectrepresenting it.
    _rooms: The rooms in this Gym.
        Each key is the name ofa room and its value is its capacity, that is,
        the number of people whocan register for a class in this room.
    _schedule: The schedule of classes offered atthis gym. Each key is a date
        and time and its valueis a nested dictionary describing all offerings
        that start then. Eachkey in the nested dictionary is the name of a room
        that has an offeringscheduled then, and its value is a tuple describing
        the offering. The tupleelements record the instructor teaching the
        class, the workout classitself, and a list of registered clients. Each
        client is represented bya unique string.

    === Representation Invariants===
    – Each key in _schedule is for a time that is onthe hour.
    – No instructor is recorded as teaching twoworkout classes at the same
      time.
    – No client is recorded as registered for twoworkout classes at the same
      time.
    – If an instructor is recorded as teaching aworkout class, they have the
      necessary qualifications.
    – If there are no offerings scheduled at dateand time <d> in room <r> then
      <r> does not occur as a key in_schedule[d]
    – If there are no offerings at date and time<d> in any room at all, then
      <d> 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 Gymwith <name> that has no instructors, workout
        classes, rooms, orofferings.

       >>> 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<instructor> to this Gym’s roster iff the<instructor>
        has not already beenadded to this Gym’s roster.

        Return Trueiff the instructor was added.

       >>> ac = Gym(‘Athletic Centre’)
        >>> diane =Instructor(1, ‘Diane’)
        >>>ac.add_instructor(diane)
        True
        “””
        # TODO: implement thismethod!
        pass

    def add_workout_class(self,workout_class: WorkoutClass) -> bool:
        “””Add a<workout_class> to this Gym iff the <workout_class> hasnot
        already been added thisGym.

        Return Trueiff the workout class was added.

       >>> ac = Gym(‘Athletic Centre’)
        >>> kickboxing= WorkoutClass(‘Kickboxing’, [‘Strength Training’])
        >>>ac.add_workout_class(kickboxing)
        True
        “””
        # TODO: implement thismethod!
        pass

    def add_room(self, name: str,capacity: int) -> bool:
        “””Add a room with a<name> and <capacity> to this Gym iff the room
        has not already beenadded to this Gym.

        Return Trueiff the room was added.

       >>> ac = Gym(‘Athletic Centre’)
        >>>ac.add_room(‘Dance Studio’, 50)
        True
        “””
        # TODO: implement thismethod!
        pass

    def schedule_workout_class(self,time_point: datetime, room_name: str,
                              workout_name: str, instr_id: int) -> bool:
        “””Add an offering tothis Gym at a <time_point> iff:
           – the room with <room_name> is available,
           – the instructor with <instr_id> is qualified to teach theworkout
             class with <workout_name>, and
           – the instructor is not teaching another workout class duringthe
             same <time_point>.
        A room is available iffit does not already have another workout class
        scheduled at that dateand time.

        The addedoffering should start with no registered clients.

        Return Trueiff 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 thismethod!
        pass

    def register(self, time_point:datetime, client: str, workout_name: str)
           -> bool:
        “””Add <client> tothe WorkoutClass with <workout_name> that is being
        offered at<time_point> iff the client has not already beenregistered
        in any course (including<workout_name>) at <time_point>, and the room
        is not full.

        If theWorkoutClass is being offered in more than one room at
        <time_point>, thenthe client is added to any one of the rooms (i.e.,
        the room chosen does notmatter).

        Return Trueiff the client was added.

       Precondition: the WorkoutClass with <workout_name> is beingoffered in
           some room at <time_point>.

       >>> 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 thismethod!
        pass

    def offerings_at(self, time_point:datetime) -> List[Tuple[str, str, str]]:
        “””Return all theofferings that start at <time_point>.

        Return alist 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
        <time_point>,return an empty list.

        The orderof 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 thismethod!
        pass

    def instructor_hours(self, time1:datetime, time2: datetime) ->
           Dict[int, int]:
        “””Return a dictionaryreporting the hours worked by instructors
        between <time1>and <time2>, inclusive.

        Each key isan instructor ID and its value is the total number of hours
        worked by thatinstructor between <time1> and <time2> inclusive.Both
        <time1> and<time2> specify the start time for an hour when an
        instructor may havetaught.

       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 thismethod!
        pass

    def payroll(self, time1: datetime,time2: datetime, base_rate: float)
           -> List[Tuple[int, str, int, float]]:
        “””Return a sorted listof tuples reporting the total wages earned by
        instructors between<time1> and <time2>, inclusive.

        Each tuplecontains 4 elements, in this order:
           – the instructor’s ID,
           – the instructor’s name,
           – the number of hours worked by the instructor between<time1>
             and <time2> inclusive, and
           – the instructor’s total wages earned between <time1> and<time2>
             inclusive.
        The list is sorted byinstructor ID.

        Both<time1> and <time2> specify the start time for an hourwhen an
        instructor may havetaught.

        Eachinstructor earns a <base_rate> per hour plus anadditional
        BONUS_RATE per hour foreach 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(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 thismethod!
        pass

def parse_instructor(file: TextIO, header: str) ->Instructor:
    “””Return a new Instructor based on the datafound in the file and the
    header.

    Precondition: header has the format’Instructor <ID> <Full Name>’
    “””
    # Extract instructor information from theheader
    header_elements = header.split()
    instr_id = int(header_elements[1].strip())
    name = ‘ ‘.join(header_elements[2:])

    # Create a new instructorobject.
    instr = Instructor(instr_id, name)

    # Add any certificates that theinstructor 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 datafound in the file and the
    header.

    Precondition: header has the format’Class <Workout Class Name>’
    “””
    name = header.replace(‘Class’, ”).strip()

    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 inthe file and the header.

    Precondition: header has the format’Room <Room Name>’
    “””
    room_name = header.split()[1].strip()

    # 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 adatetime for when the
    offerings are scheduled. The second element is alist of all offerings.
    Each offering is a tuple with three elements:the instructor ID, the
    workout class name, and the room name in thatorder.

    Precondition: header has the format’Offerings <Date and Time>’, where the
    date and time are in the following format:%Y-%m-%d %H:%M
    “””
    date_time = header.replace(‘Offerings’,”).strip()
    when = datetime.strptime(date_time, ‘%Y-%m-%d%H:%M’)

    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 adatetime for the offering
    being registered for. The second element is alist of tuples where, for each
    tuple, the first element is the name of theclient and the second element is
    the name of the workout class the client isregistering for.

    Precondition: header has the format’Registrations <Date and Time>’, where
    the date and time are in the following format:%Y-%m-%d %H:%M
    “””
    date_time = header.replace(‘Registrations’,”).strip()
    when = datetime.strptime(date_time, ‘%Y-%m-%d%H:%M’)

    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 thefile being read.

    Precondition: Assumes that the file<file_name> exists and can be read.
    “””
    new_gym = Gym(gym_name)

    with open(file_name, ‘r’) asf:
        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 Gymfrom a file.
    # ac = load_data(‘athletic-centre.txt’,’Athletic Centre’)

plz use python, i copied in all class and test thingswhat need to do is TODO part. It seems easy but im confused aboutprograms ,thx

Expert Answer


Answer to BONUS_RATE = 1.50 class WorkoutClass: “””A workout class that can be offered at a gym. === Private Attributes === _name:…

OR