Пример #1
0
    def test_has_right_neighbour(self):
        #TODO
        #Test for timetableslots that are occupied with lectures

        #test for edge cases

        #test for extreme left condition
        #test for left index out of bounds
        self.assertTrue(self.timetable.has_right_neighbour(
             TimetableSlot('Mon', Classroom('PB001', 100, 'Petroleum building'),TimeSlot('8:00', '9:00'))))

        #test for slot with right neighbour
        self.assertTrue(self.timetable.has_right_neighbour(
             TimetableSlot('Mon', Classroom('PB001', 100, 'Petroleum building'),TimeSlot('9:00', '10:00'))))
        
        #test for extreme right
        #should lack right neighbour
        self.assertFalse(self.timetable.has_right_neighbour(
             TimetableSlot('Mon', Classroom('PB001', 100, 'Petroleum building'),TimeSlot('16:00', '17:00'))))
        
        #test for slot not in timetable 
        self.assertFalse(self.timetable.has_right_neighbour(
             TimetableSlot('Tues', Classroom('PB001', 100, 'Petroleum building'),TimeSlot('9:00', '10:00'))))
        
        #test for slot not in timetable
        self.assertFalse(self.timetable.has_right_neighbour(
             TimetableSlot('Mon',  Classroom('PB001', 50, 'Petroleum building'),TimeSlot('16:00', '17:00'))))
Пример #2
0
 def test_remove_time_table_slot(self):
     self.timetable.remove_time_table_slot(Classroom('LT ', 45, 'PBOO2'),TimeSlot('8:00','9:00'))
     self.timetable.remove_time_table_slot(Classroom('LT ', 45, 'PBOO2'),TimeSlot('9:00','10:00'))
     self.timetable.remove_time_table_slot(Classroom('LT ', 45, 'PBOO2'),TimeSlot('10:00','11:00'))
     self.timetable.remove_time_table_slot(Classroom('LT ', 45, 'PBOO2'),TimeSlot('11:00','12:00'))
     print('-------------------------Remove time table slot ------------------')
     print(self.timetable)
Пример #3
0
    def test_swap_lectures(self):
        pass
        #Test later, not called in generator at the moment
        lecturer = Lecturer('Benjamin Kommey', 4564541, 'Mr')
        course = Course('Embedded Systems', 'COE 361')

        section = Section('ED CoE', 25, 3,
                          'Electrical and Electronics Engineering',
                          'Computer Engineering')
        c_item = CurriculumItem(section, course, lecturer)

        lecture = Lecture(c_item, 60)

        ttslot = TimetableSlot('Monday', Classroom('LT ', 45, 'PBOO2'),
                               TimeSlot('8:00', '9:00'))
        ttslot1 = TimetableSlot('Tuesday', Classroom(' A110', 300, 'Libary'),
                                TimeSlot('9:00', '10:00'))
        ttslot2 = TimetableSlot('Thursday', Classroom('Room C', 67, 'N1'),
                                TimeSlot('10:00', '11:00'))
        ttslot3 = TimetableSlot('Friday', Classroom('LT ', 45, 'PBOO2'),
                                TimeSlot('11:00', '12:00'))
        self.assertTrue(self.timetable.add_lecture('Monday', lecture, ttslot))
        self.assertTrue(self.timetable.add_lecture('Tuesday', lecture,
                                                   ttslot1))
        self.assertTrue(
            self.timetable.add_lecture('Thursday', lecture, ttslot2))
        self.assertTrue(self.timetable.add_lecture('Friday', lecture, ttslot3))
        print(self.timetable)
Пример #4
0
    def test_all_slots(self):
        lecturer = Lecturer('Benjamin Kommey', 4564541, 'Mr')
        course = Course('Embedded Systems', 'COE 361')

        section = Section('ED CoE', 25, 3,
                          'Electrical and Electronics Engineering',
                          'Computer Engineering')
        c_item = CurriculumItem(section, course, lecturer)

        lecture = Lecture(c_item, 60)

        ttslot = TimetableSlot('Monday', Classroom('LT ', 45, 'PBOO2'),
                               TimeSlot('8:00', '9:00'))
        ttslot1 = TimetableSlot('Tuesday', Classroom(' A110', 300, 'Libary'),
                                TimeSlot('9:00', '10:00'))
        ttslot2 = TimetableSlot('Thursday', Classroom('Room C', 67, 'N1'),
                                TimeSlot('10:00', '11:00'))
        ttslot3 = TimetableSlot('Friday', Classroom('LT ', 45, 'PBOO2'),
                                TimeSlot('11:00', '12:00'))
        ttslot4 = TimetableSlot('Monday', Classroom('LT ', 45, 'PBOO2'),
                                TimeSlot('10:00', '11:00'))

        #print(self.timetable)
        self.assertTrue(self.timetable.add_lecture('Monday', lecture, ttslot))
        self.assertTrue(self.timetable.add_lecture('Tuesday', lecture,
                                                   ttslot1))
        self.assertTrue(
            self.timetable.add_lecture('Thursday', lecture, ttslot2))
        self.assertTrue(self.timetable.add_lecture('Friday', lecture, ttslot3))
        print("############ Testing All Slots##############################")
        slots = self.timetable.all_slots()

        for slot in slots:
            print(slot)
