Description:
added contest mode
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r93:bdd89e00b68d - - 2 files changed: 54 inserted, 6 deleted

@@ -105,25 +105,25
105 if ARGV.length >=1
105 if ARGV.length >=1
106 options[:mode] = ARGV.shift
106 options[:mode] = ARGV.shift
107 end
107 end
108 end
108 end
109
109
110 options[:dry_run] = (ARGV.delete('--dry') != nil)
110 options[:dry_run] = (ARGV.delete('--dry') != nil)
111 if options[:dry_run] and (not options[:mode] == 'prob')
111 if options[:dry_run] and (not options[:mode] == 'prob')
112 puts "Dry run currently works only for 'prob' mode."
112 puts "Dry run currently works only for 'prob' mode."
113 exit(0)
113 exit(0)
114 end
114 end
115
115
116 options[:report] = (ARGV.delete('--report') != nil)
116 options[:report] = (ARGV.delete('--report') != nil)
117 - if options[:report] and (not options[:mode] == 'prob')
117 + if options[:report] and (not ['prob','contest'].include? options[:mode])
118 puts "Report currently works only for 'prob' mode."
118 puts "Report currently works only for 'prob' mode."
119 exit(0)
119 exit(0)
120 end
120 end
121
121
122 return options
122 return options
123 end
123 end
124
124
125 class ResultCollector
125 class ResultCollector
126 def initialize
126 def initialize
127 @results = {}
127 @results = {}
128 @problems = {}
128 @problems = {}
129 @users = {}
129 @users = {}
@@ -240,58 +240,102
240 if task==nil
240 if task==nil
241 sleep(1)
241 sleep(1)
242 end
242 end
243 end
243 end
244
244
245 when "prob"
245 when "prob"
246 if options[:report]
246 if options[:report]
247 result_collector = ResultCollector.new
247 result_collector = ResultCollector.new
248 else
248 else
249 result_collector = nil
249 result_collector = nil
250 end
250 end
251
251
252 - engine = (Grader::Engine.
252 + if options[:dry_run]
253 - new(:reporter =>
253 + puts "Running in dry mode"
254 - Grader::SubmissionReporter.new(:dry_run => dry_run,
254 + end
255 - :result_collector => result_collector)))
255 +
256 + prob_reporter = Grader::SubmissionReporter.new(:dry_run => dry_run,
257 + :result_collector => result_collector)
258 + engine = Grader::Engine.new(:reporter => prob_reporter)
256 runner = Grader::Runner.new(engine, grader_proc)
259 runner = Grader::Runner.new(engine, grader_proc)
257
260
258 grader_proc.report_active if grader_proc!=nil
261 grader_proc.report_active if grader_proc!=nil
259
262
260 ARGV.each do |prob_name|
263 ARGV.each do |prob_name|
261 prob = Problem.find_by_name(prob_name)
264 prob = Problem.find_by_name(prob_name)
262 if prob==nil
265 if prob==nil
263 puts "cannot find problem: #{prob_name}"
266 puts "cannot find problem: #{prob_name}"
264 else
267 else
265 runner.grade_problem(prob)
268 runner.grade_problem(prob)
266 end
269 end
267 end
270 end
268
271
269 if options[:report]
272 if options[:report]
270 result_collector.print_report_by_user
273 result_collector.print_report_by_user
271 end
274 end
272
275
276 + when "contest"
277 + # always use dry run when grading during contest
278 + contest_name = ARGV.shift
279 +
280 + options[:dry_run] = true
281 +
282 + contest = Contest.find_by_name(contest_name)
283 + if contest==nil
284 + puts "cannot find contest: #{contest_name}"
285 + exit(0)
286 + end
287 +
288 + if options[:report]
289 + result_collector = ResultCollector.new
290 + else
291 + result_collector = nil
292 + end
293 +
294 + if options[:dry_run]
295 + puts "Running in dry mode"
296 + end
297 +
298 + prob_reporter = Grader::SubmissionReporter.new(:dry_run => dry_run,
299 + :result_collector => result_collector)
300 + engine = Grader::Engine.new(:reporter => prob_reporter)
301 + runner = Grader::Runner.new(engine, grader_proc)
302 +
303 + grader_proc.report_active if grader_proc!=nil
304 +
305 + contest.problems.each do |problem|
306 + puts "Grading: #{problem.name}"
307 + runner.grade_problem(problem,
308 + :user_conditions => lambda {|u| u.contest_finished?})
309 + end
310 +
311 + if options[:report]
312 + result_collector.print_report_by_user
313 + end
314 +
273 when "sub"
315 when "sub"
274 engine = Grader::Engine.new
316 engine = Grader::Engine.new
275 runner = Grader::Runner.new(engine, grader_proc)
317 runner = Grader::Runner.new(engine, grader_proc)
276
318
277 grader_proc.report_active if grader_proc!=nil
319 grader_proc.report_active if grader_proc!=nil
278
320
279 ARGV.each do |sub_id|
321 ARGV.each do |sub_id|
280 puts "Grading #{sub_id}"
322 puts "Grading #{sub_id}"
281 begin
323 begin
282 submission = Submission.find(sub_id.to_i)
324 submission = Submission.find(sub_id.to_i)
283 rescue ActiveRecord::RecordNotFound
325 rescue ActiveRecord::RecordNotFound
284 puts "Record not found"
326 puts "Record not found"
285 submission = nil
327 submission = nil
286 end
328 end
287
329
288 if submission!=nil
330 if submission!=nil
289 runner.grade_submission(submission)
331 runner.grade_submission(submission)
290 end
332 end
291 end
333 end
292
334
335 +
336 +
293 else
337 else
294 display_manual
338 display_manual
295 exit(0)
339 exit(0)
296 end
340 end
297
341
@@ -15,28 +15,32
15 task = Task.get_inqueue_and_change_status(Task::STATUS_GRADING)
15 task = Task.get_inqueue_and_change_status(Task::STATUS_GRADING)
16 if task!=nil
16 if task!=nil
17 @grader_process.report_active(task) if @grader_process!=nil
17 @grader_process.report_active(task) if @grader_process!=nil
18
18
19 submission = Submission.find(task.submission_id)
19 submission = Submission.find(task.submission_id)
20 @engine.grade(submission)
20 @engine.grade(submission)
21 task.status_complete!
21 task.status_complete!
22 @grader_process.report_inactive(task) if @grader_process!=nil
22 @grader_process.report_inactive(task) if @grader_process!=nil
23 end
23 end
24 return task
24 return task
25 end
25 end
26
26
27 - def grade_problem(problem)
27 + def grade_problem(problem, options={})
28 users = User.find(:all)
28 users = User.find(:all)
29 users.each do |u|
29 users.each do |u|
30 puts "user: #{u.login}"
30 puts "user: #{u.login}"
31 + if options[:user_conditions]!=nil
32 + con_proc = options[:user_conditions]
33 + next if not con_proc.call(u)
34 + end
31 last_sub = Submission.find_last_by_user_and_problem(u.id,problem.id)
35 last_sub = Submission.find_last_by_user_and_problem(u.id,problem.id)
32 if last_sub!=nil
36 if last_sub!=nil
33 @engine.grade(last_sub)
37 @engine.grade(last_sub)
34 end
38 end
35 end
39 end
36 end
40 end
37
41
38 def grade_submission(submission)
42 def grade_submission(submission)
39 puts "Submission: #{submission.id} by #{submission.user.full_name}"
43 puts "Submission: #{submission.id} by #{submission.user.full_name}"
40 @engine.grade(submission)
44 @engine.grade(submission)
41 end
45 end
42
46
You need to be logged in to leave comments. Login now