当前位置: 首页>>代码示例>>Python>>正文


Python CorrectMap.get_dict方法代码示例

本文整理汇总了Python中capa.correctmap.CorrectMap.get_dict方法的典型用法代码示例。如果您正苦于以下问题:Python CorrectMap.get_dict方法的具体用法?Python CorrectMap.get_dict怎么用?Python CorrectMap.get_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在capa.correctmap.CorrectMap的用法示例。


在下文中一共展示了CorrectMap.get_dict方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_update_from_correctmap

# 需要导入模块: from capa.correctmap import CorrectMap [as 别名]
# 或者: from capa.correctmap.CorrectMap import get_dict [as 别名]
    def test_update_from_correctmap(self):
        # Initialize a CorrectMap with some properties
        self.cmap.set(
            answer_id='1_2_1',
            correctness='correct',
            npoints=5,
            msg='Test message',
            hint='Test hint',
            hintmode='always',
            queuestate={
                'key': 'secretstring',
                'time': '20130228100026'
            }
        )

        self.cmap.set_overall_message("Test message")

        # Create a second cmap, then update it to have the same properties
        # as the first cmap
        other_cmap = CorrectMap()
        other_cmap.update(self.cmap)

        # Assert that it has all the same properties
        self.assertEqual(
            other_cmap.get_overall_message(),
            self.cmap.get_overall_message()
        )

        self.assertEqual(
            other_cmap.get_dict(),
            self.cmap.get_dict()
        )
开发者ID:189140879,项目名称:edx-platform,代码行数:34,代码来源:test_correctmap.py

示例2: update_score

# 需要导入模块: from capa.correctmap import CorrectMap [as 别名]
# 或者: from capa.correctmap.CorrectMap import get_dict [as 别名]
    def update_score(self, score_msg, queuekey):
        """
        Deliver grading response (e.g. from async code checking) to
            the specific ResponseType that requested grading

        Returns an updated CorrectMap
        """
        cmap = CorrectMap()
        cmap.update(self.correct_map)
        for responder in self.responders.values():
            if hasattr(responder, "update_score"):
                # Each LoncapaResponse will update its specific entries in cmap
                #   cmap is passed by reference
                responder.update_score(score_msg, cmap, queuekey)
        self.correct_map.set_dict(cmap.get_dict())
        return cmap
开发者ID:hastexo,项目名称:edx-platform,代码行数:18,代码来源:capa_problem.py

示例3: LoncapaProblem

# 需要导入模块: from capa.correctmap import CorrectMap [as 别名]
# 或者: from capa.correctmap.CorrectMap import get_dict [as 别名]

#.........这里部分代码省略.........

    def do_reset(self):
        """
        Reset internal state to unfinished, with no answers
        """
        self.student_answers = dict()
        self.correct_map = CorrectMap()
        self.done = False

    def set_initial_display(self):
        """
        Set the student's answers to the responders' initial displays, if specified.
        """
        initial_answers = dict()
        for responder in self.responders.values():
            if hasattr(responder, "get_initial_display"):
                initial_answers.update(responder.get_initial_display())

        self.student_answers = initial_answers

    def __unicode__(self):
        return u"LoncapaProblem ({0})".format(self.problem_id)

    def get_state(self):
        """
        Stored per-user session data neeeded to:
            1) Recreate the problem
            2) Populate any student answers.
        """

        return {
            "seed": self.seed,
            "student_answers": self.student_answers,
            "correct_map": self.correct_map.get_dict(),
            "input_state": self.input_state,
            "done": self.done,
        }

    def get_max_score(self):
        """
        Return the maximum score for this problem.
        """
        maxscore = 0
        for responder in self.responders.values():
            maxscore += responder.get_max_score()
        return maxscore

    def get_score(self):
        """
        Compute score for this problem.  The score is the number of points awarded.
        Returns a dictionary {'score': integer, from 0 to get_max_score(),
                              'total': get_max_score()}.
        """
        correct = 0
        for key in self.correct_map:
            try:
                correct += self.correct_map.get_npoints(key)
            except Exception:
                log.error("key=%s, correct_map = %s", key, self.correct_map)
                raise

        if (not self.student_answers) or len(self.student_answers) == 0:
            return {"score": 0, "total": self.get_max_score()}
        else:
            return {"score": correct, "total": self.get_max_score()}