Пример #5
0
    def setUp(self) -> None:
        # self.classrooms = factory.generate_batch(ClassRoomFactory, size=20, strategy="build")
        # self.slots = slots
        # self.day_tt = DayTimetable(classrooms=self.classrooms, time_slots=self.slots)

        classrooms = [
            Classroom('LT ', 45, 'PBOO2'),
            Classroom('PB001', 100, 'Petroleum building'),
            Classroom('PBOO2 ', 45, 'Petroleum building'),
            # Classroom('Pb103', 67, 'Petroleum Building'),
            # Classroom('PB119', 150, 'Petroluem'),
            # Classroom(' A110', 300, 'Libary'),
            # Classroom('Computer lab', 67, 'vodafone'),
            # Classroom('LAB-12', 40, 'vodafone'),
            # Classroom('Room A', 100, 'tyeh'),
            # Classroom('Room B ', 45, 'PBOO2'),
            # Classroom('Main Library ', 60, 'Admiss'),
            Classroom('Room C', 67, 'N1')]

        timeslots = [
            TimeSlot('8:00','9:00'),
            TimeSlot('9:00','10:00'),
            TimeSlot('10:00', '11:00'),
            TimeSlot('11:00', '12:00'),
            TimeSlot('12:00', '13:00'),
            TimeSlot('13:00', '14:00'),
            TimeSlot('14:00', '15:00'),
            TimeSlot('15:00', '16:00'),
            TimeSlot('16:00', '17:00')
        ]

        self.timetable = DayTimetable(classrooms, timeslots,'Mon')
Пример #6
0
	def get_inviter_data(self, mtg_id, user_id):
		result = self.collection.find_one({'_id': ObjectId(mtg_id)})
		if result == None:
			# Invalid meeting id
			return None
		if user_id == result['inviter']['inv_id']:
			# Valid inviter. Get all inviter and invitee free times
			# Encoding freetimes into TimeSlot objects to allow for calculations
			raw_freetimes = result['inviter']['freetimes']
			inviter_freetimes = []
			for raw_ft in raw_freetimes:
				inviter_freetimes.append(TimeSlot(raw_ft['begin_datetime'], raw_ft['end_datetime']))
			
			invitee_freetimes = []
			for invitee in result['invitees']:
				# Encoding invitees data
				if not invitee['responded']:
					# Ignores invitees that have not responded from the calculations
					print('{} did not respond, skipping...'.format(invitee['email']))
					continue
				raw_freetimes = invitee['freetimes']
				print('raw freetimes {}'.format(raw_freetimes))
				temp = []
				for raw_ft in raw_freetimes:
					temp.append(TimeSlot(raw_ft['begin_datetime'], raw_ft['end_datetime']))
				invitee_freetimes.append(temp)
			
			# Finding the intersection of all user freetimes
			curr_inter = inviter_freetimes
			print('Inviter freetimes: {}'.format(curr_inter))
			for each_invitee in invitee_freetimes:
				print('Invitee freetimes: {}'.format(each_invitee))
				curr_inter = calc.intersect_two_lists(curr_inter, each_invitee)
				print('Intersection: {}'.format(curr_inter))
			
			# Putting together data
			data = {}
			data['desc'] = result['desc']
			data['duration'] = result['duration']
			data['begin_datetime'] = result['begin_datetime']
			data['end_datetime'] = result['end_datetime']
			data['freetimes'] = timeslot.serialize_list(timeslot.sort_by_begin_time(curr_inter, timeslot.ASCENDING))
			data['invitees'] = []
			for invitee in result['invitees']:
				temp = {}
				temp['email'] = invitee['email']
				temp['responded'] = invitee['responded']
				data['invitees'].append(temp)
			return data
		# Invalid user id
		return None
