Exemplo n.º 1
0
    def handle(self, *args, **options):
        tt = Timetable.objects.get(slug=options['timetable_slug'])
        method_name = options['method_name'][0]
        GroupSizeHint.objects.filter(method=method_name).delete()

        for a in tt.activities.filter(type='P'):
            enrollment_types = [4, 26]
            for group in a.groups.all().exclude(shortName__contains='PAD'):
                if GroupSizeHint.objects.filter(
                        group=group, method=method_name).count() == 0:
                    GroupSizeHint.size_from_enrollments(
                        group,
                        tt.groupset,
                        enrollment_types=enrollment_types,
                        method=method_name)
            enrollment_types = sorted(
                [e[0] for e in ENROLMENTTYPES if e[0] not in [4, 26]])
            try:
                group = a.groups.get(shortName__contains='PAD')
                if GroupSizeHint.objects.filter(
                        group=group, method=method_name).count() == 0:
                    se = StudentEnrollment.objects.filter(
                        groupset=tt.groupset,
                        subject=a.subject,
                        enrollment_type__in=enrollment_types)
                    GroupSizeHint(
                        method=method_name,
                        size=se.count(),
                        group=group,
                    ).save()
            except:
                print("No PAD group for {}".format(a.name, a.type))
        GroupSizeHint.objects.filter(size=0, method=method_name).delete()
Exemplo n.º 2
0
    def test_group_size_hint_max(self):
        strategy = 'max'

        methods = ['1', '2', '3']
        expected = 12
        val = GroupSizeHint.strategy(self.g1, methods, strategy)
        self.assertEqual(
            val, expected,
            "Strategy '{}' for {} and methods {} should return {}".format(
                strategy, self.g1, methods, expected))

        val = GroupSizeHint.strategy(self.g1, ['non', 'existing'], strategy)
        self.assertIsNone(val,
                          "If no hints are available None should be returned")

        methods = ['1', '2', '3']
        expected = 0
        val = GroupSizeHint.strategy(self.g2, methods, strategy)
        self.assertEqual(
            val, expected,
            "Strategy '{}' for {} and methods {} should return {}".format(
                strategy,
                self.g2,
                methods,
                expected,
            ))
Exemplo n.º 3
0
    def test_group_size_hint_first_not_zero(self):
        strategy = 'first-non-zero'

        methods = ['1', '2', '3']
        expected = 10
        val = GroupSizeHint.strategy(self.g1, methods, strategy)
        self.assertEqual(
            val, expected,
            "Strategy '{}' for {} and methods {} should return {}".format(
                strategy, self.g1, methods, expected))

        methods = ['1', '2', '3']
        val = GroupSizeHint.strategy(self.g2, methods, strategy)
        self.assertIsNone(val,
                          "If no hints are available None should be returned")
Exemplo n.º 4
0
 def test_group_size_hint_incorrect_strategy(self):
     with self.assertRaises(KeyError):
         GroupSizeHint.strategy(self.g1, ["unknown"], 'Weird strategy name')