Created
March 29, 2018 21:51
-
-
Save AgrawalAmey/4e499d0334e4d05c783cd8504fe7fe82 to your computer and use it in GitHub Desktop.
NNFL Submission Sanitiser
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
#!/bin/bash | |
# Unzip everything | |
pushd submissions | |
mkdir ../submissions_cleaned | |
find -name '*.zip' -exec sh -c 'unzip -jod ../submissions_cleaned/"${1%.*}" "$1"' _ {} \; | |
popd | |
# Remove spaces from all file name | |
find $1 -type f -print0 | \ | |
while read -d $'\0' f; do mv -v "$f" "${f// /_}"; done | |
pushd submissions_cleaned | |
for sol_dir in `find . -type d` | |
do | |
# Find the best match and replace | |
missing_files=`diff -rq $sol_dir ../source | grep "Only in ../source".*.ipynb | grep -v .ipynb_checkpoints | sed 's/Only in \.\.\/source://'` | |
unkown_files=`diff -rq $sol_dir ../source | grep "Only in $sol_dir".*.ipynb | grep -v .ipynb_checkpoints | sed "s|Only in \$sol_dir:||"` | |
for missing_file in $missing_files | |
do | |
best_match="-1" | |
best_match_file="none" | |
for unkown_file in $unkown_files | |
do | |
common_lines=`comm --nocheck-order -12 ../source/$missing_file $sol_dir/$unkown_file | wc -l` | |
if test $common_lines -gt $best_match | |
then | |
best_match=$common_lines | |
best_match_file=$unkown_file | |
fi | |
done | |
if test $best_match -gt "0" | |
then | |
echo "Renaming $best_match_file to $missing_file with $best_match common lines." | |
mv $sol_dir/$unkown_file $sol_dir/$missing_file | |
fi | |
done | |
# Remove garbage | |
unkown_files=`diff -rq $sol_dir ../source | grep "Only in $sol_dir" | sed "s|Only in \$sol_dir:||"` | |
for unkown_file in $unkown_files | |
do | |
rm -f $sol_dir/$unkown_file | |
done | |
# Move the files in nbgraders format | |
mv $sol_dir ps1 | |
mkdir -p $sol_dir/ps1 | |
mv ps1 $sol_dir | |
done | |
popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment