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


Python Gradebook.find_grade方法代码示例

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


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

示例1: GetGrades

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import find_grade [as 别名]
class GetGrades(NbGraderPreprocessor):
    """Preprocessor for saving grades from the database to the notebook"""

    def preprocess(self, nb, resources):
        # pull information from the resources
        self.notebook_id = resources['nbgrader']['notebook']
        self.assignment_id = resources['nbgrader']['assignment']
        self.student_id = resources['nbgrader']['student']
        self.db_url = resources['nbgrader']['db_url']

        # connect to the database
        self.gradebook = Gradebook(self.db_url)

        self.comment_index = 0

        # process the cells
        nb, resources = super(GetGrades, self).preprocess(nb, resources)

        submission = self.gradebook.find_submission_notebook(
            self.notebook_id, self.assignment_id, self.student_id)
        resources['nbgrader']['score'] = submission.score
        resources['nbgrader']['max_score'] = submission.max_score

        return nb, resources

    def _get_comment(self, cell, resources):
        """Graders can optionally add comments to the student's solutions, so
        add the comment information into the database if it doesn't
        already exist. It should NOT overwrite existing comments that
        might have been added by a grader already.

        """

        # retrieve or create the comment object from the database
        comment = self.gradebook.find_comment(
            self.comment_index,
            self.notebook_id,
            self.assignment_id,
            self.student_id)

        # save it in the notebook
        cell.metadata.nbgrader['comment'] = comment.to_dict()

        # update the number of comments we have inserted
        self.comment_index += 1

    def _get_score(self, cell, resources):
        grade = self.gradebook.find_grade(
            cell.metadata['nbgrader']['grade_id'],
            self.notebook_id,
            self.assignment_id,
            self.student_id)

        cell.metadata.nbgrader['score'] = grade.score
        cell.metadata.nbgrader['points'] = grade.max_score

    def preprocess_cell(self, cell, resources, cell_index):
        # if it's a solution cell, then add a comment
        if utils.is_solution(cell):
            self._get_comment(cell, resources)

        # if it's a grade cell, the add a grade
        if utils.is_grade(cell):
            self._get_score(cell, resources)

        return cell, resources
开发者ID:haraldschilly,项目名称:nbgrader,代码行数:68,代码来源:getgrades.py

