jupyter / nbgrader

A system for assigning and grading notebooks
https://nbgrader.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.3k stars 317 forks source link

Simple grading python API #1371

Open vpozdnyakov opened 4 years ago

vpozdnyakov commented 4 years ago

Hello there!

I use nbgrader to run competitions at my university. Each student submit an .ipynb file and then the external system (EvalAI) starts evaluation via nbgrader. I don't need to maintain gradebook.db, course structure and so on, because EvalAI already does this. I just only need a python interface that allows me to grade student's submissions and that's it. It could be an interface of the form

def autograde(source_ipynb, solution_ipynb):
    ...
    return {'cell_1': 1.0, 'cell_2': 0.0, 'cell_3': 2.0, ...}

Unfortunately there is no such interface, so I have to recreate a course structure with random username in each iteration of evaluation to save free disk space . It looks like:

def autograde():
    makedirs('source/practice/', exist_ok=True)
    copyfile('source.ipynb', 'source/practice/assignment_1.ipynb')
    username = random_username()
    makedirs('submitted/{}/practice/'.format(username), exist_ok=True)
    copyfile('solution.ipynb', 'submitted/{}/practice/assignment_1.ipynb'.format(username))
    api = NbGraderAPI()
    api.autograde('practice', username, force=True, create=True)
    api.generate_feedback('practice', username, force=True)
    copyfile('feedback/{}/practice/assignment_1.html'.format(username), destination_path)
    score = api.get_student_submissions(username)[0]['code_score']
    rmtree('autograded/{}'.format(username), ignore_errors=True)
    rmtree('feedback/{}'.format(username), ignore_errors=True)
    rmtree('submitted/{}'.format(username), ignore_errors=True)
    return score

I suggest to develop such interface that allow to grade (also generate assignment/feedback) submissions without gradebook.db, course structure and so on.

perllaghu commented 4 years ago

That's because the grading system requires the gradebook.db file.

The workflow is thus:

..... so the gradebook.db database is integral to the process.

There was a proposal to create an external grader..... however I can't find the reference for that.

vpozdnyakov commented 4 years ago

@perllaghu thanks for answer. as I understand there is no prohibitions to do it in memory or using temp files. At least my code above does something like this, but with a few extra-steps for maintenance gradebook.db and course structure that I don't use actually.

perllaghu commented 4 years ago

sqlite in memory.... no problem :)

ajaykushwaha commented 1 year ago

The new notebook is then run [akin to using the double-headed arrow in the notebooks tool-bar]. “Autograded test” cells that run with no errors are given the points (stored in the db) defined

@perllaghu , Can you point out which files are used for this? I am looking more specifically for code , where it decides whether cell ran with or without error.