Skip to content

Commit

Permalink
Add raw cell support
Browse files Browse the repository at this point in the history
  • Loading branch information
KrKOo committed Oct 9, 2024
1 parent be97e17 commit de85452
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
42 changes: 21 additions & 21 deletions nbgrader/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ def max_score(cls):
#: The cell type, either "code" or "markdown"
@declared_attr
def cell_type(cls):
return Column(Enum("code", "markdown", name="grade_cell_type", validate_strings=True), nullable=False)
return Column(Enum("code", "markdown", "raw", name="grade_cell_type", validate_strings=True), nullable=False)


class GradeCell(BaseCell, GradedMixin):
Expand Down Expand Up @@ -381,7 +381,7 @@ class SourceCell(Base):
name = Column(String(128), nullable=False)

#: The cell type, either "code" or "markdown"
cell_type = Column(Enum("code", "markdown", name="source_cell_type", validate_strings=True), nullable=False)
cell_type = Column(Enum("code", "markdown", "raw", name="source_cell_type", validate_strings=True), nullable=False)

#: Whether the cell is locked (e.g. the source saved in the database should
#: be used to overwrite the source of students' cells)
Expand Down Expand Up @@ -1082,7 +1082,7 @@ def __repr__(self):
.where(and_(
Grade.notebook_id == SubmittedNotebook.id,
GradeCell.id == Grade.cell_id,
GradeCell.cell_type == "markdown"))
GradeCell.cell_type in ("markdown", "raw")))
.correlate_except(Grade)
.scalar_subquery(), deferred=True)

Expand All @@ -1092,7 +1092,7 @@ def __repr__(self):
SubmittedNotebook.assignment_id == SubmittedAssignment.id,
Grade.notebook_id == SubmittedNotebook.id,
GradeCell.id == Grade.cell_id,
GradeCell.cell_type == "markdown"))
GradeCell.cell_type in ("markdown", "raw")))
.correlate_except(Grade)
.scalar_subquery(), deferred=True)

Expand All @@ -1104,7 +1104,7 @@ def __repr__(self):
.select_from(GradeCell)
.where(and_(
GradeCell.notebook_id == Notebook.id,
GradeCell.cell_type == "markdown"))
GradeCell.cell_type in ("markdown", "raw")))
.correlate_except(GradeCell)
.scalar_subquery(), deferred=True)

Expand All @@ -1120,7 +1120,7 @@ def __repr__(self):
.where(and_(
Notebook.assignment_id == Assignment.id,
GradeCell.notebook_id == Notebook.id,
GradeCell.cell_type == "markdown"))
GradeCell.cell_type in ("markdown", "raw")))
.correlate_except(GradeCell)
.scalar_subquery(), deferred=True)

Expand Down Expand Up @@ -1193,7 +1193,7 @@ def __repr__(self):
.where(and_(
Grade.notebook_id == SubmittedNotebook.id,
TaskCell.id == Grade.cell_id,
TaskCell.cell_type == "markdown"))
TaskCell.cell_type in ("markdown", "raw")))
.correlate_except(Grade)
.scalar_subquery(), deferred=True)

Expand All @@ -1203,7 +1203,7 @@ def __repr__(self):
SubmittedNotebook.assignment_id == SubmittedAssignment.id,
Grade.notebook_id == SubmittedNotebook.id,
TaskCell.id == Grade.cell_id,
TaskCell.cell_type == "markdown"))
TaskCell.cell_type in ("markdown", "raw")))
.correlate_except(Grade)
.scalar_subquery(), deferred=True)

Expand All @@ -1215,7 +1215,7 @@ def __repr__(self):
.select_from(TaskCell)
.where(and_(
TaskCell.notebook_id == Notebook.id,
TaskCell.cell_type == "markdown"))
TaskCell.cell_type in ("markdown", "raw")))
.correlate_except(TaskCell)
.scalar_subquery(), deferred=True)

Expand All @@ -1231,7 +1231,7 @@ def __repr__(self):
.where(and_(
Notebook.assignment_id == Assignment.id,
TaskCell.notebook_id == Notebook.id,
TaskCell.cell_type == "markdown"))
TaskCell.cell_type in ("markdown", "raw")))
.correlate_except(TaskCell)
.scalar_subquery(), deferred=True)

Expand Down Expand Up @@ -2826,7 +2826,7 @@ def average_assignment_task_score(self, assignment_id):
Notebook.assignment_id == Assignment.id,
TaskCell.notebook_id == Notebook.id,
Grade.cell_id == TaskCell.id,
TaskCell.cell_type == "markdown")).scalar()
TaskCell.cell_type in ("markdown", "raw"))).scalar()
return score_sum / assignment.num_submissions

def average_notebook_score(self, notebook_id: str, assignment_id: str) -> float:
Expand Down Expand Up @@ -2920,7 +2920,7 @@ def average_notebook_written_score(self, notebook_id: str, assignment_id: str) -
Notebook.assignment_id == Assignment.id,
GradeCell.notebook_id == Notebook.id,
Grade.cell_id == GradeCell.id,
GradeCell.cell_type == "markdown")).scalar()
GradeCell.cell_type in ("markdown", "raw"))).scalar()
return score_sum / notebook.num_submissions

def average_notebook_task_score(self, notebook_id: str, assignment_id: str) -> float:
Expand Down Expand Up @@ -2953,7 +2953,7 @@ def average_notebook_task_score(self, notebook_id: str, assignment_id: str) -> f
Notebook.assignment_id == Assignment.id,
TaskCell.notebook_id == Notebook.id,
Grade.cell_id == TaskCell.id,
TaskCell.cell_type == "markdown")).scalar()
TaskCell.cell_type in ("markdown", "raw"))).scalar()
return score_sum / notebook.num_submissions

