示例#1
0
    def test_get_student_answers(self):
        first_question = RF.MultipleChoiceResponseXMLFactory().build_xml(
            choices=[True, False, False])

        second_question = RF.MultipleChoiceResponseXMLFactory().build_xml(
            choices=[False, True, False])

        self.problem_module.data = self._build_problem(first_question, second_question)
        problem_monitor = ProblemMonitor(self.problem_module)

        cmap = self._build_correct_map('correct', 'incorrect')
        student_answers = self._build_student_answers('choice_0', 'choice_2')

        StudentModuleFactory(course_id=self.course.id,
                             state=self._build_student_module_state(cmap, student_answers))

        problem_monitor.get_student_answers()

        correctness_first_question = problem_monitor.question_monitors[self._build_question_id(0)].correctness
        student_answers_first_question = problem_monitor.question_monitors[self._build_question_id(1)].student_answers
        correctness_second_question = problem_monitor.question_monitors[self._build_question_id(1)].correctness
        student_answers_second_question = problem_monitor.question_monitors[self._build_question_id(1)].student_answers

        self.assertDictContainsSubset(correctness_first_question, {'correct' : 1, 'incorrect' : 0})
        self.assertDictContainsSubset(student_answers_first_question, {'choice_0' : 1})
        self.assertDictContainsSubset(correctness_second_question, {'correct' : 0, 'incorrect' : 1})
        self.assertDictContainsSubset(student_answers_second_question, {'choice_2' : 1})
 def test_preprocess_problem(self):
     problem_tree = self._build_problem(
         RF.MultipleChoiceResponseXMLFactory().build_xml(),
         RF.MultipleChoiceResponseXMLFactory().build_xml(),
         RF.MultipleChoiceResponseXMLFactory().build_xml())
     self.problem_module.data = problem_tree
     problem_monitor = ProblemMonitor(self.problem_module)
     for question_monitor in problem_monitor.question_monitors.values():
         self.assertTrue(
             isinstance(question_monitor, QM.MultipleChoiceMonitor))
示例#3
0
文件: views.py 项目: cuissai/fun-apps
def get_stats(request, course_id, problem_id):
    """ et stats for a single problem (LoncapaProblem).

    The problem id is passed has a GET paramater with 'problem_id' key.

    Args:
         course_id (str): The course id as string.
     """
    start_time = time.time()
    store = modulestore()
    course_key = CourseKey.from_string(course_id)

    problem = utils.fetch_problem(store, course_key, problem_id)
    problem_monitor = ProblemMonitor(problem)
    problem_monitor.get_student_answers()
    tracker.emit("course_dashboard.problem_stats.views.get_stats",
                 {'task-time' : time.time() - start_time})

    return HttpResponse(problem_monitor.get_html())
    def test_get_student_answers(self):
        first_question = RF.MultipleChoiceResponseXMLFactory().build_xml(
            choices=[True, False, False])

        second_question = RF.MultipleChoiceResponseXMLFactory().build_xml(
            choices=[False, True, False])

        self.problem_module.data = self._build_problem(first_question,
                                                       second_question)
        problem_monitor = ProblemMonitor(self.problem_module)

        cmap = self._build_correct_map('correct', 'incorrect')
        student_answers = self._build_student_answers('choice_0', 'choice_2')

        StudentModuleFactory(course_id=self.course.id,
                             state=self._build_student_module_state(
                                 cmap, student_answers))

        problem_monitor.get_student_answers()

        correctness_first_question = problem_monitor.question_monitors[
            self._build_question_id(0)].correctness
        student_answers_first_question = problem_monitor.question_monitors[
            self._build_question_id(1)].student_answers
        correctness_second_question = problem_monitor.question_monitors[
            self._build_question_id(1)].correctness
        student_answers_second_question = problem_monitor.question_monitors[
            self._build_question_id(1)].student_answers

        self.assertDictContainsSubset(correctness_first_question, {
            'correct': 1,
            'incorrect': 0
        })
        self.assertDictContainsSubset(student_answers_first_question,
                                      {'choice_0': 1})
        self.assertDictContainsSubset(correctness_second_question, {
            'correct': 0,
            'incorrect': 1
        })
        self.assertDictContainsSubset(student_answers_second_question,
                                      {'choice_2': 1})
示例#5
0
def get_stats(request, course_id, problem_id):
    """ et stats for a single problem (LoncapaProblem).

    The problem id is passed has a GET paramater with 'problem_id' key.

    Args:
         course_id (str): The course id as string.
     """
    start_time = time.time()
    store = modulestore()
    course_key = CourseKey.from_string(course_id)

    try:
        problem = utils.fetch_problem(store, course_key, problem_id)
    except ItemNotFoundError:
        raise Http404()
    problem_monitor = ProblemMonitor(problem)
    problem_monitor.get_student_answers()
    tracker.emit("course_dashboard.problem_stats.views.get_stats",
                 {'task-time': time.time() - start_time})

    return HttpResponse(problem_monitor.get_html())
    def test_preprocess_problem_with_context(self):
        problem_tree = self._build_problem(
            RF.MultipleChoiceResponseXMLFactory().build_xml(
                question_text='First question, who am I ?'),
            "<p>Second question, whot are you ?</p>",
            RF.MultipleChoiceResponseXMLFactory().build_xml(
                question_text='Choose the best answer.'))

        self.problem_module.data = problem_tree
        problem_monitor = ProblemMonitor(self.problem_module)

        question_monitors = problem_monitor.question_monitors

        self.assertEqual(len(question_monitors), 2)
        self.assertEqual(
            len(question_monitors[self._build_question_id(0)].context), 1)
        self.assertEqual(
            len(question_monitors[self._build_question_id(1)].context), 2)
        for element in question_monitors[self._build_question_id(1)].context:
            self.assertEqual(element.tag, 'p')
    def test_preprocess_problem_with_not_handled_question(self):

        problem_tree = self._build_problem(
            RF.MultipleChoiceResponseXMLFactory().build_xml(),
            RF.SymbolicResponseXMLFactory().build_xml(),
            RF.MultipleChoiceResponseXMLFactory().build_xml())
        self.problem_module.data = problem_tree

        problem_monitor = ProblemMonitor(self.problem_module)
        question_monitors = problem_monitor.question_monitors

        self.assertEqual(len(question_monitors), 3)
        self.assertTrue(
            isinstance(question_monitors[self._build_question_id(0)],
                       QM.MultipleChoiceMonitor))
        self.assertTrue(
            isinstance(question_monitors[self._build_question_id(1)],
                       QM.UnhandledQuestionMonitor))
        self.assertTrue(
            isinstance(question_monitors[self._build_question_id(2)],
                       QM.MultipleChoiceMonitor))