Beispiel #1
0
    def test_select_single(self):
        # semi-mock practice context
        context = PracticeContext()
        context.get = lambda parameter_name, student=None, task=None: None
        context.get_difficulty_dict = lambda x: {FlowFactors.TASK_BIAS: 0}
        context.get_skill_dict = lambda x: {FlowFactors.STUDENT_BIAS: 0}

        selector = BestScoreTaskSelector()
        result = selector.select([12], student_id=11, practice_context=context)
        self.assertEqual(12, result)
    def test_update_parameters_with_same_predicted_and_reported_flow(self):
        # TODO: unhardcode flow-factors, sth. like
        # context = PracticeContext()
        # context.get = lambda parameter_name=None, task=None, student=None: 1

        context = PracticeContext(
            [
                (FlowFactors.STUDENT_BIAS, 1, None, 0.0),
                (FlowFactors.CONDITIONS, 1, None, 0),
                (FlowFactors.LOOPS, 1, None, 0),
                (FlowFactors.LOGIC_EXPR, 1, None, -1),
                (FlowFactors.COLORS, 1, None, 0),
                (FlowFactors.TOKENS, 1, None, 1),
                (FlowFactors.PITS, 1, None, -1),
                (FlowFactors.TASK_BIAS, None, 2, 3.7),
                (FlowFactors.CONDITIONS, None, 2, 1),
                (FlowFactors.LOOPS, None, 2, 0),
                (FlowFactors.LOGIC_EXPR, None, 2, 0),
                (FlowFactors.COLORS, None, 2, 1),
                (FlowFactors.TOKENS, None, 2, 1),
                (FlowFactors.PITS, None, 2, 0),
                ("solution-count", None, 2, 10),
            ]
        )

        expected_context = PracticeContext(
            [
                (FlowFactors.STUDENT_BIAS, 1, None, 0.15),
                (FlowFactors.CONDITIONS, 1, None, 0),
                (FlowFactors.LOOPS, 1, None, 0),
                (FlowFactors.LOGIC_EXPR, 1, None, -1),
                (FlowFactors.COLORS, 1, None, 0),
                (FlowFactors.TOKENS, 1, None, 1),
                (FlowFactors.PITS, 1, None, -1),
                (FlowFactors.TASK_BIAS, None, 2, 3.7),
                (FlowFactors.CONDITIONS, None, 2, 1),
                (FlowFactors.LOOPS, None, 2, 0),
                (FlowFactors.LOGIC_EXPR, None, 2, 0),
                (FlowFactors.COLORS, None, 2, 1),
                (FlowFactors.TOKENS, None, 2, 1),
                (FlowFactors.PITS, None, 2, 0),
                ("solution-count", None, 2, 10),
            ]
        )

        # action
        parameters_update.update_parameters(
            context, student_id=1, task_id=2, reported_flow=-1.0, predicted_flow=-1.0, last_solved_delta=None
        )

        # assert
        for key in context.get_skill_dict(student=1):
            self.assertAlmostEquals(context.get(key, student=1), expected_context.get(key, student=1))
        for key in context.get_difficulty_dict(task=2):
            self.assertAlmostEquals(context.get(key, task=2), expected_context.get(key, task=2))
    def test_update_parameters_with_same_predicted_and_reported_flow(self):
        # TODO: unhardcode flow-factors, sth. like
        #context = PracticeContext()
        #context.get = lambda parameter_name=None, task=None, student=None: 1

        context = PracticeContext([
            (FlowFactors.STUDENT_BIAS,  1, None, 0.0),
            (FlowFactors.CONDITIONS,    1, None, 0),
            (FlowFactors.LOOPS,         1, None, 0),
            (FlowFactors.LOGIC_EXPR,    1, None, -1),
            (FlowFactors.COLORS,        1, None, 0),
            (FlowFactors.TOKENS,        1, None, 1),
            (FlowFactors.PITS,          1, None, -1),
            (FlowFactors.TASK_BIAS,     None, 2, 3.7),
            (FlowFactors.CONDITIONS,    None, 2, 1),
            (FlowFactors.LOOPS,         None, 2, 0),
            (FlowFactors.LOGIC_EXPR,    None, 2, 0),
            (FlowFactors.COLORS,        None, 2, 1),
            (FlowFactors.TOKENS,        None, 2, 1),
            (FlowFactors.PITS,          None, 2, 0),
            ('solution-count',          None, 2, 10)
        ])

        expected_context = PracticeContext([
            (FlowFactors.STUDENT_BIAS,  1, None, 0.15),
            (FlowFactors.CONDITIONS,    1, None, 0),
            (FlowFactors.LOOPS,         1, None, 0),
            (FlowFactors.LOGIC_EXPR,    1, None, -1),
            (FlowFactors.COLORS,        1, None, 0),
            (FlowFactors.TOKENS,        1, None, 1),
            (FlowFactors.PITS,          1, None, -1),
            (FlowFactors.TASK_BIAS,     None, 2, 3.7),
            (FlowFactors.CONDITIONS,    None, 2, 1),
            (FlowFactors.LOOPS,         None, 2, 0),
            (FlowFactors.LOGIC_EXPR,    None, 2, 0),
            (FlowFactors.COLORS,        None, 2, 1),
            (FlowFactors.TOKENS,        None, 2, 1),
            (FlowFactors.PITS,          None, 2, 0),
            ('solution-count',          None, 2, 10)
        ])

        # action
        parameters_update.update_parameters(context, student_id=1, task_id=2,
                reported_flow=-1.0, predicted_flow=-1.0, last_solved_delta=None)

        # assert
        for key in context.get_skill_dict(student=1):
            self.assertAlmostEquals(
                context.get(key, student=1),
                expected_context.get(key, student=1))
        for key in context.get_difficulty_dict(task=2):
            self.assertAlmostEquals(
                context.get(key, task=2),
                expected_context.get(key, task=2))