Пример #7
0
    def test_section_is_free(self):
        lecturer = Lecturer('Benjamin Kommey',4564541,'Mr')
        course = Course('Embedded Systems','COE 361')

        section = Section('ED CoE',25,3,'Electrical and Electronics Engineering','Computer Engineering')
        c_item = CurriculumItem(section,course,lecturer)

        lecture = Lecture(c_item,60)

        ttslot =  TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('8:00', '9:00'))
        ttslot1 =TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('9:00', '10:00'))
        ttslot2 = TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('10:00', '11:00'))
        ttslot3 = TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('11:00', '12:00'))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot1))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot2))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot3))

        self.assertFalse(self.timetable.section_is_free(section,ttslot.time_slot))
        self.assertFalse(self.timetable.section_is_free(section,ttslot1.time_slot))
        self.assertFalse(self.timetable.section_is_free(section,ttslot2.time_slot))
        self.assertFalse(self.timetable.section_is_free(section,ttslot3.time_slot))

        self.assertTrue(self.timetable.section_is_free(section,TimeSlot('15:00', '16:00')))
        self.assertTrue(self.timetable.section_is_free(section,TimeSlot('12:00', '13:00')))
        self.assertTrue(self.timetable.section_is_free(section,TimeSlot('16:00', '17:00')))
        self.assertTrue(self.timetable.section_is_free(section,TimeSlot('7:00', '8:00')))
Пример #8
0
 def __init__(self, course):
     assert course is not None
     self.course = course
     self.slots = [TimeSlot() for _ in range(0,TimeTable.numSlotsPerWeek)]
     
     #for each subject assign the slots(random)
     curSlot = 0
     for subject in self.course.subjects:
         slotsNeeded = int(subject.theoryHours + subject.practicalHours)
         #TODO: Encorporate duration in slotsNeeded
         assert slotsNeeded < len(self.slots) - curSlot
         for i in range(slotsNeeded):
             self.slots[curSlot + i] = TimeSlot(self.course, subject)
         curSlot += slotsNeeded
Пример #9
0
    def test_timetableslot(self):
        lecturer = Lecturer('Benjamin Kommey',4564541,'Mr')
        course = Course('Embedded Systems','COE 361')

        section = Section('ED CoE',25,3,'Electrical and Electronics Engineering','Computer Engineering')
        c_item = CurriculumItem(section,course,lecturer)

        lecture = Lecture(c_item,60)

        ttslot =  TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('8:00', '9:00'))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot))
        self.assertEqual(self.timetable.timetableslot(ttslot.room,ttslot.time_slot),ttslot)
        ttslot1 = TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('9:00', '10:00'))
        self.assertEqual(self.timetable.timetableslot(ttslot1.room,ttslot1.time_slot),ttslot1)
def to_timeslot(instance):
	"""
	Creates a timeslot object from a Google Calendar event instance.

	Args:
		instance:	dict, a google calendar dict

	Returns:
		a dict with only relevant key value pairs
	"""
	if 'dateTime' in instance['start']:
		# Instance has a start and end time
		begin_datetime = instance['start']['dateTime']
		end_datetime   = instance['end']['dateTime']
	elif 'date' in instance['start']:
		# Without a start and end time: is an all day event
		begin_datetime = arrow.get(instance['start']['date']).replace(hour=00,
																	  minute=00,
																	  tzinfo=tz.tzlocal()
																	  ).isoformat()
		end_datetime   = arrow.get(instance['end']['date']).replace(hour=00,
																	minute=00,
																	tzinfo=tz.tzlocal()
																	).isoformat()
	else:
		# This case shouldn't happen
		print("Instance has no specified start and end time or date")
		assert False

	return TimeSlot(instance['summary'], begin_datetime, end_datetime)