def student_dicts(self):
Expand Down Expand Up @@ -3038,7 +3038,7 @@ def submission_dicts(self, assignment_id):
func.sum(GradeCell.max_score).label("max_written_score"),
).select_from(SubmittedAssignment
).join(SubmittedNotebook).join(Notebook).join(Assignment).join(Student).join(Grade).join(GradeCell)\
.filter(GradeCell.cell_type == "markdown")\
.filter(GradeCell.cell_type in ("markdown", "raw"))\
.group_by(SubmittedAssignment.id)\
.subquery()

Expand All @@ -3049,7 +3049,7 @@ def submission_dicts(self, assignment_id):
func.sum(TaskCell.max_score).label("max_task_score"),
).select_from(SubmittedAssignment
).join(SubmittedNotebook).join(Notebook).join(Assignment).join(Student).join(Grade).join(TaskCell)\
.filter(TaskCell.cell_type == "markdown")\
.filter(TaskCell.cell_type in ("markdown", "raw"))\
.group_by(SubmittedAssignment.id)\
.subquery()

Expand Down Expand Up @@ -3082,7 +3082,7 @@ def submission_dicts(self, assignment_id):
func.sum(GradeCell.max_score).label("max_score"),
).select_from(SubmittedAssignment
).join(SubmittedNotebook).join(Grade).join(GradeCell)\
.filter(GradeCell.cell_type == "markdown")\
.filter(GradeCell.cell_type in ("markdown", "raw"))\
.group_by(SubmittedAssignment.id),

self.db.query(
Expand All @@ -3091,7 +3091,7 @@ def submission_dicts(self, assignment_id):
func.sum(TaskCell.max_score).label("max_score"),
).select_from(SubmittedAssignment
).join(SubmittedNotebook).join(Grade).join(TaskCell)\
.filter(TaskCell.cell_type == "markdown")\
.filter(TaskCell.cell_type in ("markdown", "raw"))\
.group_by(SubmittedAssignment.id)
).subquery()

Expand Down Expand Up @@ -3186,7 +3186,7 @@ def notebook_submission_dicts(self, notebook_id, assignment_id):
func.sum(GradeCell.max_score).label("max_written_score"),
).select_from(SubmittedNotebook
).join(SubmittedAssignment).join(Notebook).join(Assignment).join(Student).join(Grade).join(GradeCell)\
.filter(GradeCell.cell_type == "markdown")\
.filter(GradeCell.cell_type in ("markdown", "raw"))\
.group_by(SubmittedNotebook.id)\
.subquery()
# subquery for the written scores
Expand All @@ -3196,7 +3196,7 @@ def notebook_submission_dicts(self, notebook_id, assignment_id):
func.sum(TaskCell.max_score).label("max_task_score"),
).select_from(SubmittedNotebook
).join(SubmittedAssignment).join(Notebook).join(Assignment).join(Student).join(Grade).join(TaskCell)\
.filter(TaskCell.cell_type == "markdown")\
.filter(TaskCell.cell_type in ("markdown", "raw"))\
.group_by(SubmittedNotebook.id)\
.subquery()

Expand Down Expand Up @@ -3224,7 +3224,7 @@ def notebook_submission_dicts(self, notebook_id, assignment_id):
func.sum(GradeCell.max_score).label("max_score"),
).select_from(SubmittedNotebook
).join(Grade).join(GradeCell)\
.filter(GradeCell.cell_type == "markdown")\
.filter(GradeCell.cell_type in ("markdown", "raw"))\
.group_by(SubmittedNotebook.id),

self.db.query(
Expand All @@ -3233,7 +3233,7 @@ def notebook_submission_dicts(self, notebook_id, assignment_id):
func.sum(TaskCell.max_score).label("max_score"),
).select_from(SubmittedNotebook
).join(Grade).join(TaskCell)\
.filter(TaskCell.cell_type == "markdown")\
.filter(TaskCell.cell_type in ("markdown", "raw"))\
.group_by(SubmittedNotebook.id)
).subquery()

Expand Down
12 changes: 6 additions & 6 deletions nbgrader/nbgraderformat/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,17 @@ def validate_cell(self, cell: NotebookNode) -> None:

# check that markdown cells are grade AND solution (not either/or)
if not task:
if cell.cell_type == "markdown" and grade and not solution:
if cell.cell_type in ("markdown", "raw") and grade and not solution:
raise ValidationError(
"Markdown grade cell '{}' is not marked as a solution cell".format(
"Markdown/raw grade cell '{}' is not marked as a solution cell".format(
meta['grade_id']))
if cell.cell_type == "markdown" and not grade and solution:
if cell.cell_type in ("markdown", "raw") and not grade and solution:
raise ValidationError(
"Markdown solution cell is not marked as a grade cell: {}".format(cell.source))
"Markdown/raw solution cell is not marked as a grade cell: {}".format(cell.source))
else:
if cell.cell_type != "markdown":
if cell.cell_type not in ("markdown", "raw"):
raise ValidationError(
"Task cells have to be markdown: {}".format(cell.source))
"Task cells have to be markdown or raw: {}".format(cell.source))

def validate_nb(self, nb: NotebookNode) -> None:
super(MetadataValidatorV3, self).validate_nb(nb)
Expand Down

0 comments on commit de85452

Please sign in to comment.