Beispiel #4
0
    def test_select_best(self):
        # semi-mock practice context
        context = PracticeContext()
        context.get = lambda parameter_name, student=None, task=None: None
        context.get_difficulty_dict = lambda x: {FlowFactors.TASK_BIAS: 0.4}\
                if x == 12 else {FlowFactors.TASK_BIAS: 0.3}
        context.get_skill_dict = lambda x: {FlowFactors.STUDENT_BIAS: 0.5}

        selector = BestScoreTaskSelector()
        result = selector.select([i for i in range(20)], student_id=11,
                practice_context=context)
        self.assertEqual(12, result)
    def test_update_parameters_without_reported_flow(self):
        context = PracticeContext(
            [
                (FlowFactors.STUDENT_BIAS, 1, None, 0.0),
                (FlowFactors.CONDITIONS, 1, None, 0),
                (FlowFactors.LOOPS, 1, None, 0),
                (FlowFactors.LOGIC_EXPR, 1, None, -1),
                (FlowFactors.COLORS, 1, None, 0),
                (FlowFactors.TOKENS, 1, None, 1),
                (FlowFactors.PITS, 1, None, -1),
                (FlowFactors.TASK_BIAS, None, 2, 3.7),
                (FlowFactors.CONDITIONS, None, 2, 1),
                (FlowFactors.LOOPS, None, 2, 0),
                (FlowFactors.LOGIC_EXPR, None, 2, 0),
                (FlowFactors.COLORS, None, 2, 1),
                (FlowFactors.TOKENS, None, 2, 1),
                (FlowFactors.PITS, None, 2, 0),
                ("solution-count", None, 2, 10),
            ]
        )

        expected_context = PracticeContext(
            [
                (FlowFactors.STUDENT_BIAS, 1, None, 0.15),
                (FlowFactors.CONDITIONS, 1, None, 0),
                (FlowFactors.LOOPS, 1, None, 0),
                (FlowFactors.LOGIC_EXPR, 1, None, -1),
                (FlowFactors.COLORS, 1, None, 0),
                (FlowFactors.TOKENS, 1, None, 1),
                (FlowFactors.PITS, 1, None, -1),
                (FlowFactors.TASK_BIAS, None, 2, 3.7),
                (FlowFactors.CONDITIONS, None, 2, 1),
                (FlowFactors.LOOPS, None, 2, 0),
                (FlowFactors.LOGIC_EXPR, None, 2, 0),
                (FlowFactors.COLORS, None, 2, 1),
                (FlowFactors.TOKENS, None, 2, 1),
                (FlowFactors.PITS, None, 2, 0),
                ("solution-count", None, 2, 10),
            ]
        )

        # action
        parameters_update.update_parameters(
            context, student_id=1, task_id=2, reported_flow=None, predicted_flow=1.2, last_solved_delta=None
        )

        # assert
        for key in context.get_skill_dict(student=1):
            self.assertAlmostEquals(context.get(key, student=1), expected_context.get(key, student=1))
        for key in context.get_difficulty_dict(task=2):
            self.assertAlmostEquals(context.get(key, task=2), expected_context.get(key, task=2))
    def test_update_parameters_without_reported_flow(self):
        context = PracticeContext([
            (FlowFactors.STUDENT_BIAS,  1, None, 0.0),
            (FlowFactors.CONDITIONS,    1, None, 0),
            (FlowFactors.LOOPS,         1, None, 0),
            (FlowFactors.LOGIC_EXPR,    1, None, -1),
            (FlowFactors.COLORS,        1, None, 0),
            (FlowFactors.TOKENS,        1, None, 1),
            (FlowFactors.PITS,          1, None, -1),
            (FlowFactors.TASK_BIAS,     None, 2, 3.7),
            (FlowFactors.CONDITIONS,    None, 2, 1),
            (FlowFactors.LOOPS,         None, 2, 0),
            (FlowFactors.LOGIC_EXPR,    None, 2, 0),
            (FlowFactors.COLORS,        None, 2, 1),
            (FlowFactors.TOKENS,        None, 2, 1),
            (FlowFactors.PITS,          None, 2, 0),
            ('solution-count',          None, 2, 10)
        ])

        expected_context = PracticeContext([
            (FlowFactors.STUDENT_BIAS,  1, None, 0.15),
            (FlowFactors.CONDITIONS,    1, None, 0),
            (FlowFactors.LOOPS,         1, None, 0),
            (FlowFactors.LOGIC_EXPR,    1, None, -1),
            (FlowFactors.COLORS,        1, None, 0),
            (FlowFactors.TOKENS,        1, None, 1),
            (FlowFactors.PITS,          1, None, -1),
            (FlowFactors.TASK_BIAS,     None, 2, 3.7),
            (FlowFactors.CONDITIONS,    None, 2, 1),
            (FlowFactors.LOOPS,         None, 2, 0),
            (FlowFactors.LOGIC_EXPR,    None, 2, 0),
            (FlowFactors.COLORS,        None, 2, 1),
            (FlowFactors.TOKENS,        None, 2, 1),
            (FlowFactors.PITS,          None, 2, 0),
            ('solution-count',          None, 2, 10)
        ])

        # action
        parameters_update.update_parameters(context, student_id=1, task_id=2,
                reported_flow=None, predicted_flow=1.2, last_solved_delta=None)

        # assert
        for key in context.get_skill_dict(student=1):
            self.assertAlmostEquals(
                context.get(key, student=1),
                expected_context.get(key, student=1))
        for key in context.get_difficulty_dict(task=2):
            self.assertAlmostEquals(
                context.get(key, task=2),
                expected_context.get(key, task=2))