Пример #11
0
    def test_remove_lecture(self):
        #test for removing a lecture from a slot that exists and is occupied
        
        lecturer = Lecturer('Benjamin Kommey',4564541,'Mr')
        course = Course('Embedded Systems','COE 361')

        section = Section('ED CoE',25,3,'Electrical and Electronics Engineering','Computer Engineering')
        c_item = CurriculumItem(section,course,lecturer)

        lecture = Lecture(c_item,60)

        print(self.timetable)
        print('--------TEST - REMOVE-------------------After Adding Lecture-----------------')
        ttslot =  TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('8:00', '9:00'))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot))
        print(self.timetable)
        self.assertTrue(self.timetable.remove_lecture(ttslot))
        print('-----TEST REMOVE-----------------------After removing Lecture---------------')
        print(self.timetable)

        #test for removing a lecture from a slot that is empty
        self.assertFalse(self.timetable.remove_lecture(ttslot))

        #test for removing a lecture from a slot that does not exists
        self.assertFalse(self.timetable.remove_lecture( TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('7:00', '8:00'))))
    def best_fit(self, lecture):
        free_slots = self._timetable.free_slots()
        
        # only slots that can hold lecture
        dest_slots = list(filter(lambda slot: self.can_hold(lecture, slot), free_slots))
        
        # TODO
        # change to get metric for obtaining the best

        if dest_slots:
            #sort the slots according to priority
            dest_slots.sort(key = lambda ttslot : self.priority(lecture,ttslot),reverse=False)
            return  dest_slots[-1] #return the last element on the list i.e the element with the highest
            #priority

        # we require merging slots to obtain a slot
        else:
            for ttslot in free_slots:
                # TODO
                # modify left_neighbours and right_neighbours function
                left = self._timetable.left_free_cont_neighbours(ttslot)  # free contiguous left neighbours of slot
                right = self._timetable.right_free_cont_neighbours(ttslot)

                all_slots = left + [ttslot] + right

                for slt in all_slots:
                    if slt.is_occupied:
                        continue

                total_duration = 0

                # determine if the combined duration of all slots can accomodate lecture
                for lslot in all_slots:
                    total_duration += lslot.time_slot.duration

                if lecture.duration <= total_duration:
                    total_duration = 0

                    dest_slots = []
                    for lslot in all_slots:
                        dest_slots.append(lslot)
                        total_duration += lslot.time_slot.duration
                        if total_duration >= lecture.duration:
                            break
                        
                        

                    #create a new temporary slot to accomodate the combination of slots
                    
                    tslot = TimeSlot(dest_slots[0].time_slot.startstr,dest_slots[-1].time_slot.endstr)
                    tempslot = TimetableSlot(dest_slots[0].day,dest_slots[0].room,tslot)

                    #remove all dest_slots from timetable
                    for slot in dest_slots:
                        self.timetable.remove_slot(slot.day,slot.room,slot.time_slot)
                    #add temp slot to timetable
                    self.timetable.insert_slot(tempslot.day,tempslot)

                    return tempslot
Пример #13
0
def timeSlotInput(startTimeInfo: str, endTimeInfo: str) -> TimeSlot:
    while True:
        try:
            startTime = timeInput(startTimeInfo)
            endTime = timeInput(endTimeInfo)
            return TimeSlot(startTime, endTime)
        except ValueError as e:
            print(e)
Пример #14
0
    def test_remove_lecture(self):
        print(
            '################################### Test Removing Lectures ###############################'
        )
        lecturer = Lecturer('Benjamin Kommey', 4564541, 'Mr')
        course = Course('Embedded Systems', 'COE 361')

        section = Section('ED CoE', 25, 3,
                          'Electrical and Electronics Engineering',
                          'Computer Engineering')
        c_item = CurriculumItem(section, course, lecturer)

        lecture = Lecture(c_item, 60)

        ttslot = TimetableSlot('Monday', Classroom('LT ', 45, 'PBOO2'),
                               TimeSlot('8:00', '9:00'))
        ttslot1 = TimetableSlot('Tuesday', Classroom(' A110', 300, 'Libary'),
                                TimeSlot('9:00', '10:00'))
        ttslot2 = TimetableSlot('Thursday', Classroom('Room C', 67, 'N1'),
                                TimeSlot('10:00', '11:00'))
        ttslot3 = TimetableSlot('Friday', Classroom('LT ', 45, 'PBOO2'),
                                TimeSlot('11:00', '12:00'))
        ttslot4 = TimetableSlot('Monday', Classroom('LT ', 45, 'PBOO2'),
                                TimeSlot('10:00', '11:00'))
        print(self.timetable)
        self.assertTrue(self.timetable.add_lecture('Monday', lecture, ttslot))
        self.assertTrue(self.timetable.add_lecture('Tuesday', lecture,
                                                   ttslot1))
        self.assertTrue(
            self.timetable.add_lecture('Thursday', lecture, ttslot2))
        self.assertTrue(self.timetable.add_lecture('Friday', lecture, ttslot3))
        print(self.timetable)
        self.assertTrue(self.timetable.remove_lecture(ttslot.day, ttslot))
        self.assertTrue(self.timetable.remove_lecture(ttslot1.day, ttslot1))
        self.assertTrue(self.timetable.remove_lecture(ttslot2.day, ttslot2))
        self.assertTrue(self.timetable.remove_lecture(ttslot3.day, ttslot3))
        self.assertFalse(self.timetable.remove_lecture(ttslot4.day, ttslot4))
        print(self.timetable)

        print(
            '####################################################################'
        )
        print(self.timetable)
        self.timetable.timetable['Monday'].move_lecture(ttslot, ttslot4)
