コード例 #1
0
    def test_problems_by_difficulty(self):
        # Trivial
        problem1 = Problem.objects.get(pk=1)
        # Medium
        problem2 = Problem.objects.get(pk=2)
        problem5 = Problem.objects.get(pk=5)

        trivial_result = list(get_problems_by_difficulty(DIFFICULTY.TRIVIAL).all())
        self.assertEqual(trivial_result, [problem1])
        medium_result = list(get_problems_by_difficulty(DIFFICULTY.MEDIUM).all())
        self.assertIn(problem2, medium_result)
        self.assertIn(problem5, medium_result)
        self.assertEqual(len(medium_result), 2)

        hard_result = list(get_problems_by_difficulty(DIFFICULTY.HARD).all())
        self.assertEqual(hard_result, [])
コード例 #2
0
    def test_problems_by_difficulty(self):
        # Trivial
        problem1 = Problem.objects.get(pk=1)
        # Medium
        problem2 = Problem.objects.get(pk=2)
        problem5 = Problem.objects.get(pk=5)

        trivial_result =\
            list(get_problems_by_difficulty(DIFFICULTY.TRIVIAL).all())
        self.assertEqual(trivial_result, [problem1])
        medium_result =\
            list(get_problems_by_difficulty(DIFFICULTY.MEDIUM).all())
        self.assertIn(problem2, medium_result)
        self.assertIn(problem5, medium_result)
        self.assertEqual(len(medium_result), 2)

        hard_result = list(get_problems_by_difficulty(DIFFICULTY.HARD).all())
        self.assertEqual(hard_result, [])
コード例 #3
0
ファイル: controllers.py プロジェクト: papedaniel/oioioi
    def suggest_task(self, user):
        """Returns a problem object as a suggestion for the user or None if no
           suggestion can be returned
        """
        user_level = Experience(user).current_level

        if user_level >= SuggestLvl5From:
            qset = get_problems_by_difficulty(DIFFICULTY.IMPOSSIBLE)
        elif user_level >= SuggestLvl4From:
            qset = get_problems_by_difficulty(DIFFICULTY.HARD)
        elif user_level >= SuggestLvl3From:
            qset = get_problems_by_difficulty(DIFFICULTY.MEDIUM)
        elif user_level >= SuggestLvl2From:
            qset = get_problems_by_difficulty(DIFFICULTY.EASY)
        else:
            qset = get_problems_by_difficulty(DIFFICULTY.TRIVIAL)

        try:
            return qset.filter(is_public=True).order_by('?').first()
        except Problem.DoesNotExist:
            return None
コード例 #4
0
ファイル: controllers.py プロジェクト: marmistrz/oioioi
    def suggest_task(self, user):
        """Returns a problem object as a suggestion for the user or None if no
           suggestion can be returned
        """
        if not user.is_authenticated():
            return None

        user_level = Experience(user).current_level

        if user_level >= SuggestLvl5From:
            qset = get_problems_by_difficulty(DIFFICULTY.IMPOSSIBLE)
        elif user_level >= SuggestLvl4From:
            qset = get_problems_by_difficulty(DIFFICULTY.HARD)
        elif user_level >= SuggestLvl3From:
            qset = get_problems_by_difficulty(DIFFICULTY.MEDIUM)
        elif user_level >= SuggestLvl2From:
            qset = get_problems_by_difficulty(DIFFICULTY.EASY)
        else:
            qset = get_problems_by_difficulty(DIFFICULTY.TRIVIAL)

        try:
            return qset.filter(is_public=True).order_by('?').first()
        except Problem.DoesNotExist:
            return None