Example #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))
Example #3
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))
Example #5
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_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(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_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(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))
Example #10
0
 def test_predict_flow2(self):
     context = PracticeContext([(FlowFactors.STUDENT_BIAS, 11, None, 5.2),
                                (FlowFactors.CONDITIONS, 11, None, 0),
                                (FlowFactors.LOOPS, 11, None, 1.2),
                                (FlowFactors.LOGIC_EXPR, 11, None, 0),
                                (FlowFactors.COLORS, 11, None, 0),
                                (FlowFactors.TOKENS, 11, None, 0),
                                (FlowFactors.PITS, 11, None, -0.1),
                                (FlowFactors.TASK_BIAS, None, 12, 3.7),
                                (FlowFactors.CONDITIONS, None, 12, 0),
                                (FlowFactors.LOOPS, None, 12, 0.5),
                                (FlowFactors.LOGIC_EXPR, None, 12, 0),
                                (FlowFactors.COLORS, None, 12, 0),
                                (FlowFactors.TOKENS, None, 12, 0),
                                (FlowFactors.PITS, None, 12, 2.0)])
     result = predict_flow(student_id=11,
                           task_id=12,
                           practice_context=context)
     self.assertAlmostEquals(activation(1.9), result)
Example #11
0
 def test_predict_zero_flow(self):
     context = PracticeContext([(FlowFactors.STUDENT_BIAS, 11, None, 0),
                                (FlowFactors.CONDITIONS, 11, None, 0),
                                (FlowFactors.LOOPS, 11, None, 0),
                                (FlowFactors.LOGIC_EXPR, 11, None, 0),
                                (FlowFactors.COLORS, 11, None, 0),
                                (FlowFactors.TOKENS, 11, None, 0),
                                (FlowFactors.PITS, 11, None, 0),
                                (FlowFactors.TASK_BIAS, None, 12, 0),
                                (FlowFactors.CONDITIONS, None, 12, 0),
                                (FlowFactors.LOOPS, None, 12, 0),
                                (FlowFactors.LOGIC_EXPR, None, 12, 0),
                                (FlowFactors.COLORS, None, 12, 0),
                                (FlowFactors.TOKENS, None, 12, 0),
                                (FlowFactors.PITS, None, 12, 0)])
     result = predict_flow(student_id=11,
                           task_id=12,
                           practice_context=context)
     self.assertAlmostEquals(0, result)