Пример #15
0
    def test_insert_time_table_slot(self):
        #TODO
        #do tests for slots  containing lectures
        #insert to the right
        room =  Classroom('LT ', 45, 'PBOO2')
        ttslot =  TimetableSlot('Mon', room,TimeSlot('17:00', '18:00'))
        self.timetable.insert_time_table_slot(ttslot)
        self.assertEqual(self.timetable.right_neighbour(TimetableSlot('Mon',room,TimeSlot('16:00', '17:00'))),ttslot)
        
        #test for inserting to the left
        room =  Classroom('LT ', 45, 'PBOO2')
        ttslot =  TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('7:00', '8:00'))
        self.timetable.insert_time_table_slot(ttslot)
        self.assertEqual(self.timetable.left_neighbour(TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('8:00', '9:00'))),ttslot)

        #test for inserting slot that already exists 
        room =  Classroom('LT ', 45, 'PBOO2')
        ttslot =  TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('8:00', '9:00'))
        self.assertFalse(self.timetable.insert_time_table_slot(ttslot),ttslot)
Пример #16
0
 def test_remove_slot(self):
     print(
         '##################################### TEST_REMOVE_SLOT##############################'
     )
     self.timetable.remove_slot('Monday', Classroom('LT ', 45, 'PBOO2'),
                                TimeSlot('8:00', '9:00'))
     self.timetable.remove_slot('Monday', Classroom('LT ', 45, 'PBOO2'),
                                TimeSlot('9:00', '10:00'))
     self.timetable.remove_slot('Wednesday', Classroom('LT ', 45, 'PBOO2'),
                                TimeSlot('8:00', '9:00'))
     self.timetable.remove_slot('Thursday', Classroom('LT ', 45, 'PBOO2'),
                                TimeSlot('8:00', '9:00'))
     print(self.timetable)
     print(
         '################################# INSERT SLOT #####################################'
     )
     self.timetable.insert_slot(
         'Monday',
         TimetableSlot('Monday', Classroom('LT ', 45, 'PBOO2'),
                       TimeSlot('8:00', '10:00')))
     print(self.timetable)
Пример #17
0
 def fromDict(valueDict: dict, globalTasks=None):
     parsedDate = util.dateStringToArrow(valueDict["dateString"]).date()
     timeSlots = [
         TimeSlot.fromDict(t, globalTasks=globalTasks)
         for t in valueDict["timeSlots"]
     ]
     appointments = [
         Appointment.fromDict(appDict)
         for appDict in valueDict["appointments"]
     ]
     isSpecial = valueDict["special"]
     return Day(parsedDate, timeSlots, appointments, special=isSpecial)
Пример #18
0
    def test_move_lecture(self):
         #test for moving lecture from a slot that is occupied

        #first create a new lecture and then add it to a slot
        lecturer = Lecturer('Benjamin Kommey',4564541,'Mr')
        course = Course('Embedded Systems','COE 361')

        section = Section('ED CoE',25,3,'Electrical and Electronics Engineering','Computer Engineering')
        c_item = CurriculumItem(section,course,lecturer)

        lecture = Lecture(c_item,60)

        print(self.timetable)
        print('---------------------------After Adding Lecture-----------------')
        ttslot =  TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('8:00', '9:00'))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot))
        print(self.timetable)

         #test for moving lecture from a slot that is not occupied

        self.assertFalse(self.timetable.move_lecture(TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('10:00', '11:00')),
        TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('14:00', '15:00'))))
        print('---------------------After attempting wrong move-------------------')
        print(self.timetable)

         #test for moving lecture to a slot that is not occupied
        self.assertTrue(self.timetable.move_lecture(TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('8:00', '9:00')),
        TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('10:00', '11:00'))
        ))
        print('------------------------------After moving lecture (unoccupied)-------------------------')
        print(self.timetable)
         #test for moving lecture to a slot that is occupied with free as True
        ttslot =  TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('9:00', '10:00'))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot))
        self.assertFalse(self.timetable.move_lecture(TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('8:00', '9:00')),
        TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('10:00', '11:00'))
        ))
        print(self.timetable)

        #test for moving lecture to a slot that is not occupied with free as False


        #test for moving a lecture back to itself



        #test for moving from a slot that does not exits 
        self.assertFalse(self.timetable.move_lecture(TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('8:00', '10:00')),
        TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('10:00', '11:00'))
        ))

        #test for moving to a slot that does not exits 
        self.assertFalse(self.timetable.move_lecture(TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('8:00', '9:00')),
        TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('10:00', '12:00'))
        ))