开发者ID:hastexo,项目名称:edx-platform,代码行数:69,代码来源:capa_problem.py

示例4: LoncapaProblem

# 需要导入模块: from capa.correctmap import CorrectMap [as 别名]
# 或者: from capa.correctmap.CorrectMap import get_dict [as 别名]

#.........这里部分代码省略.........
        self.extracted_tree = self._extract_html(self.tree)

    def do_reset(self):
        '''
        Reset internal state to unfinished, with no answers
        '''
        self.student_answers = dict()
        self.correct_map = CorrectMap()
        self.done = False

    def set_initial_display(self):
        """
        Set the student's answers to the responders' initial displays, if specified.
        """
        initial_answers = dict()
        for responder in self.responders.values():
            if hasattr(responder, 'get_initial_display'):
                initial_answers.update(responder.get_initial_display())

        self.student_answers = initial_answers

    def __unicode__(self):
        return u"LoncapaProblem ({0})".format(self.problem_id)

    def get_state(self):
        '''
        Stored per-user session data neeeded to:
            1) Recreate the problem
            2) Populate any student answers.
        '''

        return {'seed': self.seed,
                'student_answers': self.student_answers,
                'correct_map': self.correct_map.get_dict(),
                'input_state': self.input_state,
                'done': self.done}

    def get_max_score(self):
        '''
        Return the maximum score for this problem.
        '''
        maxscore = 0
        for responder in self.responders.values():
            maxscore += responder.get_max_score()
        return maxscore

    def get_score(self):
        """
        Compute score for this problem.  The score is the number of points awarded.
        Returns a dictionary {'score': integer, from 0 to get_max_score(),
                              'total': get_max_score()}.
        """
        correct = 0
        for key in self.correct_map:
            try:
                correct += self.correct_map.get_npoints(key)
            except Exception:
                log.error('key=%s, correct_map = %s' % (key, self.correct_map))
                raise

        if (not self.student_answers) or len(self.student_answers) == 0:
            return {'score': 0,
                    'total': self.get_max_score()}
        else:
            return {'score': correct,
                    'total': self.get_max_score()}
开发者ID:frankrbentley,项目名称:edx-platform,代码行数:70,代码来源:capa_problem.py

示例5: LoncapaProblem

# 需要导入模块: from capa.correctmap import CorrectMap [as 别名]
# 或者: from capa.correctmap.CorrectMap import get_dict [as 别名]

#.........这里部分代码省略.........
    def do_reset(self):
        """
        Reset internal state to unfinished, with no answers
        """
        self.student_answers = dict()
        self.has_saved_answers = False
        self.correct_map = CorrectMap()
        self.done = False

    def set_initial_display(self):
        """
        Set the student's answers to the responders' initial displays, if specified.
        """
        initial_answers = dict()
        for responder in self.responders.values():
            if hasattr(responder, 'get_initial_display'):
                initial_answers.update(responder.get_initial_display())

        self.student_answers = initial_answers

    def __unicode__(self):
        return u"LoncapaProblem ({0})".format(self.problem_id)

    def get_state(self):
        """
        Stored per-user session data neeeded to:
            1) Recreate the problem
            2) Populate any student answers.
        """

        return {'seed': self.seed,
                'student_answers': self.student_answers,
                'has_saved_answers': self.has_saved_answers,
                'correct_map': self.correct_map.get_dict(),
                'input_state': self.input_state,
                'done': self.done}

    def get_max_score(self):
        """
        Return the maximum score for this problem.
        """
        maxscore = 0
        for responder in self.responders.values():
            maxscore += responder.get_max_score()
        return maxscore

    def calculate_score(self, correct_map=None):
        """
        Compute score for this problem.  The score is the number of points awarded.
        Returns a dictionary {'score': integer, from 0 to get_max_score(),
                              'total': get_max_score()}.

        Takes an optional correctness map for use in the rescore workflow.
        """
        if correct_map is None:
            correct_map = self.correct_map
        correct = 0
        for key in correct_map:
            try:
                correct += correct_map.get_npoints(key)
            except Exception:
                log.error('key=%s, correct_map = %s', key, correct_map)
                raise

        return {'score': correct, 'total': self.get_max_score()}
