Exemple #1
0
    def test_create_schedules_throws_when_no_schedules_are_possible(self):
        """ Tests that create_schedules throws an appropriate error message when all
            sections for the chosen courses overlap, meaning no schedules are possible.
        """
        # Arrange
        courses = (
            CourseFilter('CSCE', '221', include_full=True),
            CourseFilter('CSCE', '310', section_nums=['501']),
        )
        term = '201931'

        unavailable_times = []
        meetings = [
            Meeting(id=10,
                    meeting_days=[True] * 7,
                    start_time=time(0, 0),
                    end_time=time(23, 59),
                    meeting_type='LEC',
                    section=self.sections[0]),
            Meeting(id=80,
                    meeting_days=[True] * 7,
                    start_time=time(0, 0),
                    end_time=time(23, 59),
                    meeting_type='LEC',
                    section=self.sections[7]),
        ]
        Meeting.objects.bulk_create(meetings)
        expected_error = _NO_SCHEDULES_POSSIBLE

        # Act + Assert
        with self.assertRaisesMessage(NoSchedulesError, expected_error):
            create_schedules(courses, term, unavailable_times)
Exemple #2
0
    def test_create_schedules_throws_when_no_courses_are_provided(self):
        """ Tests that create_schedules throws an appropriate error message when the array
            of courses is empty.
        """
        courses = []
        term = '201931'
        unavailable_times = []
        expected_error = _NO_COURSES

        # Act + Assert
        with self.assertRaisesMessage(NoSchedulesError, expected_error):
            create_schedules(courses, term, unavailable_times)
Exemple #3
0
    def test_create_schedules_throws_when_no_sections_have_seats(self):
        """ Tests that create_schedules throws an appropriate error message when no
            sections have available seats, and include_full is set to False.
        """
        # Arrange
        subject = 'CSCE'
        course_num = '221'
        courses = (CourseFilter(subject, course_num, include_full=False), )
        term = '201931'
        unavailable_times = []
        expected_error = _NO_SECTIONS_WITH_SEATS.format(subject=subject,
                                                        course_num=course_num)

        # Act + Assert
        with self.assertRaisesMessage(NoSchedulesError, expected_error):
            create_schedules(courses, term, unavailable_times)
    def post(self, request):
        """ Receives a POST request containg the schedule-generating parameters
            and returns a list of generate schedules
        """

        query = request.data

        # List[Tuple[str, str]]
        courses = [_parse_course_filter(course) for course in query["courses"]]
        unavailable_times = [_parse_unavailable_time(avail)
                             for avail in query["availabilities"]]

        term = query["term"]

        num_schedules = 5

        schedules = []
        message = ''
        try:
            schedules = create_schedules(courses, term, unavailable_times, num_schedules)
        except NoSchedulesError as err:
            message = str(err)

        response = {
            'schedules': _serialize_schedules(schedules),
            'message': message
        }
        return Response(response)
Exemple #5
0
    def test_create_shedules_throws_when_no_sections_match_basic_filters(self):
        """ Tests that create_schedules throws an appropriate error message when no
            sections match the provided basic filters.
        """
        # Arrange
        subject = 'CSCE'
        course_num = '2212'
        courses = (CourseFilter(subject,
                                course_num,
                                honors=BasicFilter.ONLY,
                                include_full=True), )
        term = '201931'
        unavailable_times = []
        expected_error = _BASIC_FILTERS_TOO_RESTRICTIVE.format(
            subject=subject, course_num=course_num)

        # Act + Assert
        with self.assertRaisesMessage(NoSchedulesError, expected_error):
            create_schedules(courses, term, unavailable_times)