Пример #19
0
    def setUp(self):
        #create an empty timetable of 5 days
        classrooms = [
            Classroom('LT ', 45, 'PBOO2'),
            Classroom('PB001', 100, 'Petroleum building'),
            Classroom('Main Library ', 60, 'Admiss'),
            Classroom('Room C', 67, 'N1'),
            Classroom(' A110', 300, 'Libary')
        ]

        timeslots = [
            TimeSlot('8:00', '9:00'),
            TimeSlot('9:00', '10:00'),
            TimeSlot('10:00', '11:00'),
            TimeSlot('11:00', '12:00'),
            TimeSlot('12:00', '13:00'),
            TimeSlot('13:00', '14:00')
        ]

        days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
        day_tables = []

        self.days = days
        for day in days:
            day_tables.append(DayTimetable(classrooms, timeslots, day))

        self.timetable = Timetable(days, day_tables)
Пример #20
0
    def test_first_fit(self):
        lecturer = Lecturer('Benjamin Kommey',4564541,'Mr')
        course = Course('Embedded Systems','COE 361')

        section = Section('ED CoE',25,3,'Electrical and Electronics Engineering','Computer Engineering')
        c_item = CurriculumItem(section,course,lecturer)

        lecture = Lecture(c_item,60)

        ttslot =  TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('8:00', '9:00'))

        print('----------------First Fit-----------------------------')
        print(self.timetable.first_fit(lecture))
Пример #21
0
    def __init__(self, course):

        assert course is not None

        self.course = course
        self.slots = [
            TimeSlot(self.course)
            for x in range(0, TimeTable.num_of_slots_per_week)
        ]  #None value has been assigned to the all the possible slots in above statement
        '''
        Each subject's theory and practical slots are summed up and checked if 
        there are enough slots left in a week interval to be alloted 
        '''

        occupied_slots = 0
        for subject in self.course.subjects:
            slots_required = int(subject.theory_slots +
                                 subject.practical_slots)
            assert slots_required < len(self.slots) - occupied_slots
            for i in range(slots_required):
                self.slots[occupied_slots + i] = TimeSlot(self.course, subject)
            occupied_slots += slots_required
Пример #22
0
    def freeTimeSlots(
        self,
        before=None,
        after=None
    ) -> [TimeSlot
          ]:  # Returns a NEW DEEPCOPIED LIST containing new objects / copies
        # At this point, priority could be used to determine if appointments should get thrown out
        blocking_appointments = self.appointments.copy()
        virtualAppointments = [
        ]  # Blocking appointments to simulate some constraint, i.e. after/before
        if before is not None and before != Time(23, 59):
            before = Appointment("VIRTUAL_APP_BEFORE",
                                 TimeSlot(before, Time(23, 59)))
            virtualAppointments.append(before)
        if after is not None and after != Time(0, 0):
            after = Appointment("VIRTUAL_APP_AFTER",
                                TimeSlot(Time(0, 0), after))
            virtualAppointments.append(after)

        blocking_appointments += virtualAppointments

        freeSlots = []
        for timeSlot in self.timeSlots:
            # TimeSlots with a TaskOrAppointment assigned to it are not free
            if timeSlot.taskOrAppointment is not None:
                continue

            # Calculate overlap with appointments and perhaps split up TimeSlots as necessary
            currentTimeSlots = [timeSlot.copy()]
            for appointment in blocking_appointments:
                newTimeSlots = []
                for currentTimeSlot in currentTimeSlots:
                    newTimeSlots += currentTimeSlot.nonOverlap(
                        appointment.timeSlot)
                currentTimeSlots = newTimeSlots.copy(
                )  # .copy() is very important; mutation danger
            freeSlots += currentTimeSlots.copy()
        return freeSlots
