示例#1
0
    def test_text_difficulty_with_preference(self):

        # with the default estimator (Frequency) the difficulty is EASY
        difficulty = self.user.text_difficulty(self.text, self.english)
        assert difficulty['discrete'] == 'MEDIUM'

        # setting a preference for this user
        p = UserPreference.set_difficulty_estimator(self.db.session, self.user, "frequency")

        # with fk difficulty for the example text is MEDIUM
        difficulty = self.user.text_difficulty(self.text, self.english)
        assert difficulty['discrete'] == 'EASY'
示例#2
0
    def preferred_difficulty_estimator(self):
        """
        :return: Difficulty estimator from preferences,
        otherwise the default one which is FrequencyDifficultyEstimator
        """

        from zeeguu_core.model.user_preference import UserPreference
        # Must have this import here to avoid circular dependency

        preference = UserPreference.get_difficulty_estimator(
            self) or "FleschKincaidDifficultyEstimator"
        logger.debug(f"Difficulty estimator for user {self.id}: {preference}")
        return preference
示例#3
0
    def test_setting_preference(self):

        UserPreference.set_difficulty_estimator(self.db.session, self.user, "fk")
        assert UserPreference.get_difficulty_estimator(self.user) == "fk"
示例#4
0
 def test_no_preference_at_first(self):
     assert not UserPreference.get_difficulty_estimator(self.user)