Created
March 24, 2018 22:52
-
-
Save kylekyle/25bd7ca7927aa1acd6ccda4d8da0bedb to your computer and use it in GitHub Desktop.
A CLI grader for Runestone Academy assignments
This file contains hidden or 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
require 'http' | |
max_points = 30 | |
cutoff_time = Time.local(2018,3,23,10,10) | |
question = 'IT105_AY182_GradedLab01_01' | |
base = 'https://runestone.academy/runestone/' | |
http = HTTP.cookies session_id_runestone: ENV['RUNESTONE_SESSION_ID'] | |
names = JSON.parse http.get(base+'admin/course_students').to_s | |
names = names.to_a.sort.to_h | |
names.each_with_index do |(sid,name),i| | |
params = { sid: sid, acid: question } | |
comments = JSON.parse(http.get(base+'admin/getGradeComments', params: params).to_s) | |
if comments['grade'] == max_points | |
puts "Perfect score for #{name}, skipping ..." | |
next | |
end | |
history = JSON.parse(http.get(base+'/ajax/gethist.json', params: params).to_s) | |
if history['timestamps'].empty? | |
puts "no submissions for #{name}, skipping ..." | |
next | |
end | |
submissions = history['timestamps'].map do |string| | |
# arg. times should always be in iso8601 | |
Time.parse string + "-00:00" | |
end.zip history['history'] | |
submissions.reject! {|t,_| t > cutoff_time} | |
time, code = submissions.last | |
system('clear') | |
puts "====================================" | |
puts "Student #{i}/#{names.size} - #{comments['grade']}/#{max_points} points" | |
puts "#{name} (#{sid})" | |
puts time | |
puts "====================================" | |
puts | |
puts code | |
puts "\n" | |
print "Comments (#{comments['comments']}): " | |
comment = gets.strip | |
print "Grade (#{comments['grade']}): " | |
grade = gets.strip | |
unless comment.empty? and grade.empty? | |
puts "Saving ..." | |
grade = grade.empty? ? comments['grade'] : grade.to_i | |
comment = comment.empty? ? comments['coment'] : comment | |
form = { acid: question, sid: sid, grade: grade, comment: comment } | |
http.post(base+'assignments/record_grade', form: form) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment