本文整理汇总了Python中nbgrader.api.Gradebook.find_submission_notebook方法的典型用法代码示例。如果您正苦于以下问题:Python Gradebook.find_submission_notebook方法的具体用法?Python Gradebook.find_submission_notebook怎么用?Python Gradebook.find_submission_notebook使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nbgrader.api.Gradebook
的用法示例。
在下文中一共展示了Gradebook.find_submission_notebook方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_grade
# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import find_submission_notebook [as 别名]
def test_grade(self, gradebook):
"""Can files be graded?"""
self._copy_file("files/submitted-unchanged.ipynb", "source/ps1/p1.ipynb")
run_command('nbgrader assign ps1 --db="{}" '.format(gradebook))
self._copy_file("files/submitted-unchanged.ipynb", "submitted/foo/ps1/p1.ipynb")
self._copy_file("files/submitted-changed.ipynb", "submitted/bar/ps1/p1.ipynb")
run_command('nbgrader autograde ps1 --db="{}"'.format(gradebook))
assert os.path.isfile("autograded/foo/ps1/p1.ipynb")
assert not os.path.isfile("autograded/foo/ps1/timestamp.txt")
assert os.path.isfile("autograded/bar/ps1/p1.ipynb")
assert not os.path.isfile("autograded/bar/ps1/timestamp.txt")
gb = Gradebook(gradebook)
notebook = gb.find_submission_notebook("p1", "ps1", "foo")
assert notebook.score == 1
assert notebook.max_score == 4
assert notebook.needs_manual_grade == False
comment1 = gb.find_comment(0, "p1", "ps1", "foo")
comment2 = gb.find_comment(1, "p1", "ps1", "foo")
assert comment1.comment == "No response."
assert comment2.comment == "No response."
notebook = gb.find_submission_notebook("p1", "ps1", "bar")
assert notebook.score == 2
assert notebook.max_score == 4
assert notebook.needs_manual_grade == True
comment1 = gb.find_comment(0, "p1", "ps1", "bar")
comment2 = gb.find_comment(1, "p1", "ps1", "bar")
assert comment1.comment == None
assert comment2.comment == None
示例2: test_grade
# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import find_submission_notebook [as 别名]
def test_grade(self):
"""Can files be graded?"""
with self._temp_cwd(["files/submitted-unchanged.ipynb", "files/submitted-changed.ipynb"]):
dbpath = self._setup_db()
os.makedirs('source/ps1')
shutil.copy('submitted-unchanged.ipynb', 'source/ps1/p1.ipynb')
self._run_command('nbgrader assign ps1 --db="{}" '.format(dbpath))
os.makedirs('submitted/foo/ps1')
shutil.move('submitted-unchanged.ipynb', 'submitted/foo/ps1/p1.ipynb')
os.makedirs('submitted/bar/ps1')
shutil.move('submitted-changed.ipynb', 'submitted/bar/ps1/p1.ipynb')
self._run_command('nbgrader autograde ps1 --db="{}"'.format(dbpath))
assert os.path.isfile("autograded/foo/ps1/p1.ipynb")
assert not os.path.isfile("autograded/foo/ps1/timestamp.txt")
assert os.path.isfile("autograded/bar/ps1/p1.ipynb")
assert not os.path.isfile("autograded/bar/ps1/timestamp.txt")
gb = Gradebook(dbpath)
notebook = gb.find_submission_notebook("p1", "ps1", "foo")
assert_equal(notebook.score, 1)
assert_equal(notebook.max_score, 4)
assert_equal(notebook.needs_manual_grade, False)
comment1 = gb.find_comment(0, "p1", "ps1", "foo")
comment2 = gb.find_comment(1, "p1", "ps1", "foo")
assert_equal(comment1.comment, "No response.")
assert_equal(comment2.comment, "No response.")
notebook = gb.find_submission_notebook("p1", "ps1", "bar")
assert_equal(notebook.score, 2)
assert_equal(notebook.max_score, 4)
assert_equal(notebook.needs_manual_grade, True)
comment1 = gb.find_comment(0, "p1", "ps1", "bar")
comment2 = gb.find_comment(1, "p1", "ps1", "bar")
assert_equal(comment1.comment, None)
assert_equal(comment2.comment, None)
示例3: test_grade
# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import find_submission_notebook [as 别名]
def test_grade(self, gradebook):
"""Can files be graded?"""
self._copy_file("files/submitted-unchanged.ipynb", "source/ps1/p1.ipynb")
run_command(["nbgrader", "assign", "ps1", "--db", gradebook])
self._copy_file("files/submitted-unchanged.ipynb", "submitted/foo/ps1/p1.ipynb")
self._copy_file("files/submitted-changed.ipynb", "submitted/bar/ps1/p1.ipynb")
run_command(["nbgrader", "autograde", "ps1", "--db", gradebook])
assert os.path.isfile("autograded/foo/ps1/p1.ipynb")
assert not os.path.isfile("autograded/foo/ps1/timestamp.txt")
assert os.path.isfile("autograded/bar/ps1/p1.ipynb")
assert not os.path.isfile("autograded/bar/ps1/timestamp.txt")
gb = Gradebook(gradebook)
notebook = gb.find_submission_notebook("p1", "ps1", "foo")
assert notebook.score == 1
assert notebook.max_score == 7
assert notebook.needs_manual_grade == False
comment1 = gb.find_comment("set_a", "p1", "ps1", "foo")
comment2 = gb.find_comment("baz", "p1", "ps1", "foo")
comment3 = gb.find_comment("quux", "p1", "ps1", "foo")
assert comment1.comment == "No response."
assert comment2.comment == "No response."
assert comment3.comment == "No response."
notebook = gb.find_submission_notebook("p1", "ps1", "bar")
assert notebook.score == 2
assert notebook.max_score == 7
assert notebook.needs_manual_grade == True
comment1 = gb.find_comment("set_a", "p1", "ps1", "bar")
comment2 = gb.find_comment("baz", "p1", "ps1", "bar")
comment2 = gb.find_comment("quux", "p1", "ps1", "bar")
assert comment1.comment == None
assert comment2.comment == None
示例4: GetGrades
# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import find_submission_notebook [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