Created
June 24, 2021 16:06
-
-
Save rubdos/fac49824301ee1fc0a14513e0d127956 to your computer and use it in GitHub Desktop.
Export nbgrader as per-assignment CSV files with per-question columns
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pathlib | |
from nbgrader.plugins import ExportPlugin | |
from nbgrader.api import Gradebook, MissingEntry | |
class VubExporter(ExportPlugin): | |
def export(self, gradebook: Gradebook) -> None: | |
if self.to == "": | |
dest = "grades" | |
else: | |
dest = self.to | |
pathlib.Path(dest).mkdir(parents=True, exist_ok=True) | |
for assignment in gradebook.assignments: | |
keys = [ | |
"student_id", | |
"submission_time", | |
"needs_manual_grade", | |
] | |
# assignment.submissions | |
if len(assignment.notebooks) == 0: | |
continue | |
cells = [] | |
for notebook in assignment.notebooks: | |
for cell in notebook.grade_cells: | |
cells.append(notebook.name + "/" + cell.id) | |
keys.append("cell " + notebook.name + "/" + cell.id + " (" + str(int(cell.max_score)) + ")") | |
fh = open(dest + "/" + assignment.name + ".csv", "w") | |
fh.write(", ".join(keys) + "\n") | |
for student in gradebook.students: | |
try: | |
submission = gradebook.find_submission(assignment.name, student.id) | |
except MissingEntry: | |
continue | |
student_grades = ["0"] * len(cells) | |
for notebook in submission.notebooks: | |
for grade in notebook.grades: | |
key = notebook.name + "/" + grade.cell_id | |
key = cells.index(key) | |
student_grades[key] = str(grade.score) | |
fh.write(", ".join([student.id, submission.timestamp.isoformat(), str(submission.needs_manual_grade)])) | |
fh.write(", ") | |
fh.write(", ".join(student_grades) + "\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment