Description:
added --dry option to grader prob mode
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r91:5df0d71260f4 - - 2 files changed: 42 inserted, 16 deleted

@@ -51,64 +51,92
51 (4) grader --help
51 (4) grader --help
52 (1) call grader with environment = 'exam', mode = 'queue'
52 (1) call grader with environment = 'exam', mode = 'queue'
53 (2) possible modes are: 'queue', 'prob', 'test_request'
53 (2) possible modes are: 'queue', 'prob', 'test_request'
54 (3) create stop-file to stop running grader in queue mode
54 (3) create stop-file to stop running grader in queue mode
55 (4) You are here.
55 (4) You are here.
56 USAGE
56 USAGE
57 end
57 end
58
58
59 #########################################
59 #########################################
60 # main program
60 # main program
61 #########################################
61 #########################################
62
62
63 - # with --help
63 + # Reading environment and options.
64 +
65 + def process_options_and_stop_file
66 + # The list of options are:
67 + # - stop [all|process ids]
68 + # -
69 +
70 + # Process 'help' option
64 if (ARGV.length==1) and (/help/.match(ARGV[0]))
71 if (ARGV.length==1) and (/help/.match(ARGV[0]))
65 display_manual
72 display_manual
66 exit(0)
73 exit(0)
67 end
74 end
68
75
69 - # reading environment and options
76 + # Process 'stop' option.
70 if (ARGV.length >= 1) and (ARGV[0]=='stop')
77 if (ARGV.length >= 1) and (ARGV[0]=='stop')
71 if ARGV.length==1
78 if ARGV.length==1
72 puts "you should specify pid-list or 'all'"
79 puts "you should specify pid-list or 'all'"
73 display_manual
80 display_manual
74 elsif (ARGV.length==2) and (ARGV[1]=='all')
81 elsif (ARGV.length==2) and (ARGV[1]=='all')
75 stop_grader(:all)
82 stop_grader(:all)
76 puts "A global stop file ('stop.all') created."
83 puts "A global stop file ('stop.all') created."
77 puts "You should remove it manually later."
84 puts "You should remove it manually later."
78 else
85 else
79 (1..ARGV.length-1).each do |i|
86 (1..ARGV.length-1).each do |i|
80 stop_grader(ARGV[i])
87 stop_grader(ARGV[i])
81 end
88 end
82 puts "stop file(s) created"
89 puts "stop file(s) created"
83 end
90 end
84 exit(0)
91 exit(0)
85 end
92 end
86
93
94 + # Check stop file.
87 if check_stopfile
95 if check_stopfile
88 puts "Stop file exists. Terminated."
96 puts "Stop file exists. Terminated."
89 clear_stopfile
97 clear_stopfile
90 exit(0)
98 exit(0)
91 end
99 end
92
100
93 - grader_mode = 'queue'
101 + #default options
102 + options = {
103 + :mode => 'queue',
104 + :environment => 'exam',
105 + :dry_run => false,
106 + }
107 +
108 + # Process mode and environment option
109 + if ARGV.length >= 1
110 + options[:environment] = ARGV.shift
94 if ARGV.length >= 1
111 if ARGV.length >=1
95 - GRADER_ENV = ARGV[0]
112 + options[:mode] = ARGV.shift
96 - if ARGV.length >=2
113 + end
97 - grader_mode = ARGV[1]
114 + end
115 +
116 + options[:dry_run] = (ARGV.delete('--dry') != nil)
117 + if options[:dry_run] and (not options[:mode] == 'prob')
118 + puts "Dry run currently works for 'prob' mode."
119 + exit(0)
98 end
120 end
99 - else
121 +
100 - GRADER_ENV = 'exam'
122 + return options
101 end
123 end
102
124
125 + # ======= Main ========
126 + options = process_options_and_stop_file
127 + GRADER_ENV = options[:environment]
128 + grader_mode = options[:mode]
129 + dry_run = options[:dry_run]
130 +
103 puts "environment: #{GRADER_ENV}"
131 puts "environment: #{GRADER_ENV}"
104 require File.join(File.dirname(__FILE__),'config/environment')
132 require File.join(File.dirname(__FILE__),'config/environment')
105
133
106 # add grader_mode to config
134 # add grader_mode to config
107 # this is needed because method log needs it. TODO: clean this up
135 # this is needed because method log needs it. TODO: clean this up
108 class << config
136 class << config
109 attr_accessor :grader_mode
137 attr_accessor :grader_mode
110 end
138 end
111 config.grader_mode = grader_mode
139 config.grader_mode = grader_mode
112
140
113 # reading rails environment
141 # reading rails environment
114 log 'Reading rails environment'
142 log 'Reading rails environment'
@@ -161,50 +189,44
161
189
162 if grader_mode=="queue"
190 if grader_mode=="queue"
163 task = runner.grade_oldest_task
191 task = runner.grade_oldest_task
164 else
192 else
165 task = runner.grade_oldest_test_request
193 task = runner.grade_oldest_test_request
166 end
194 end
167 if task==nil
195 if task==nil
168 sleep(1)
196 sleep(1)
169 end
197 end
170 end
198 end
171
199
172 when "prob"
200 when "prob"
173 - engine = Grader::Engine.new
201 + engine = Grader::Engine.new(nil, Grader::SubmissionReporter.new(dry_run))
174 runner = Grader::Runner.new(engine, grader_proc)
202 runner = Grader::Runner.new(engine, grader_proc)
175
203
176 grader_proc.report_active if grader_proc!=nil
204 grader_proc.report_active if grader_proc!=nil
177
205
178 - ARGV.shift
179 - ARGV.shift
180 -
181 ARGV.each do |prob_name|
206 ARGV.each do |prob_name|
182 prob = Problem.find_by_name(prob_name)
207 prob = Problem.find_by_name(prob_name)
183 if prob==nil
208 if prob==nil
184 puts "cannot find problem: #{prob_name}"
209 puts "cannot find problem: #{prob_name}"
185 else
210 else
186 runner.grade_problem(prob)
211 runner.grade_problem(prob)
187 end
212 end
188 end
213 end
189
214
190 when "sub"
215 when "sub"
191 engine = Grader::Engine.new
216 engine = Grader::Engine.new
192 runner = Grader::Runner.new(engine, grader_proc)
217 runner = Grader::Runner.new(engine, grader_proc)
193
218
194 grader_proc.report_active if grader_proc!=nil
219 grader_proc.report_active if grader_proc!=nil
195
220
196 - ARGV.shift
197 - ARGV.shift
198 -
199 ARGV.each do |sub_id|
221 ARGV.each do |sub_id|
200 puts "Grading #{sub_id}"
222 puts "Grading #{sub_id}"
201 begin
223 begin
202 submission = Submission.find(sub_id.to_i)
224 submission = Submission.find(sub_id.to_i)
203 rescue ActiveRecord::RecordNotFound
225 rescue ActiveRecord::RecordNotFound
204 puts "Record not found"
226 puts "Record not found"
205 submission = nil
227 submission = nil
206 end
228 end
207
229
208 if submission!=nil
230 if submission!=nil
209 runner.grade_submission(submission)
231 runner.grade_submission(submission)
210 end
232 end
@@ -23,26 +23,27
23 def save_source(submission,source_name)
23 def save_source(submission,source_name)
24 dir = self.produce_grading_room(submission)
24 dir = self.produce_grading_room(submission)
25 f = File.open("#{dir}/#{source_name}","w")
25 f = File.open("#{dir}/#{source_name}","w")
26 f.write(submission.source)
26 f.write(submission.source)
27 f.close
27 f.close
28 end
28 end
29
29
30 def clean_up(submission)
30 def clean_up(submission)
31 end
31 end
32 end
32 end
33
33
34 class SubmissionReporter
34 class SubmissionReporter
35 - def initialize
35 + def initialize(dry_run=false)
36 @config = Grader::Configuration.get_instance
36 @config = Grader::Configuration.get_instance
37 + @dry_run = dry_run
37 end
38 end
38
39
39 def report(sub,test_result_dir)
40 def report(sub,test_result_dir)
40 save_result(sub,read_result(test_result_dir))
41 save_result(sub,read_result(test_result_dir))
41 end
42 end
42
43
43 def report_error(sub,msg)
44 def report_error(sub,msg)
44 save_result(sub,{:points => 0,
45 save_result(sub,{:points => 0,
45 :comment => "Grading error: #{msg}" })
46 :comment => "Grading error: #{msg}" })
46 end
47 end
47
48
48 protected
49 protected
@@ -106,18 +107,21
106 if problem == nil
107 if problem == nil
107 submission.grader_comment = 'PASSED: ' + comment + '(problem is nil)'
108 submission.grader_comment = 'PASSED: ' + comment + '(problem is nil)'
108 elsif points == problem.full_score
109 elsif points == problem.full_score
109 #submission.grader_comment = 'PASSED: ' + comment
110 #submission.grader_comment = 'PASSED: ' + comment
110 submission.grader_comment = comment
111 submission.grader_comment = comment
111 elsif result[:comment].chomp =~ /^[\[\]P]+$/
112 elsif result[:comment].chomp =~ /^[\[\]P]+$/
112 submission.grader_comment = 'PASSED: ' + comment + '(inconsistent score)'
113 submission.grader_comment = 'PASSED: ' + comment + '(inconsistent score)'
113 else
114 else
114 #submission.grader_comment = 'FAILED: ' + comment
115 #submission.grader_comment = 'FAILED: ' + comment
115 submission.grader_comment = comment
116 submission.grader_comment = comment
116 end
117 end
117 submission.compiler_message = result[:cmp_msg] or ''
118 submission.compiler_message = result[:cmp_msg] or ''
119 +
120 + if not @dry_run
118 submission.save
121 submission.save
119 end
122 end
123 + end
120
124
121 end
125 end
122
126
123 end
127 end
You need to be logged in to leave comments. Login now