本文整理汇总了Python中nbgrader.api.Gradebook.find_student方法的典型用法代码示例。如果您正苦于以下问题:Python Gradebook.find_student方法的具体用法?Python Gradebook.find_student怎么用?Python Gradebook.find_student使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nbgrader.api.Gradebook
的用法示例。
在下文中一共展示了Gradebook.find_student方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_assignment
# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import find_student [as 别名]
def init_assignment(self, assignment_id, student_id):
super(AutogradeApp, self).init_assignment(assignment_id, student_id)
# try to get the student from the database, and throw an error if it
# doesn't exist
gb = Gradebook(self.db_url)
try:
gb.find_student(student_id)
except MissingEntry:
if self.create_student:
self.log.warning("Creating student with ID '%s'", student_id)
gb.add_student(student_id)
else:
self.fail("No student with ID '%s' exists in the database", student_id)
# try to read in a timestamp from file
src_path = self._format_source(assignment_id, student_id)
timestamp = self._get_existing_timestamp(src_path)
if timestamp:
submission = gb.update_or_create_submission(
assignment_id, student_id, timestamp=timestamp)
self.log.info("%s submitted at %s", submission, timestamp)
# if the submission is late, print out how many seconds late it is
if timestamp and submission.total_seconds_late > 0:
self.log.warning("%s is %s seconds late", submission, submission.total_seconds_late)
else:
submission = gb.update_or_create_submission(assignment_id, student_id)
# copy files over from the source directory
self.log.info("Overwriting files with master versions from the source directory")
dest_path = self._format_dest(assignment_id, student_id)
source_path = self.directory_structure.format(
nbgrader_step=self.source_directory,
student_id='.',
assignment_id=assignment_id)
source_files = utils.find_all_files(source_path, self.ignore + ["*.ipynb"])
# copy them to the build directory
for filename in source_files:
dest = os.path.join(dest_path, os.path.relpath(filename, source_path))
ensure_dir_exists(os.path.dirname(dest))
if not os.path.normpath(dest) == os.path.normpath(filename):
self.log.info("Linking %s -> %s", filename, dest)
link_or_copy(filename, dest)
# ignore notebooks that aren't in the database
notebooks = []
for notebook in self.notebooks:
notebook_id = os.path.splitext(os.path.basename(notebook))[0]
try:
gb.find_notebook(notebook_id, assignment_id)
except MissingEntry:
self.log.warning("Skipping unknown notebook: %s", notebook)
continue
else:
notebooks.append(notebook)
self.notebooks = notebooks
示例2: SaveAutoGrades
# 需要导入模块: from nbgrader.api import Gradebook [as 别名]
# 或者: from nbgrader.api.Gradebook import find_student [as 别名]
class SaveAutoGrades(Preprocessor):
"""Preprocessor for saving out the autograder grades into a MongoDB"""
db_name = Unicode("gradebook", config=True, help="Database name")
db_ip = Unicode("localhost", config=True, help="IP address for the database")
db_port = Integer(27017, config=True, help="Port for the database")
assignment_id = Unicode(u'assignment', config=True, help="Assignment ID")
def preprocess(self, nb, resources):
# connect to the mongo database
self.gradebook = Gradebook(self.db_name, ip=self.db_ip, port=self.db_port)
self.student = self.gradebook.find_student(
student_id=resources['nbgrader']['student_id'])
self.assignment = self.gradebook.find_assignment(
assignment_id=self.assignment_id)
self.notebook = self.gradebook.find_or_create_notebook(
notebook_id=resources['unique_key'],
student=self.student,
assignment=self.assignment)
# keep track of the number of comments we add
self.comment_index = 0
# process the cells
nb, resources = super(SaveAutoGrades, self).preprocess(nb, resources)
return nb, resources
def _add_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_or_create_comment(
notebook=self.notebook,
comment_id=self.comment_index)
# update the number of comments we have inserted
self.comment_index += 1
self.log.debug(comment)
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_or_create_grade(
notebook=self.notebook,
grade_id=cell.metadata['nbgrader']['grade_id'])
# set the maximum earnable score
points = float(cell.metadata['nbgrader']['points'])
grade.max_score = points
# If it's a code cell and it threw an error, then they get
# zero points, otherwise they get max_score points. If it's a
# text cell, we can't autograde it.
if cell.cell_type == 'code':
grade.autoscore = points
for output in cell.outputs:
if output.output_type == 'pyerr':
grade.autoscore = 0
break
else:
grade.autoscore = None
# Update the grade information and print it out
self.gradebook.update_grade(grade)
self.log.debug(grade)
def preprocess_cell(self, cell, resources, cell_index):
# if it's a solution cell, then add a comment
if utils.is_solution(cell):
self._add_comment(cell, resources)
# if it's a grade cell, the add a grade
if utils.is_grade(cell):
self._add_score(cell, resources)
return cell, resources