Пример #1
0
def main_board(req, **kwargs):

    department = req.department

    # Get week list
    period = PeriodWeeks(department, exclude_empty_weeks=True)
    week_list = period.get_weeks(format=True)

    # Get solver list
    solvers_viewmodel = get_pulp_solvers_viewmodel()

    # Get all TrainingProgramme
    all_tps = list(TrainingProgramme.objects \
                    .filter(department=department) \
                    .values_list('abbrev', flat=True))

    view_context = {
        'department': department,
        'text_all': text_all,
        'weeks': json.dumps(week_list),
        'train_progs': json.dumps(all_tps),
        'solvers': solvers_viewmodel,
    }

    # Get contextual datas (constraints, work_copies)
    data_context = get_context(department,
                               year=week_list[0][0],
                               week=week_list[0][1])
    view_context.update({k: json.dumps(v) for k, v in data_context.items()})

    return TemplateResponse(req, 'solve_board/main-board.html', view_context)
Пример #2
0
 def test_Q_filter_week_all(self):
     pw = PeriodWeeks(department=self.department, year=2018)
     filter_all = pw.get_filter()
     self.assertEqual(
         str(filter_all),
         "(OR: (AND: ('cours__an', 2018), ('cours__semaine__in', {35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52})), (AND: ('cours__an', 2019), ('cours__semaine__in', {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26})))"
     )
Пример #3
0
 def test_filter_empty_weeks(self):
     year_2018_without_weeks = {
         36, 37, 38, 39, 40, 41, 42, 43, 45, 46, 47, 48, 49, 50, 51
     }
     pw = PeriodWeeks(department=self.department,
                      year=2018,
                      exclude_empty_weeks=True).get_raw()
     self.assertSetEqual(pw[0][1], year_2018_without_weeks)
Пример #4
0
 def test_get_holiday_list(self):
     # May, 1, 2019
     wednesday, _ = models.Day.objects.get_or_create(
         day=models.Day.WEDNESDAY)
     holiday, _ = models.Holiday.objects.get_or_create(year=2019,
                                                       week=19,
                                                       day=wednesday)
     period = PeriodWeeks(2018)
     holiday_list = list(get_holiday_list(period))
     self.assertIn((holiday.year, holiday.week, holiday.day.no),
                   holiday_list)
Пример #5
0
    def test_school_year_2018(self):

        pw = PeriodWeeks(department=self.department, year=2018)

        for index, (year, weeks) in enumerate(pw):
            self.assertEqual(self.period_2018[index][0], year)
            self.assertSetEqual(self.period_2018[index][1], weeks)

        self.assertEqual(pw.start_year, 2018)
        self.assertEqual(pw.start_week, 35)
        self.assertEqual(pw.end_week, 26)
Пример #6
0
def get_tutor_hours(department, year=None):

    # Return a tutor list with the numbers
    # of hours of given courses

    # year : correponds to the first period's year
    period = PeriodWeeks(year=year)
    period_filter = period.get_filter(related_path='taught_courses')

    # Filter all the scheduled courses for the period
    # and group by tutor
    query = Tutor.objects \
        .filter(
            period_filter,
            departments=department,
            taught_courses__scheduledcourse__copie_travail=0,
            ) \
        .values_list('pk', 'username', 'first_name', 'last_name') \
        .annotate(slots=Count('taught_courses__scheduledcourse'))

    return list(query)
Пример #7
0
def get_work_copies(department, week):
    """
    Get the list of working copies for a target week
    """
    period_filter = PeriodWeeks().get_filter(week=week)
    work_copies = ScheduledCourse.objects \
                    .filter(
                        period_filter,
                        cours__module__train_prog__department=department) \
                    .values_list('copie_travail', flat=True) \
                    .distinct()

    return list(work_copies)
Пример #8
0
 def test_get_weeks_full_period(self):
     pw = PeriodWeeks(year=2018)
     weeks = pw.get_weeks()
     self.assertIn(35, weeks)
     self.assertIn(51, weeks)
     self.assertIn(2, weeks)