Beispiel #7
0
    def test_select_prefer_not_seen_task(self):
        date1 = datetime(2015, 1, 1, 0, 0, 0)
        date2 = datetime(2015, 1, 1, 0, 1, 0)
        context = PracticeContext([
            ('time', None, None, date2),
            ('last-time', 11, 5, None),
            ('last-time', 11, 6, date1)
        ])
        context.get_difficulty_dict = lambda x: {FlowFactors.TASK_BIAS: 0}
        context.get_skill_dict = lambda x: {FlowFactors.STUDENT_BIAS: 0}

        selector = BestScoreTaskSelector()
        result = selector.select([5, 6], student_id=11, practice_context=context)
        self.assertEqual(5, result)
    def test_update_parameters(self):
        context = PracticeContext(
            [
                (FlowFactors.STUDENT_BIAS, 1, None, 0.20),
                (FlowFactors.CONDITIONS, 1, None, 0),
                (FlowFactors.LOOPS, 1, None, 0),
                (FlowFactors.LOGIC_EXPR, 1, None, -1),
                (FlowFactors.COLORS, 1, None, 0),
                (FlowFactors.TOKENS, 1, None, 1),
                (FlowFactors.PITS, 1, None, -1),
                (FlowFactors.TASK_BIAS, None, 2, 3.7),
                (FlowFactors.CONDITIONS, None, 2, 1),
                (FlowFactors.LOOPS, None, 2, 0),
                (FlowFactors.LOGIC_EXPR, None, 2, 0),
                (FlowFactors.COLORS, None, 2, 1),
                (FlowFactors.TOKENS, None, 2, 1),
                (FlowFactors.PITS, None, 2, 0),
                ("solution-count", None, 2, 10),
            ]
        )

        expected_context = PracticeContext(
            [
                (FlowFactors.STUDENT_BIAS, 1, None, 0.622809612962),
                (FlowFactors.CONDITIONS, 1, None, 1),
                (FlowFactors.LOOPS, 1, None, 0),
                (FlowFactors.LOGIC_EXPR, 1, None, -1),
                (FlowFactors.COLORS, 1, None, 1),
                (FlowFactors.TOKENS, 1, None, 1),
                (FlowFactors.PITS, 1, None, -1),
                (FlowFactors.TASK_BIAS, None, 2, 3.657142857142),
                (FlowFactors.CONDITIONS, None, 2, 1),
                (FlowFactors.LOOPS, None, 2, 0),
                (FlowFactors.LOGIC_EXPR, None, 2, 0),
                (FlowFactors.COLORS, None, 2, 1),
                (FlowFactors.TOKENS, None, 2, 1),
                (FlowFactors.PITS, None, 2, 0),
                ("solution-count", None, 2, 10),
            ]
        )
        parameters_update.update_parameters(context, 1, 2, 1, 0, None)

        for key in context.get_skill_dict(1):
            self.assertAlmostEquals(context.get(key, 1, None), expected_context.get(key, 1, None))
        for key in context.get_difficulty_dict(2):
            self.assertAlmostEquals(context.get(key, None, 2), expected_context.get(key, None, 2))
    def test_update_parameters(self):
        context = PracticeContext([
            (FlowFactors.STUDENT_BIAS,  1, None, 0.20),
            (FlowFactors.CONDITIONS,    1, None, 0),
            (FlowFactors.LOOPS,         1, None, 0),
            (FlowFactors.LOGIC_EXPR,    1, None, -1),
            (FlowFactors.COLORS,        1, None, 0),
            (FlowFactors.TOKENS,        1, None, 1),
            (FlowFactors.PITS,          1, None, -1),
            (FlowFactors.TASK_BIAS,     None, 2, 3.7),
            (FlowFactors.CONDITIONS,    None, 2, 1),
            (FlowFactors.LOOPS,         None, 2, 0),
            (FlowFactors.LOGIC_EXPR,    None, 2, 0),
            (FlowFactors.COLORS,        None, 2, 1),
            (FlowFactors.TOKENS,        None, 2, 1),
            (FlowFactors.PITS,          None, 2, 0),
            ('solution-count',          None, 2, 10)
        ])

        expected_context = PracticeContext([
            (FlowFactors.STUDENT_BIAS,  1, None, 0.622809612962),
            (FlowFactors.CONDITIONS,    1, None, 1),
            (FlowFactors.LOOPS,         1, None, 0),
            (FlowFactors.LOGIC_EXPR,    1, None, -1),
            (FlowFactors.COLORS,        1, None, 1),
            (FlowFactors.TOKENS,        1, None, 1),
            (FlowFactors.PITS,          1, None, -1),
            (FlowFactors.TASK_BIAS,     None, 2, 3.657142857142),
            (FlowFactors.CONDITIONS,    None, 2, 1),
            (FlowFactors.LOOPS,         None, 2, 0),
            (FlowFactors.LOGIC_EXPR,    None, 2, 0),
            (FlowFactors.COLORS,        None, 2, 1),
            (FlowFactors.TOKENS,        None, 2, 1),
            (FlowFactors.PITS,          None, 2, 0),
            ('solution-count',          None, 2, 10)
        ])
        parameters_update.update_parameters(context, 1, 2, 1, 0, None)

        for key in context.get_skill_dict(1):
            self.assertAlmostEquals(
                context.get(key, 1, None), expected_context.get(key, 1, None))
        for key in context.get_difficulty_dict(2):
            self.assertAlmostEquals(
                context.get(key, None, 2), expected_context.get(key, None, 2))