Пример #23
0
    def test_add_lecture(self):

        #test for the case of adding a lecture to a slot that is free with free parameter
        lecturer = Lecturer('Benjamin Kommey',4564541,'Mr')
        course = Course('Embedded Systems','COE 361')

        section = Section('ED CoE',25,3,'Electrical and Electronics Engineering','Computer Engineering')
        c_item = CurriculumItem(section,course,lecturer)

        lecture = Lecture(c_item,60)

        print(self.timetable)
        print('---------------------------After Adding Lecture-----------------')
        ttslot =  TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('8:00', '9:00'))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot))
        print(self.timetable)

        #test for the case of adding a lecture to a slot that is not free with free parameter
        lecturer = Lecturer('Selasi Agbemenu',4564541,'Mr')
        course = Course('Linear Electronics','COE 361')

        section = Section('ED CoE',25,3,'Electrical and Electronics Engineering','Computer Engineering')
        c_item = CurriculumItem(section,course,lecturer)

        lecture = Lecture(c_item,60)
        
        print('---------------------------After Adding Lecture to Occupied---------')
        ttslot =  TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('8:00', '9:00'))
        self.assertFalse(self.timetable.add_lecture(lecture,ttslot))
        print(self.timetable)
        


        #test for adding a lecture to slot that is not in the timetable 
        print('---------------------------After Adding Lecture to Occupied---------')
        ttslot =  TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('6:00', '7:00'))
        self.assertFalse(self.timetable.add_lecture(lecture,ttslot))
        print(self.timetable)
Пример #24
0
    def test_remove_all(self):
         #test for the case of adding a lecture to a slot that is free with free parameter
        lecturer = Lecturer('Benjamin Kommey',4564541,'Mr')
        course = Course('Embedded Systems','COE 361')

        section = Section('ED CoE',25,3,'Electrical and Electronics Engineering','Computer Engineering')
        c_item = CurriculumItem(section,course,lecturer)

        lecture = Lecture(c_item,60)
        
        ttslot =  TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('8:00', '9:00'))
        ttslot1 =TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('9:00', '10:00'))
        ttslot2 = TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('10:00', '11:00'))
        ttslot3 = TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('11:00', '12:00'))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot1))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot2))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot3))
        print('---------------------------After Adding Lectures-----------------')
        print(self.timetable)
        self.assertTrue(self.timetable.remove_all())
        print('---------------------------After Removing Lectures-----------------')
        print(self.timetable)
Пример #25
0
    def test_occupied_slots(self):
        #if all slots are empty return an empty lists
        self.assertEqual([],self.timetable.occupied_slots())
        print(self.timetable.occupied_slots())

        lecturer = Lecturer('Benjamin Kommey',4564541,'Mr')
        course = Course('Embedded Systems','COE 361')

        section = Section('ED CoE',25,3,'Electrical and Electronics Engineering','Computer Engineering')
        c_item = CurriculumItem(section,course,lecturer)

        lecture = Lecture(c_item,60)
        
        ttslot =  TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('8:00', '9:00'))
        ttslot1 =TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('9:00', '10:00'))
        ttslot2 = TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('10:00', '11:00'))
        ttslot3 = TimetableSlot('Mon', Classroom('LT ', 45, 'PBOO2'),TimeSlot('11:00', '12:00'))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot1))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot2))
        self.assertTrue(self.timetable.add_lecture(lecture,ttslot3))

        self.assertEqual([ttslot,ttslot1,ttslot2,ttslot3],self.timetable.occupied_slots())
Пример #26
0
    def test_right_neighbours(self):
        #TODO
        #test for cases with lectures assigned to timetableslots
        
        #test for edge cases
        ttslot1 =   TimetableSlot('Mon', Classroom('PB001', 100, 'Petroleum building'),TimeSlot('14:00', '15:00'))
        neighbours = [TimetableSlot('Mon', Classroom('PB001', 100, 'Petroleum building'),TimeSlot('15:00', '16:00')),
        TimetableSlot('Mon', Classroom('PB001', 100, 'Petroleum building'),TimeSlot('16:00', '17:00'))]
        self.assertEqual(self.timetable.right_neighbours(ttslot1),neighbours)

        #leftmmost slot with no right neighours
        ttslot1 =   TimetableSlot('Mon', Classroom('PB001', 100, 'Petroleum building'),TimeSlot('16:00', '17:00'))
        self.assertEqual(self.timetable.right_neighbours(ttslot1),[])

        #slot not in timetable has no neighbours
        ttslot1 =   TimetableSlot('Fri', Classroom('PB001', 100, 'Petroleum building'),TimeSlot('8:00', '9:00'))
        self.assertEqual(self.timetable.right_neighbours(ttslot1),[])