Пример #9
0
def get_room_activity_by_day(department, year=None):

    # Return a array containing each room of a department
    # with the number of days a room is unoccupied
    # during a given period.

    # TODO: If the period is not ended occupancy is
    # computed until the current week

    # year : correponds to the first period's year
    period = PeriodWeeks(department=department,
                         year=year,
                         exclude_empty_weeks=True)
    period_filter = period.get_filter()

    # Get room list
    rooms = tuple(RoomGroup.objects \
        .filter(types__department = department) \
        .values_list('name', flat=True)
        .distinct())

    # Filter all the scheduled courses for the period
    scheduled = set()

    if period_filter:
        scheduled.update(ScheduledCourse.objects \
            .filter(
                period_filter,
                copie_travail=0,
                cours__module__train_prog__department=department) \
            .values_list('room__name', 'cours__an', 'cours__semaine', 'creneau__jour') \
            .distinct())

    # Holiday list
    holiday_list = set(get_holiday_list(period))

    # Get the total number of open days
    all_weeks = period.get_weeks()
    nb_open_days = len(all_weeks) * 5

    # Get the number of day per room where the room is not utilized
    unused_days_by_room = []
    for room in rooms:

        # Initialize unused count
        room_context = {'room': room, 'count': 0}
        unused_days_by_room.append(room_context)

        for current_year, weeks in period:
            for current_week in weeks:
                for week_day in tuple(range(1, 6)):

                    # Test if the current day is a holiday
                    if (
                            current_year,
                            current_week,
                            week_day,
                    ) in holiday_list:
                        continue

                    # Test if a course has been realised in the
                    # current room for a given day number
                    room_availability = (room, current_year, current_week,
                                         week_day)
                    if not (room_availability in scheduled):
                        room_context['count'] += 1

    return {'open_days': nb_open_days, 'room_activity': unused_days_by_room}
Пример #10
0
 def test_filter_not_none(self):
     pw = PeriodWeeks(department=self.department, year=1917)
     filter = pw.get_filter()
     self.assertIsNotNone(filter)
Пример #11
0
 def test_get_current_school_year(self, mock_datetime):
     target_datetime = datetime.datetime(2011, 6, 21)
     mock_datetime.datetime.now = Mock(return_value=target_datetime)
     target_year = PeriodWeeks.get_current_school_year()
     self.assertEqual(target_year, 2010)
Пример #12
0
 def test_filter_none_with_exclude_empty_weeks(self):
     pw = PeriodWeeks(department=self.department,
                      year=1917,
                      exclude_empty_weeks=True)
     filter = pw.get_filter()
     self.assertIsNone(filter)
Пример #13
0
 def test_get_holidays_weeks(self):
     period = PeriodWeeks(2018)
     holidays = list(get_holidays_weeks(period))
     self.assertIn(44, holidays)
Пример #14
0
 def test_get_weeks_formated_full_period(self):
     pw = PeriodWeeks(year=2018)
     weeks = pw.get_weeks(format=True)
     self.assertIn((2018, 35), weeks)
     self.assertIn((2018, 51), weeks)
     self.assertIn((2019, 2), weeks)
Пример #15
0
 def test_get_weeks_first_year(self):
     pw = PeriodWeeks(year=2018)
     weeks = pw.get_weeks(year=2018)
     self.assertIn(35, weeks)
     self.assertIn(51, weeks)
     self.assertNotIn(2, weeks)
Пример #16
0
 def test_Q_filter_week_35(self):
     pw = PeriodWeeks(department=self.department, year=2018)
     filter_35 = pw.get_filter(week=35)
     self.assertEqual(
         str(filter_35),
         "(AND: ('cours__an', 2018), ('cours__semaine__in', {35}))")
Пример #17
0
 def test_period_without_parameters(self):
     target_year = PeriodWeeks.get_current_school_year()
     pw = PeriodWeeks(department=self.department)
     self.assertEqual(target_year, pw.start_year)