Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quick overview of assignments without collecting #36

Open
ferdinandyb opened this issue Oct 15, 2018 · 5 comments
Open

quick overview of assignments without collecting #36

ferdinandyb opened this issue Oct 15, 2018 · 5 comments

Comments

@ferdinandyb
Copy link

Feature request (kooplex-edu):
I would need a quick overview of assignments in one folder, without having to collect and then reassign (reassignment removes them again). Preferably, if only one .ipynb is present in the students assignment folder, copy that to a single folder, with the students name prepended and also convert it to html for quick preview (jupyter nbconvert --execute --to html notebook.ipynb.)

@oroszl
Copy link

oroszl commented Oct 15, 2018

you can do that manually through the student's work dir

@jegesm
Copy link
Collaborator

jegesm commented Oct 15, 2018 via email

@ferdinandyb
Copy link
Author

This script will do the trick until there's a better solution:

eg: python3 gatherassigments.py workdir/EN-L/ assignment1 -c

import argparse
import os
import glob
import shutil
import pathlib
import subprocess

import pandas as pd

def gatherassignments(course,assignment, destination):
    stcounter = 0
    nbcounter = 0
    for st in os.listdir(course):
        snb = False
        try:
            name = studentmap[st]
        except KeyError as e:
            # students will not be in the list if they stopped attending the course at some point
            continue
        for nb in glob.glob(os.path.join(course,st,assignment,"*.ipynb")):
            snb = True
            nbcounter += 1
            shutil.copy(nb,os.path.join(destination,name + "_" + os.path.basename(nb)))
        if snb:
            stcounter += 1
    print("Found {} notebooks from {} students.".format(nbcounter,stcounter))
    
def convert_notebooks(folder):
    for nb in glob.glob(os.path.join(folder,"*.ipynb")):
        subprocess.run(["jupyter", "nbconvert", "--execute", "--to", "html",nb],timeout = 60)

if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('course',type=str)
    parser.add_argument('assignment',type=str)
    parser.add_argument('-c','--convert', action='store_true')
    parser.add_argument('-s','--students', type=str,default="hallgatok1.xlsx")
    args = parser.parse_args()
    
    studentmap = {line[1].lower() : "_".join(line[0].split()) for line in pd.read_excel(args.students).values}
    destination = os.path.join("assignments",args.assignment)
    pathlib.Path(destination).mkdir(parents=True, exist_ok=True) 
    
    gatherassignments(args.course,args.assignment,destination)
    if args.convert:
        convert_notebooks(destination)

@oroszl
Copy link

oroszl commented Oct 15, 2018

This was my solution:

WORKDIR=$1
PACKAGE=$2
for diak in `ls $WORKDIR`; do
if [ ! -d $diak/$PACKAGE/ ]; then
  mkdir -p $diak/$PACKAGE/
fi
cp $WORKDIR/$diak/$PACKAGE/MEGOLDASOK/*.ipynb $diak/$PACKAGE/
jupyter-nbconvert --to html $diak/$PACKAGE/*.ipynb --output-dir $diak/$PACKAGE
done

of course this requires a predefined structure

@ferdinandyb
Copy link
Author

I don't touch bash if I don't have to, and I wanted to prepend their names, but definitely shorter :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants