Description:
added contest mode
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r93:bdd89e00b68d - - 2 files changed: 55 inserted, 7 deleted
@@ -93,49 +93,49 | |||
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | #default options |
|
96 | 96 | options = { |
|
97 | 97 | :mode => 'queue', |
|
98 | 98 | :environment => 'exam', |
|
99 | 99 | :dry_run => false, |
|
100 | 100 | } |
|
101 | 101 | |
|
102 | 102 | # Process mode and environment option |
|
103 | 103 | if ARGV.length >= 1 |
|
104 | 104 | options[:environment] = ARGV.shift |
|
105 | 105 | if ARGV.length >=1 |
|
106 | 106 | options[:mode] = ARGV.shift |
|
107 | 107 | end |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | options[:dry_run] = (ARGV.delete('--dry') != nil) |
|
111 | 111 | if options[:dry_run] and (not options[:mode] == 'prob') |
|
112 | 112 | puts "Dry run currently works only for 'prob' mode." |
|
113 | 113 | exit(0) |
|
114 | 114 | end |
|
115 | 115 | |
|
116 | 116 | options[:report] = (ARGV.delete('--report') != nil) |
|
117 |
- if options[:report] and (not options[:mode] |
|
|
117 | + if options[:report] and (not ['prob','contest'].include? options[:mode]) | |
|
118 | 118 | puts "Report currently works only for 'prob' mode." |
|
119 | 119 | exit(0) |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | return options |
|
123 | 123 | end |
|
124 | 124 | |
|
125 | 125 | class ResultCollector |
|
126 | 126 | def initialize |
|
127 | 127 | @results = {} |
|
128 | 128 | @problems = {} |
|
129 | 129 | @users = {} |
|
130 | 130 | end |
|
131 | 131 | |
|
132 | 132 | def save(user, problem, grading_result) |
|
133 | 133 | if not @problems.has_key? problem.id |
|
134 | 134 | @problems[problem.id] = problem |
|
135 | 135 | end |
|
136 | 136 | if not @users.has_key? user.id |
|
137 | 137 | @users[user.id] = user |
|
138 | 138 | end |
|
139 | 139 | @results[[user.id, problem.id]] = grading_result |
|
140 | 140 | end |
|
141 | 141 | |
@@ -227,71 +227,115 | |||
|
227 | 227 | while true |
|
228 | 228 | |
|
229 | 229 | if check_stopfile # created by calling grader stop |
|
230 | 230 | clear_stopfile |
|
231 | 231 | log "stopped (with stop file)" |
|
232 | 232 | break |
|
233 | 233 | end |
|
234 | 234 | |
|
235 | 235 | if grader_mode=="queue" |
|
236 | 236 | task = runner.grade_oldest_task |
|
237 | 237 | else |
|
238 | 238 | task = runner.grade_oldest_test_request |
|
239 | 239 | end |
|
240 | 240 | if task==nil |
|
241 | 241 | sleep(1) |
|
242 | 242 | end |
|
243 | 243 | end |
|
244 | 244 | |
|
245 | 245 | when "prob" |
|
246 | 246 | if options[:report] |
|
247 | 247 | result_collector = ResultCollector.new |
|
248 | 248 | else |
|
249 | 249 | result_collector = nil |
|
250 | 250 | end |
|
251 | - | |
|
252 | - engine = (Grader::Engine. | |
|
253 | - new(:reporter => | |
|
254 | - Grader::SubmissionReporter.new(:dry_run => dry_run, | |
|
255 | - :result_collector => result_collector))) | |
|
251 | + | |
|
252 | + if options[:dry_run] | |
|
253 | + puts "Running in dry mode" | |
|
254 | + end | |
|
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 | 259 | runner = Grader::Runner.new(engine, grader_proc) |
|
257 | 260 | |
|
258 | 261 | grader_proc.report_active if grader_proc!=nil |
|
259 | 262 | |
|
260 | 263 | ARGV.each do |prob_name| |
|
261 | 264 | prob = Problem.find_by_name(prob_name) |
|
262 | 265 | if prob==nil |
|
263 | 266 | puts "cannot find problem: #{prob_name}" |
|
264 | 267 | else |
|
265 | 268 | runner.grade_problem(prob) |
|
266 | 269 | end |
|
267 | 270 | end |
|
268 | 271 | |
|
269 | 272 | if options[:report] |
|
270 | 273 | result_collector.print_report_by_user |
|
271 | 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 | 315 | when "sub" |
|
274 | 316 | engine = Grader::Engine.new |
|
275 | 317 | runner = Grader::Runner.new(engine, grader_proc) |
|
276 | 318 | |
|
277 | 319 | grader_proc.report_active if grader_proc!=nil |
|
278 | 320 | |
|
279 | 321 | ARGV.each do |sub_id| |
|
280 | 322 | puts "Grading #{sub_id}" |
|
281 | 323 | begin |
|
282 | 324 | submission = Submission.find(sub_id.to_i) |
|
283 | 325 | rescue ActiveRecord::RecordNotFound |
|
284 | 326 | puts "Record not found" |
|
285 | 327 | submission = nil |
|
286 | 328 | end |
|
287 | 329 | |
|
288 | 330 | if submission!=nil |
|
289 | 331 | runner.grade_submission(submission) |
|
290 | 332 | end |
|
291 | 333 | end |
|
292 | 334 | |
|
335 | + | |
|
336 | + | |
|
293 | 337 | else |
|
294 | 338 | display_manual |
|
295 | 339 | exit(0) |
|
296 | 340 | end |
|
297 | 341 |
@@ -3,52 +3,56 | |||
|
3 | 3 | # |
|
4 | 4 | |
|
5 | 5 | module Grader |
|
6 | 6 | |
|
7 | 7 | class Runner |
|
8 | 8 | |
|
9 | 9 | def initialize(engine, grader_process=nil) |
|
10 | 10 | @engine = engine |
|
11 | 11 | @grader_process = grader_process |
|
12 | 12 | end |
|
13 | 13 | |
|
14 | 14 | def grade_oldest_task |
|
15 | 15 | task = Task.get_inqueue_and_change_status(Task::STATUS_GRADING) |
|
16 | 16 | if task!=nil |
|
17 | 17 | @grader_process.report_active(task) if @grader_process!=nil |
|
18 | 18 | |
|
19 | 19 | submission = Submission.find(task.submission_id) |
|
20 | 20 | @engine.grade(submission) |
|
21 | 21 | task.status_complete! |
|
22 | 22 | @grader_process.report_inactive(task) if @grader_process!=nil |
|
23 | 23 | end |
|
24 | 24 | return task |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | - def grade_problem(problem) | |
|
27 | + def grade_problem(problem, options={}) | |
|
28 | 28 | users = User.find(:all) |
|
29 | 29 | users.each do |u| |
|
30 | 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 | 35 | last_sub = Submission.find_last_by_user_and_problem(u.id,problem.id) |
|
32 | 36 | if last_sub!=nil |
|
33 | 37 | @engine.grade(last_sub) |
|
34 | 38 | end |
|
35 | 39 | end |
|
36 | 40 | end |
|
37 | 41 | |
|
38 | 42 | def grade_submission(submission) |
|
39 | 43 | puts "Submission: #{submission.id} by #{submission.user.full_name}" |
|
40 | 44 | @engine.grade(submission) |
|
41 | 45 | end |
|
42 | 46 | |
|
43 | 47 | def grade_oldest_test_request |
|
44 | 48 | test_request = TestRequest.get_inqueue_and_change_status(Task::STATUS_GRADING) |
|
45 | 49 | if test_request!=nil |
|
46 | 50 | @grader_process.report_active(test_request) if @grader_process!=nil |
|
47 | 51 | |
|
48 | 52 | @engine.grade(test_request) |
|
49 | 53 | test_request.status_complete! |
|
50 | 54 | @grader_process.report_inactive(test_request) if @grader_process!=nil |
|
51 | 55 | end |
|
52 | 56 | return test_request |
|
53 | 57 | end |
|
54 | 58 |
You need to be logged in to leave comments.
Login now