示例2: TestSaveAutoGrades

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import find_grade [as 别名]
class TestSaveAutoGrades(TestBase):

    def setup(self):
        super(TestSaveAutoGrades, self).setup()
        db_url = self._init_db()
        self.gb = Gradebook(db_url)
        self.gb.add_assignment("ps0")
        self.gb.add_student("bar")

        self.preprocessor1 = SaveCells()
        self.preprocessor2 = SaveAutoGrades()
        self.resources = {
            "nbgrader": {
                "db_url": db_url,
                "assignment": "ps0",
                "notebook": "test",
                "student": "bar"
            }
        }

    def test_grade_correct_code(self):
        """Is a passing code cell correctly graded?"""
        cell = self._create_grade_cell("hello", "code", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        self.preprocessor2.preprocess(nb, self.resources)

        grade_cell = self.gb.find_grade("foo", "test", "ps0", "bar")
        assert_equal(grade_cell.score, 1)
        assert_equal(grade_cell.max_score, 1)
        assert_equal(grade_cell.auto_score, 1)
        assert_equal(grade_cell.manual_score, None)
        assert not grade_cell.needs_manual_grade

    def test_grade_incorrect_code(self):
        """Is a failing code cell correctly graded?"""
        cell = self._create_grade_cell("hello", "code", "foo", 1)
        cell.outputs = [new_output('error', ename="NotImplementedError", evalue="", traceback=["error"])]
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        self.preprocessor2.preprocess(nb, self.resources)

        grade_cell = self.gb.find_grade("foo", "test", "ps0", "bar")
        assert_equal(grade_cell.score, 0)
        assert_equal(grade_cell.max_score, 1)
        assert_equal(grade_cell.auto_score, 0)
        assert_equal(grade_cell.manual_score, None)
        assert not grade_cell.needs_manual_grade

    def test_grade_unchanged_markdown(self):
        """Is an unchanged markdown cell correctly graded?"""
        cell = self._create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        self.preprocessor2.preprocess(nb, self.resources)

        grade_cell = self.gb.find_grade("foo", "test", "ps0", "bar")
        assert_equal(grade_cell.score, 0)
        assert_equal(grade_cell.max_score, 1)
        assert_equal(grade_cell.auto_score, 0)
        assert_equal(grade_cell.manual_score, None)
        assert not grade_cell.needs_manual_grade

    def test_grade_changed_markdown(self):
        """Is a changed markdown cell correctly graded?"""
        cell = self._create_grade_and_solution_cell("hello", "markdown", "foo", 1)
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        cell.source = "hello!"
        self.preprocessor2.preprocess(nb, self.resources)

        grade_cell = self.gb.find_grade("foo", "test", "ps0", "bar")
        assert_equal(grade_cell.score, 0)
        assert_equal(grade_cell.max_score, 1)
        assert_equal(grade_cell.auto_score, None)
        assert_equal(grade_cell.manual_score, None)
        assert grade_cell.needs_manual_grade

    def test_comment_unchanged_code(self):
        """Is an unchanged code cell given the correct comment?"""
        cell = self._create_solution_cell("hello", "code")
        nb = new_notebook()
        nb.cells.append(cell)
        self.preprocessor1.preprocess(nb, self.resources)
        self.gb.add_submission("ps0", "bar")
        self.preprocessor2.preprocess(nb, self.resources)

        comment = self.gb.find_comment(0, "test", "ps0", "bar")
        assert_equal(comment.comment, "No response.")

    def test_comment_changed_code(self):
        """Is a changed code cell given the correct comment?"""
#.........这里部分代码省略.........
开发者ID:redSlug,项目名称:nbgrader,代码行数:103,代码来源:test_saveautogrades.py

示例3: SaveAutoGrades

# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import find_grade [as 别名]
class SaveAutoGrades(NbGraderPreprocessor):
    """Preprocessor for saving out the autograder grades into a database"""

    def preprocess(self, nb, resources):
        # pull information from the resources
        self.notebook_id = resources['nbgrader']['notebook']
        self.assignment_id = resources['nbgrader']['assignment']
        self.student_id = resources['nbgrader']['student']
        self.db_url = resources['nbgrader']['db_url']

        # connect to the database
        self.gradebook = Gradebook(self.db_url)
        self.comment_index = 0

        # process the cells
        nb, resources = super(SaveAutoGrades, self).preprocess(nb, resources)

        return nb, resources

    def _add_score(self, cell, resources):
        """Graders can override the autograder grades, and may need to
        manually grade written solutions anyway. This function adds
        score information to the database if it doesn't exist. It does
        NOT override the 'score' field, as this is the manual score
        that might have been provided by a grader.

        """
        # these are the fields by which we will identify the score
        # information
        grade = self.gradebook.find_grade(
            cell.metadata['nbgrader']['grade_id'],
            self.notebook_id,
            self.assignment_id,
            self.student_id)

        # determine what the grade is
        auto_score, max_score = utils.determine_grade(cell)
        grade.auto_score = auto_score
        self.gradebook.db.commit()
        self.log.debug(grade)

    def _add_comment(self, cell, resources):
        comment = self.gradebook.find_comment(
            self.comment_index,
            self.notebook_id,
            self.assignment_id,
            self.student_id)

        if comment.comment:
            return
        elif cell.metadata.nbgrader.get("checksum", None) == utils.compute_checksum(cell):
            comment.comment = "No response."
            self.gradebook.db.commit()
            self.log.debug(comment)

    def preprocess_cell(self, cell, resources, cell_index):
        # if it's a grade cell, the add a grade
        if utils.is_grade(cell):
            self._add_score(cell, resources)

        if utils.is_solution(cell):
            self._add_comment(cell, resources)
            self.comment_index += 1

        return cell, resources
开发者ID:haraldschilly,项目名称:nbgrader,代码行数:67,代码来源:saveautogrades.py


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