forked from saasbook/rag
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_from_json.rb
62 lines (54 loc) · 1.8 KB
/
run_from_json.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env ruby
require 'yaml'
require 'json'
require 'Base64'
require 'tempfile'
require './lib/auto_grader.rb'
def parse_grade(str)
# Used for parsing the stdout output from running grade as a shell command
# FIXME: This feels insecure and fragile
score_regex = /Score out of 100:\s*(\d+(?:\.\d+)?)$/
score = str.match(score_regex, str.rindex(score_regex))[1].to_f
comments = str.match(/^---BEGIN rspec comments---\n#{'-'*80}\n(.*)#{'-'*80}\n---END rspec comments---$/m)[1]
comments = comments.split("\n").map do |line|
line.gsub(/\(FAILED - \d+\)/, "(FAILED)")
end.join("\n")
[score, comments]
rescue
raise "Failed to parse autograder output", str
end
ags = YAML::load(File.open('local_autograders2.yml', 'r'){|f|f.read})
#p ags
subs = eval File.open('submissions_assign2_1.txt', 'r'){|f|f.read}
subs.each_key do |assign_part|
#%w[assign-2-part-5].each do |assign_part|
puts "-"*60
puts assign_part
subs[assign_part].each do |sub|
spec = ags[assign_part]
submission = Base64.strict_decode64(sub['submission'])
Tempfile.open(['test', '.rb']) do |file|
file.write(submission)
file.flush
# This is normal stuff
output = `./grade #{file.path} #{spec}`
# This is for Heroku stuff
#uri = submission
#puts uri
#output = `HEROKU_URI="#{uri}" ./grade dummy_file.rb #{spec}`
score, comments = parse_grade(output)
comments.gsub!(spec, 'spec.rb')
puts "#{subs[assign_part].index sub}: #{score}"
puts comments if score != 100
puts submission if score != 100
#puts submission if score == 0
end
#g = AutoGrader.create('1', 'RspecGrader', submission, :spec => spec)
#g.grade!
#puts "#{g.normalized_score}, #{g.comments}"
#if gets =~ /a/
# puts "Submission:"
# puts submission
#end
end
end