Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Parameters
----------
name : string
the name of the new notebook
assignment : string
the name of an existing assignment
`**kwargs`
additional keyword arguments for the :class:`~nbgrader.api.Notebook` object
Returns
-------
notebook : :class:`~nbgrader.api.Notebook`
"""
notebook = Notebook(
name=name, assignment=self.find_assignment(assignment), **kwargs)
self.db.add(notebook)
try:
self.db.commit()
except (IntegrityError, FlushError) as e:
self.db.rollback()
raise InvalidEntry(*e.args)
return notebook
name : string
the name of the solution cell
notebook : string
the name of the notebook
assignment : string
the name of the assignment
Returns
-------
solution_cell : :class:`~nbgrader.api.SolutionCell`
"""
try:
solution_cell = self.db.query(SolutionCell)\
.join(Notebook, Notebook.id == SolutionCell.notebook_id)\
.join(Assignment, Assignment.id == Notebook.assignment_id)\
.filter(SolutionCell.name == name, Notebook.name == notebook, Assignment.name == assignment)\
.one()
except NoResultFound:
raise MissingEntry("No such solution cell: {}/{}/{}".format(assignment, notebook, name))
return solution_cell
Parameters
----------
name : string
the name of the notebook
assignment : string
the name of the assignment
Returns
-------
notebook : :class:`~nbgrader.api.Notebook`
"""
try:
notebook = self.db.query(Notebook)\
.join(Assignment, Assignment.id == Notebook.assignment_id)\
.filter(Notebook.name == name, Assignment.name == assignment)\
.one()
except NoResultFound:
raise MissingEntry("No such notebook: {}/{}".format(assignment, name))
return notebook
## Overall max scores
Grade.max_score = column_property(
select([GradeCell.max_score])\
.where(Grade.cell_id == GradeCell.id)\
.correlate_except(GradeCell), deferred=True)
Notebook.max_score = column_property(
select([func.coalesce(func.sum(GradeCell.max_score), 0.0)])\
.where(GradeCell.notebook_id == Notebook.id)\
.correlate_except(GradeCell), deferred=True)
SubmittedNotebook.max_score = column_property(
select([Notebook.max_score])\
.where(SubmittedNotebook.notebook_id == Notebook.id)\
.correlate_except(Notebook), deferred=True)
Assignment.max_score = column_property(
select([func.coalesce(func.sum(GradeCell.max_score), 0.0)])\
.where(and_(
Notebook.assignment_id == Assignment.id,
GradeCell.notebook_id == Notebook.id))\
.correlate_except(GradeCell), deferred=True)
SubmittedAssignment.max_score = column_property(
select([Assignment.max_score])\
.where(SubmittedAssignment.assignment_id == Assignment.id)\
.correlate_except(Assignment), deferred=True)
Student.max_score = column_property(
GradeCell.cell_type == "code"))\
.correlate_except(Grade), deferred=True)
SubmittedAssignment.code_score = column_property(
select([func.coalesce(func.sum(Grade.score), 0.0)])\
.where(and_(
SubmittedNotebook.assignment_id == SubmittedAssignment.id,
Grade.notebook_id == SubmittedNotebook.id,
GradeCell.id == Grade.cell_id,
GradeCell.cell_type == "code"))\
.correlate_except(Grade), deferred=True)
## Code max scores
Notebook.max_code_score = column_property(
select([func.coalesce(func.sum(GradeCell.max_score), 0.0)])\
.where(and_(
GradeCell.notebook_id == Notebook.id,
GradeCell.cell_type == "code"))\
.correlate_except(GradeCell), deferred=True)
SubmittedNotebook.max_code_score = column_property(
select([Notebook.max_code_score])\
.where(Notebook.id == SubmittedNotebook.notebook_id)\
.correlate_except(Notebook), deferred=True)
Assignment.max_code_score = column_property(
select([func.coalesce(func.sum(GradeCell.max_score), 0.0)])\
.where(and_(
Notebook.assignment_id == Assignment.id,
GradeCell.notebook_id == Notebook.id,
# subquery for the written scores
written_scores = self.db.query(
SubmittedNotebook.id,
func.sum(Grade.score).label("written_score"),
func.sum(GradeCell.max_score).label("max_written_score"),
).join(SubmittedAssignment, Notebook, Assignment, Student, Grade, GradeCell)\
.filter(GradeCell.cell_type == "markdown")\
.group_by(SubmittedNotebook.id)\
.subquery()
# subquery for needing manual grading
manual_grade = self.db.query(
SubmittedNotebook.id,
exists().where(Grade.needs_manual_grade).label("needs_manual_grade")
).join(SubmittedAssignment, Assignment, Notebook)\
.filter(
Grade.notebook_id == SubmittedNotebook.id,
Grade.needs_manual_grade)\
.group_by(SubmittedNotebook.id)\
.subquery()
# subquery for failed tests
failed_tests = self.db.query(
SubmittedNotebook.id,
exists().where(Grade.failed_tests).label("failed_tests")
).join(SubmittedAssignment, Assignment, Notebook)\
.filter(
Grade.notebook_id == SubmittedNotebook.id,
Grade.failed_tests)\
.group_by(SubmittedNotebook.id)\
.subquery()
the unique id of a student
Returns
-------
notebook : :class:`~nbgrader.api.SubmittedNotebook`
"""
try:
notebook = self.db.query(SubmittedNotebook)\
.join(Notebook, Notebook.id == SubmittedNotebook.notebook_id)\
.join(SubmittedAssignment, SubmittedAssignment.id == SubmittedNotebook.assignment_id)\
.join(Assignment, Assignment.id == SubmittedAssignment.assignment_id)\
.join(Student, Student.id == SubmittedAssignment.student_id)\
.filter(
Notebook.name == notebook,
Assignment.name == assignment,
Student.id == student)\
.one()
except NoResultFound:
raise MissingEntry("No such submitted notebook: {}/{} for {}".format(
assignment, notebook, student))
return notebook
name : string
the name of the grade cell
notebook : string
the name of the notebook
assignment : string
the name of the assignment
Returns
-------
grade_cell : :class:`~nbgrader.api.GradeCell`
"""
try:
grade_cell = self.db.query(GradeCell)\
.join(Notebook, Notebook.id == GradeCell.notebook_id)\
.join(Assignment, Assignment.id == Notebook.assignment_id)\
.filter(
GradeCell.name == name,
Notebook.name == notebook,
Assignment.name == assignment)\
.one()
except NoResultFound:
raise MissingEntry("No such grade cell: {}/{}/{}".format(assignment, notebook, name))
return grade_cell
Returns
-------
score : float
The average written score
"""
assignment = self.find_assignment(assignment_id)
if assignment.num_submissions == 0:
return 0.0
score_sum = self.db.query(func.coalesce(func.sum(Grade.score), 0.0))\
.join(GradeCell, Notebook, Assignment)\
.filter(and_(
Assignment.name == assignment_id,
Notebook.assignment_id == Assignment.id,
GradeCell.notebook_id == Notebook.id,
Grade.cell_id == GradeCell.id,
GradeCell.cell_type == "markdown")).scalar()
return score_sum / assignment.num_submissions
## Needs manual grade
SubmittedNotebook.needs_manual_grade = column_property(
exists().where(and_(
Grade.notebook_id == SubmittedNotebook.id,
Grade.needs_manual_grade))\
.correlate_except(Grade), deferred=True)
SubmittedAssignment.needs_manual_grade = column_property(
exists().where(and_(
SubmittedNotebook.assignment_id == SubmittedAssignment.id,
Grade.notebook_id == SubmittedNotebook.id,
Grade.needs_manual_grade))\
.correlate_except(Grade), deferred=True)
Notebook.needs_manual_grade = column_property(
exists().where(and_(
Notebook.id == SubmittedNotebook.notebook_id,
Grade.notebook_id == SubmittedNotebook.id,
Grade.needs_manual_grade))\
.correlate_except(Grade), deferred=True)
## Overall scores
SubmittedNotebook.score = column_property(
select([func.coalesce(func.sum(Grade.score), 0.0)])\
.where(Grade.notebook_id == SubmittedNotebook.id)\
.correlate_except(Grade), deferred=True)
SubmittedAssignment.score = column_property(
select([func.coalesce(func.sum(Grade.score), 0.0)])\