Exemple #6
0
    def test_create_schedules_throws_when_no_sections_match_availability(self):
        """ Tests that create_schedules throws an appropriate error message when no
            sections match the selected availabilities.
        """
        # Arrange
        subject = 'CSCE'
        course_num = '221'
        courses = (CourseFilter(subject, course_num, include_full=True), )
        term = '201931'
        unavailable_times = [UnavailableTime(time(0, 0), time(23, 59), 0)]
        Meeting(id=80,
                meeting_days=[True, *[False] * 6],
                start_time=time(0, 0),
                end_time=time(23, 59),
                meeting_type='LEC',
                section=self.sections[7]).save()
        expected_error = _NO_SECTIONS_MATCH_AVAILABILITIES.format(
            subject=subject, course_num=course_num)

        # Act + Assert
        with self.assertRaisesMessage(NoSchedulesError, expected_error):
            create_schedules(courses, term, unavailable_times)
    def test_create_schedules_uses_unavailable_times(self):
        """ Tests that create_schedule filters out the provided unavailable_times. """
        # There are 4 possible schedules to generate, 1 is valid given the
        # unavailable times
        # Arrange
        courses = (
            CourseFilter("CSCE", "310"),
            CourseFilter("CSCE", "121",
                         honors=BasicFilter.NO_PREFERENCE,
                         web=BasicFilter.NO_PREFERENCE)
        )
        term = "201931"
        include_full = True
        unavailable_times = [UnavailableTime(time(9, 1), time(9, 2), 4)]
        meetings = [
            # Meetings for CSCE 310-501
            Meeting(id=10, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[0]),
            Meeting(id=11, meeting_days=[True] * 7, start_time=time(9),
                    end_time=time(9, 50), meeting_type='LEC', section=self.sections[0]),
            # Meetings for CSCE 310-502
            Meeting(id=20, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[1]),
            Meeting(id=21, meeting_days=[True] * 7, start_time=time(8),
                    end_time=time(8, 50), meeting_type='LAB', section=self.sections[1]),
            # Meetings for CSCE 121-501
            Meeting(id=40, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[3]),
            Meeting(id=41, meeting_days=[True] * 7, start_time=time(9, 10),
                    end_time=time(10), meeting_type='LAB', section=self.sections[3]),
            # Meetings for CSCE 121-502
            Meeting(id=50, meeting_days=[True] * 7, start_time=time(12, 30),
                    end_time=time(1, 20), meeting_type='LEC', section=self.sections[4]),
            Meeting(id=51, meeting_days=[True] * 7, start_time=time(10),
                    end_time=time(10, 50), meeting_type='LAB', section=self.sections[4]),
        ]
        Meeting.objects.bulk_create(meetings)
        expected_schedules = set(((2, 5),))

        # Act
        schedules = set(create_schedules(courses, term, unavailable_times, include_full,
                                         num_schedules=10))

        # Act
        print('calculator')
        print(schedules)
        print(expected_schedules)
        self.assertEqual(schedules, expected_schedules)
    def test_create_schedules_creates_all_valid_schedules(self):
        """ Tests that create_schedules makes all valid schedules and doesn't
            return any invalid ones
        """
        # There are 4 possible schedules to generate, 2 are valid
        # Arrange
        courses = (
            CourseFilter("CSCE", "310"),
            CourseFilter("CSCE", "121",
                         honors=BasicFilter.NO_PREFERENCE,
                         web=BasicFilter.NO_PREFERENCE)
        )
        term = "201931"
        include_full = True
        unavailable_times = []
        meetings = [
            # Meetings for CSCE 310-501
            Meeting(id=10, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[0]),
            Meeting(id=11, meeting_days=[True] * 7, start_time=time(9),
                    end_time=time(9, 50), meeting_type='LEC', section=self.sections[0]),
            # Meetings for CSCE 310-502
            Meeting(id=20, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[1]),
            Meeting(id=21, meeting_days=[True] * 7, start_time=time(8),
                    end_time=time(8, 50), meeting_type='LAB', section=self.sections[1]),
            # Meetings for CSCE 121-501
            Meeting(id=40, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[3]),
            Meeting(id=41, meeting_days=[True] * 7, start_time=time(9, 10),
                    end_time=time(10), meeting_type='LAB', section=self.sections[3]),
            # Meetings for CSCE 121-502
            Meeting(id=50, meeting_days=[True] * 7, start_time=time(12, 30),
                    end_time=time(1, 20), meeting_type='LEC', section=self.sections[4]),
            Meeting(id=51, meeting_days=[True] * 7, start_time=time(10),
                    end_time=time(10, 50), meeting_type='LAB', section=self.sections[4]),
        ]
        Meeting.objects.bulk_create(meetings)
        expected_schedules = set(((1, 5), (2, 5)))

        # Act
        schedules = set(create_schedules(courses, term, unavailable_times, include_full,
                                         num_schedules=10))

        # Act
        self.assertEqual(schedules, expected_schedules)
    def handle(self, *args, **options):
        # Setup data to create schedule from
        course_names = [("COMM", "203"), ("CSCE", "121"), ("CSCE", "411"),
                        ("MATH", "151"), ("CSCE", "181")]
        courses = [
            CourseFilter(subject, course_num)
            for subject, course_num in course_names
        ]
        courses[3] = CourseFilter("ACCT", "229", honors=True)
        term = "201911"
        unavailable_times = [
            UnavailableTime(datetime.time(8), datetime.time(8, 50), 2),
            UnavailableTime(datetime.time(8), datetime.time(8, 50), 3)
        ]

        start = time()
        schedules = create_schedules(courses, term, unavailable_times)
        end = time()
        print(f"Took {end - start:.4f} seconds to create schedules")
        print(schedules)
Exemple #10
0
    def post(self, request):
        """ Receives a POST request containg the schedule-generating parameters
            and returns a list of generate schedules
        """

        query = request.data

        # List[Tuple[str, str]]
        courses = [_parse_course_filter(course) for course in query["courses"]]
        unavailable_times = [
            _parse_unavailable_time(avail) for avail in query["availabilities"]
        ]

        term = query["term"]
        include_full = query["includeFull"]

        num_schedules = 5
        schedules = create_schedules(courses, term, unavailable_times,
                                     include_full, num_schedules)

        return Response(_serialize_schedules(schedules))