开发者ID:cpennington,项目名称:edx-platform,代码行数:69,代码来源:capa_problem.py

示例6: CorrectMapTest

# 需要导入模块: from capa.correctmap import CorrectMap [as 别名]
# 或者: from capa.correctmap.CorrectMap import get_dict [as 别名]

#.........这里部分代码省略.........
        # 2) correct, None points
        # 3) incorrect, 5 points
        # 4) incorrect, None points
        # 5) correct, 0 points
        self.cmap.set(
            answer_id='1_2_1',
            correctness='correct',
            npoints=5.3
        )

        self.cmap.set(
            answer_id='2_2_1',
            correctness='correct',
            npoints=None
        )

        self.cmap.set(
            answer_id='3_2_1',
            correctness='incorrect',
            npoints=5
        )

        self.cmap.set(
            answer_id='4_2_1',
            correctness='incorrect',
            npoints=None
        )

        self.cmap.set(
            answer_id='5_2_1',
            correctness='correct',
            npoints=0
        )

        # Assert that we get the expected points
        # If points assigned --> npoints
        # If no points assigned and correct --> 1 point
        # If no points assigned and incorrect --> 0 points
        self.assertEqual(self.cmap.get_npoints('1_2_1'), 5.3)
        self.assertEqual(self.cmap.get_npoints('2_2_1'), 1)
        self.assertEqual(self.cmap.get_npoints('3_2_1'), 5)
        self.assertEqual(self.cmap.get_npoints('4_2_1'), 0)
        self.assertEqual(self.cmap.get_npoints('5_2_1'), 0)

    def test_set_overall_message(self):

        # Default is an empty string string
        self.assertEqual(self.cmap.get_overall_message(), "")

        # Set a message that applies to the whole question
        self.cmap.set_overall_message("Test message")

        # Retrieve the message
        self.assertEqual(self.cmap.get_overall_message(), "Test message")

        # Setting the message to None --> empty string
        self.cmap.set_overall_message(None)
        self.assertEqual(self.cmap.get_overall_message(), "")

    def test_update_from_correctmap(self):
        # Initialize a CorrectMap with some properties
        self.cmap.set(
            answer_id='1_2_1',
            correctness='correct',
            npoints=5,
            msg='Test message',
            hint='Test hint',
            hintmode='always',
            queuestate={
                'key': 'secretstring',
                'time': '20130228100026'
            }
        )

        self.cmap.set_overall_message("Test message")

        # Create a second cmap, then update it to have the same properties
        # as the first cmap
        other_cmap = CorrectMap()
        other_cmap.update(self.cmap)

        # Assert that it has all the same properties
        self.assertEqual(
            other_cmap.get_overall_message(),
            self.cmap.get_overall_message()
        )

        self.assertEqual(
            other_cmap.get_dict(),
            self.cmap.get_dict()
        )

    def test_update_from_invalid(self):
        # Should get an exception if we try to update() a CorrectMap
        # with a non-CorrectMap value
        invalid_list = [None, "string", 5, datetime.datetime.today()]

        for invalid in invalid_list:
            with self.assertRaises(Exception):
                self.cmap.update(invalid)
开发者ID:189140879,项目名称:edx-platform,代码行数:104,代码来源:test_correctmap.py


注:本文中的capa.correctmap.CorrectMap.get_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。