Public
Snippet $51 authored by Steve Weber

nbgrader.md

Edited
nbgrader.md
Raw

Using nbgrader on local exchange

using the local /srv/nbgrader/exchange to manage files and enable formgrader.

Instructor

Using your user from the jupyter website, access [create > terminal].

Note: replace <course_id> with the name of your course.

First thing we willl do is create the the files needed for the course. Laying out the files for your class can be done using nbgrader quickstart.

cd ~
nbgrader quickstart <course_id>

Users connecting to jupyter wont have some nbgrader extensions enabled by default so we will want to do this for them. We will also want to give them a default nbgrader_config.py so they point to the correct course. To preform this step We'll need to use sudo to switch to root.

sudo su

cat > /runonce << 'EOF'
echo "******** $USER ********"
cd $HOME
nbgrader extension activate
cat > $HOME/nbgrader_config.py << 'EOFF'
c = get_config()
c.NbGrader.course_id = '<course_id>'
EOFF
EOF
vi /runonce

for u in `ls /home` ; do 
    sudo -Hs -u $u sh /runonce
done

# use exit to return to your user
exit

Update the course/nbgrader_config so it has your:

  • course_id
  • students
  • formgrade config
    • graders
    • proxy_token
    • hubapi_token
cd ~/<course_id>
sudo cat /etc/jupyter/jupyterhub_config.py
# set the following using the values found in the file above.
PROXY_TOKEN=<proxy_auth_token>
HUBAPI_TOKEN=<service_tokens[yours]>

mv nbgrader_config.py example_nbgrader_config.py
cat > nbgrader_config.py << EOFFF
c = get_config()
c.NbGrader.course_id = '$(basename $(pwd))'
c.NbGrader.db_assignments = [dict(name='ps1')]
c.NbGrader.db_students = []
with open('$HOME/classlist.csv', 'r') as f:
    for l in f:
        csv = l.replace('\n', '').split(',')
        c.NbGrader.db_students.append({
            'id': csv[0],
            'first_name': csv[3],
            'last_name': csv[2],
        })
c.FormgradeApp.ip = '127.0.0.1'
c.FormgradeApp.port = 9000
c.FormgradeApp.authenticator_class = "nbgrader.auth.hubauth.HubAuth"
c.HubAuth.hub_base_url = 'https://$(hostname -f)'
c.HubAuth.hub_port = 443
c.HubAuth.notebook_url_prefix = '$HOME/'
c.HubAuth.graders = ['$USER']
c.HubAuth.proxy_token = u'$PROXY_TOKEN'
c.HubAuth.hubapi_token = u'$HUBAPI_TOKEN'
EOFFF
vi nbgrader_config.py

With the course created and students able to access assigned assiments, you can now proceed to create/edit assiments.

using jupyter's editor open: `<course_id>/source/ps1`
NOTE: when editing the menu item `View > 'Cell Toolbar' > 'Create Assignment'`
can be used to access more gui options.

assign work and release the assiment to students using the nbgrader exchange.

cd ~/<course_id>
nbgrader assign ps1

# release the assign to students
sudo mkdir -m 0755 /srv/nbgrader
# TODO: not sure what the mode on directories should be docs (chmod ugo+rw)
sudo mkdir -m 0777 /srv/nbgrader/exchange
nbgrader release "ps1"
# test
nbgrader list

grading?

https://nbgrader.readthedocs.io/en/stable/user_guide/autograding_resources.html

To start the formgrade tool

  • open a new jupyter terminal
    • run the followfing
    • leave terminal running untill your done or indefently cd ~/<course_id> nbgrader formgrade --debug [FormgradeApp | INFO] Proxying /hub/nbgrader/<course_id> --> http://127.0.0.1:9000 [FormgradeApp | INFO] Serving MathJax from /usr/local/lib/python3.5/dist-packages/notebook/static/components/MathJax/MathJax.js [FormgradeApp | INFO] Form grader running at http://127.0.0.1:9000/ [FormgradeApp | INFO] Use Control-C to stop this server ... > WARN: nbgrader docs say formgrade should only have one user using it at a time!

Since we configured the formgrade tool to use HubAuth you should access the webpage through the jupyterhub proxy (you cant access it directly on port 9000)

https://hostname.domain/hub/nbgrader/<course_id>

Student

(A) from web interface

tab assignments

(B) from terminal

## optional
nbgrader list
nbgrader fetch --course <course_id> "ps1"
# work
nbgrader submit "ps1"
# see what was submited
nbgrader list --inbound