Пример #27
0
def test_init():
    begin_datetime = '2017-04-10T08:00:00-05:00'
    end_datetime = '2017-04-15T19:00:00-05:00'
    init = init_frees_by_date(begin_datetime, end_datetime)
    ans = [
        TimeSlot('2017-04-10T08:00:00-05:00', '2017-04-10T19:00:00-05:00'),
        TimeSlot('2017-04-11T08:00:00-05:00', '2017-04-11T19:00:00-05:00'),
        TimeSlot('2017-04-12T08:00:00-05:00', '2017-04-12T19:00:00-05:00'),
        TimeSlot('2017-04-13T08:00:00-05:00', '2017-04-13T19:00:00-05:00'),
        TimeSlot('2017-04-14T08:00:00-05:00', '2017-04-14T19:00:00-05:00'),
        TimeSlot('2017-04-15T08:00:00-05:00', '2017-04-15T19:00:00-05:00'),
    ]
    assert len(init) == len(ans)
    for i in range(0, len(init)):
        assert init[i].equals(ans[i])
Пример #28
0
    def scheduleTask(self, newTimeSlot: TimeSlot, task: Task, debug=False):
        if debug:
            print(f"Trying to schedule {newTimeSlot}!")
            print(f"Available TimeSlots: {self.timeSlots}")

        startTime = newTimeSlot.startTime
        endTime = newTimeSlot.endTime
        # Find matching TimeSlot
        for ts in self.timeSlots:
            # If already scheduled
            if ts.taskOrAppointment is not None:
                continue

            # If the TimeSlot includes the startTime/endTime (i.e. Scenario [{}])
            if ts.startTime <= startTime and endTime <= ts.endTime:
                # Remove the old TimeSlot
                self.timeSlots.remove(ts)

                # Add the task to it
                timeSlotToBeScheduled = newTimeSlot.copy()
                timeSlotToBeScheduled.taskOrAppointment = task

                # Calculate the nonOverlap of the existing TimeSlot with the new one. For example:
                # If they are identical, newTimeSlots = []
                # If the old ts was 15:00 - 18:00 and the new one 16:00 - 17:00, then this contains 15:00 - 16:00 and 17:00 - 18:00
                newTimeSlots = ts.nonOverlap(timeSlotToBeScheduled)

                # Add the TimeSlot to be scheduled to the list. The list now contains TimeSlots covering the full area of the original TimeSlot
                newTimeSlots.append(timeSlotToBeScheduled)

                # Re-add the TimeSlots to the day
                for new in newTimeSlots:
                    self.addTimeSlot(
                        new
                    )  # Re-use the addTimeSlot logic. It also auto-sorts
                return  # This is called separately for each (partial) TimeSlot that is supposed to be filled, so all work is done here
        raise Exception(
            f"Could not find a matching TimeSlot for {startTime} - {endTime}!")
Пример #29
0
def initDay(day: Day, config: {}) -> None:
    if day.special:  # No defaults are applied
        return

    if day.date.weekday() >= 5:  # Weekend (Sat/Sun)
        lst = config["weekendTimeSlots"]
    else:
        lst = config["weekdayTimeSlots"]

    for timeSlotDict in lst:
        timeSlot = TimeSlot.fromDict(
            timeSlotDict,
            temporary=True)  # These automatic TimeSlots are NOT persisted
        try:
            day.addTimeSlot(timeSlot)
        except ValueError:
            if timeSlot in day.timeSlots:
                pass  # Already added
            else:
                # In case of overlap, avoid a crash by not applying the default timeSlot
                print(
                    f"WARNING: Default TimeSlot {timeSlot} could not be added to {day} because it overlaps with an existing TimeSlot!"
                )
Пример #30
0
def test_sort():
    A = TimeSlot('A', '2017-11-12T09:00:00+00:00', '2017-11-12T17:00:00+00:00')
    B = TimeSlot('B', '2017-11-13T09:00:00+00:00', '2017-11-13T17:00:00+00:00')
    C = TimeSlot('C', '2017-11-14T00:00:00-08:00', '2017-11-15T00:00:00-08:00')
    D = TimeSlot('D', '2017-11-15T09:00:00+00:00', '2017-11-15T17:00:00+00:00')
    E = TimeSlot('E', '2017-11-15T21:00:00-08:00', '2017-11-16T10:00:00-08:00')
    F = TimeSlot('F', '2017-11-17T00:00:00-08:00', '2017-11-19T00:00:00-08:00')
    unsorted = [A, B, C, D, E, F]
    shuffle(unsorted)

    # Begin time, ascending
    ans = [A, B, C, D, E, F]
    sort = sort_by_begin_time(unsorted, timeslot.ASCENDING)
    assert len(sort) == len(ans)
    for i in range(0, len(ans)):
        assert ans[i].equals(sort[i])

    # End time, descending
    ans = [F, E, D, C, B, A]
    sort = sort_by_end_time(unsorted, timeslot.DESCENDING)
    assert len(sort) == len(ans)
    for i in range(0, len(ans)):
        assert ans[i].equals(sort[i])