Last active
February 7, 2018 01:43
-
-
Save ahirschberg/6ac0a43cb0401d7c473ef879dba04738 to your computer and use it in GitHub Desktop.
Moves canvas files into student folders
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
# TODO: | |
# change this to the folder where your jar files are | |
# you can download it from https://github.com/junit-team/junit4/wiki/Download-and-Install | |
# just change /usr/share/java to wherever you downloaded stuff (downloads, maybe) | |
jar_lib_folder_path="junit_libs" | |
# TODO: | |
# change these to the correct filenames for the jars you have | |
jarname_junit="junit-4.12.jar" | |
jarname_hamcrest="hamcrest-core-1.3.jar" | |
filename="WordGuess.java" | |
grader_filename="Grader2" | |
# begin script | |
student_folder=$1 | |
our_grading_folder="grader" | |
function showusage { | |
echo "First, you'll need to open this file in a text editor and set the" | |
echo "filepath where the script can find your junit and hamcrest-core" | |
echo "jarfiles. The variable to modify is at the top of the file." | |
echo "You'll also need to put the autograder files " | |
echo "(AutograderSA.java, expected_out/, and all the csv files) " | |
echo "into the folder as well, just like they are given " | |
echo "in the grader zip file." | |
echo "Url to library downloads: https://github.com/junit-team/junit4/wiki/Download-and-Install" | |
echo | |
echo "You run this script from the hw1 grading root folder, which " | |
echo "should contain all the hw-straightAs-xxxstudentxxx/ folders, as well " | |
echo "as the newly created $our_grading_folder." | |
echo | |
echo "Usage: ./hw1_autograder.sh <student_folder_path>" | |
echo "or: ./hw1_autograder.sh nocopy (to just run compile and run without copying)" | |
echo | |
echo "To repeat this message, run the program with invalid args or no args." | |
exit 1 | |
} | |
if [[ $# != 1 ]]; then | |
showusage | |
elif [[ $# == 1 ]]; then | |
if [[ "$student_folder" != "nocopy" ]]; then | |
if [[ ! -d "$student_folder" ]]; then | |
showusage | |
fi | |
cp "$student_folder/$filename" "$our_grading_folder/" | |
fi | |
fi | |
pushd $our_grading_folder | |
rm *.class | |
# you will have to change the filenames around if you're using different versions of hamcrest and junit | |
javac -cp ".:$jar_lib_folder_path/$jarname_junit:$jar_lib_folder_path/$jarname_hamcrest" \ | |
*.java | |
javac WordGuess.java && java WordGuess 0 < input/cats.in > actual/cats.out && java WordGuess 0 < input/catf.in > actual/catf.out && java WordGuess 1 < input/dads.in > actual/dads.out && java WordGuess 1 < input/dadf.in > actual/dadf.out && java WordGuess 2 < input/dogs.in > actual/dogs.out && java WordGuess 2 < input/dogf.in > actual/dogf.out && java WordGuess 3 < input/moms.in > actual/moms.out && java WordGuess 3 < input/momf.in > actual/momf.out && java WordGuess 4 < input/rats.in > actual/rats.out && java WordGuess 4 < input/ratf.in > actual/ratf.out | |
for file in expected/*.out; do | |
echo "Stripping file $file" | |
mv $file "$file.old" | |
tr -d '\r' < "$file.old" > $file | |
done | |
java -cp ".:$jar_lib_folder_path/$jarname_junit:$jar_lib_folder_path/$jarname_hamcrest" \ | |
org.junit.runner.JUnitCore \ | |
"$grader_filename" | sed -e /\\tat/d # hey, if you're getting weird errors with the runner and would like to see the stack trace, comment out the | |
# # | sed -e ... because that's piping things to sed to hide java stack traces... | |
popd | |
echo "Press any key to open vim (CTRL+C to quit)." | |
echo "Also, if you want to run their submission directly, cd into $our_grading_folder" | |
echo "and just run it with java <filename> <args>. It should already be compiled." | |
read | |
vi $our_grading_folder/$filename |
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
#!/usr/bin/env ruby | |
# please direct all questions to @ahirschberg on slack | |
require 'fileutils' | |
CANVAS_REGEX = / | |
(?<canvas_info>[A-Za-z]+_\d+_\d+) | |
_ | |
(?<filename>\w+) | |
(?:-\d*)? | |
(?<fileext>(\.\w+)?)/x | |
submissions=Dir['*.java'] | |
submissions.each do |name| | |
md = CANVAS_REGEX.match name | |
FileUtils.mkdir_p(md['canvas_info']) | |
FileUtils.mv(name, "./#{md['canvas_info']}/#{md['filename']}#{md['fileext']}") | |
end | |
puts "Done (#{submissions.length})" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment