Description:
only grades users in the contest
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r94:1ba4bf8cd712 - - 1 file changed: 9 inserted, 6 deleted
@@ -87,92 +87,92 | |||||
|
87 |
|
87 | ||
|
88 | # Check stop file. |
|
88 | # Check stop file. |
|
89 | if check_stopfile |
|
89 | if check_stopfile |
|
90 | puts "Stop file exists. Terminated." |
|
90 | puts "Stop file exists. Terminated." |
|
91 | clear_stopfile |
|
91 | clear_stopfile |
|
92 | exit(0) |
|
92 | exit(0) |
|
93 | end |
|
93 | end |
|
94 |
|
94 | ||
|
95 | #default options |
|
95 | #default options |
|
96 | options = { |
|
96 | options = { |
|
97 | :mode => 'queue', |
|
97 | :mode => 'queue', |
|
98 | :environment => 'exam', |
|
98 | :environment => 'exam', |
|
99 | :dry_run => false, |
|
99 | :dry_run => false, |
|
100 | } |
|
100 | } |
|
101 |
|
101 | ||
|
102 | # Process mode and environment option |
|
102 | # Process mode and environment option |
|
103 | if ARGV.length >= 1 |
|
103 | if ARGV.length >= 1 |
|
104 | options[:environment] = ARGV.shift |
|
104 | options[:environment] = ARGV.shift |
|
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] |
|
111 | + if options[:dry_run] and (not ['prob','contest'].include? options[:mode]) |
|
112 | - puts "Dry run currently works only for 'prob' mode." |
|
112 | + puts "Dry run currently works only for 'prob' or 'contest' modes." |
|
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 ['prob','contest'].include? options[:mode]) |
|
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' or 'contest' modes." |
|
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 = {} |
|
130 | end |
|
130 | end |
|
131 |
|
131 | ||
|
132 | def save(user, problem, grading_result) |
|
132 | def save(user, problem, grading_result) |
|
133 | if not @problems.has_key? problem.id |
|
133 | if not @problems.has_key? problem.id |
|
134 | @problems[problem.id] = problem |
|
134 | @problems[problem.id] = problem |
|
135 | end |
|
135 | end |
|
136 | if not @users.has_key? user.id |
|
136 | if not @users.has_key? user.id |
|
137 | @users[user.id] = user |
|
137 | @users[user.id] = user |
|
138 | end |
|
138 | end |
|
139 | @results[[user.id, problem.id]] = grading_result |
|
139 | @results[[user.id, problem.id]] = grading_result |
|
140 | end |
|
140 | end |
|
141 |
|
141 | ||
|
142 | def print_report_by_user |
|
142 | def print_report_by_user |
|
143 | puts "---------------------" |
|
143 | puts "---------------------" |
|
144 | puts " REPORT" |
|
144 | puts " REPORT" |
|
145 | puts "---------------------" |
|
145 | puts "---------------------" |
|
146 |
|
146 | ||
|
147 | - print "login" |
|
147 | + print "login,email" |
|
148 | @problems.each_value do |problem| |
|
148 | @problems.each_value do |problem| |
|
149 | print ",#{problem.name}" |
|
149 | print ",#{problem.name}" |
|
150 | end |
|
150 | end |
|
151 | print "\n" |
|
151 | print "\n" |
|
152 |
|
152 | ||
|
153 | @users.each_value do |user| |
|
153 | @users.each_value do |user| |
|
154 | - print "#{user.login}" |
|
154 | + print "#{user.login},#{user.email}" |
|
155 | @problems.each_value do |problem| |
|
155 | @problems.each_value do |problem| |
|
156 | if @results.has_key? [user.id, problem.id] |
|
156 | if @results.has_key? [user.id, problem.id] |
|
157 | print ",#{@results[[user.id,problem.id]][:points]}" |
|
157 | print ",#{@results[[user.id,problem.id]][:points]}" |
|
158 | else |
|
158 | else |
|
159 | print "," |
|
159 | print "," |
|
160 | end |
|
160 | end |
|
161 | end |
|
161 | end |
|
162 | print "\n" |
|
162 | print "\n" |
|
163 | end |
|
163 | end |
|
164 | end |
|
164 | end |
|
165 | end |
|
165 | end |
|
166 |
|
166 | ||
|
167 | ######################################### |
|
167 | ######################################### |
|
168 | # main program |
|
168 | # main program |
|
169 | ######################################### |
|
169 | ######################################### |
|
170 |
|
170 | ||
|
171 | options = process_options_and_stop_file |
|
171 | options = process_options_and_stop_file |
|
172 | GRADER_ENV = options[:environment] |
|
172 | GRADER_ENV = options[:environment] |
|
173 | grader_mode = options[:mode] |
|
173 | grader_mode = options[:mode] |
|
174 | dry_run = options[:dry_run] |
|
174 | dry_run = options[:dry_run] |
|
175 |
|
175 | ||
|
176 | puts "environment: #{GRADER_ENV}" |
|
176 | puts "environment: #{GRADER_ENV}" |
|
177 | require File.join(File.dirname(__FILE__),'config/environment') |
|
177 | require File.join(File.dirname(__FILE__),'config/environment') |
|
178 |
|
178 | ||
@@ -284,49 +284,52 | |||||
|
284 | puts "cannot find contest: #{contest_name}" |
|
284 | puts "cannot find contest: #{contest_name}" |
|
285 | exit(0) |
|
285 | exit(0) |
|
286 | end |
|
286 | end |
|
287 |
|
287 | ||
|
288 | if options[:report] |
|
288 | if options[:report] |
|
289 | result_collector = ResultCollector.new |
|
289 | result_collector = ResultCollector.new |
|
290 | else |
|
290 | else |
|
291 | result_collector = nil |
|
291 | result_collector = nil |
|
292 | end |
|
292 | end |
|
293 |
|
293 | ||
|
294 | if options[:dry_run] |
|
294 | if options[:dry_run] |
|
295 | puts "Running in dry mode" |
|
295 | puts "Running in dry mode" |
|
296 | end |
|
296 | end |
|
297 |
|
297 | ||
|
298 | prob_reporter = Grader::SubmissionReporter.new(:dry_run => dry_run, |
|
298 | prob_reporter = Grader::SubmissionReporter.new(:dry_run => dry_run, |
|
299 | :result_collector => result_collector) |
|
299 | :result_collector => result_collector) |
|
300 | engine = Grader::Engine.new(:reporter => prob_reporter) |
|
300 | engine = Grader::Engine.new(:reporter => prob_reporter) |
|
301 | runner = Grader::Runner.new(engine, grader_proc) |
|
301 | runner = Grader::Runner.new(engine, grader_proc) |
|
302 |
|
302 | ||
|
303 | grader_proc.report_active if grader_proc!=nil |
|
303 | grader_proc.report_active if grader_proc!=nil |
|
304 |
|
304 | ||
|
305 | contest.problems.each do |problem| |
|
305 | contest.problems.each do |problem| |
|
306 | puts "Grading: #{problem.name}" |
|
306 | puts "Grading: #{problem.name}" |
|
307 | runner.grade_problem(problem, |
|
307 | runner.grade_problem(problem, |
|
308 |
- :user_conditions => lambda |
|
308 | + :user_conditions => lambda do |u| |
|
|
309 | + u.contest_finished? and | ||
|
|
310 | + u.contest_ids.include?(contest.id) | ||
|
|
311 | + end) | ||
|
309 | end |
|
312 | end |
|
310 |
|
313 | ||
|
311 | if options[:report] |
|
314 | if options[:report] |
|
312 | result_collector.print_report_by_user |
|
315 | result_collector.print_report_by_user |
|
313 | end |
|
316 | end |
|
314 |
|
317 | ||
|
315 | when "sub" |
|
318 | when "sub" |
|
316 | engine = Grader::Engine.new |
|
319 | engine = Grader::Engine.new |
|
317 | runner = Grader::Runner.new(engine, grader_proc) |
|
320 | runner = Grader::Runner.new(engine, grader_proc) |
|
318 |
|
321 | ||
|
319 | grader_proc.report_active if grader_proc!=nil |
|
322 | grader_proc.report_active if grader_proc!=nil |
|
320 |
|
323 | ||
|
321 | ARGV.each do |sub_id| |
|
324 | ARGV.each do |sub_id| |
|
322 | puts "Grading #{sub_id}" |
|
325 | puts "Grading #{sub_id}" |
|
323 | begin |
|
326 | begin |
|
324 | submission = Submission.find(sub_id.to_i) |
|
327 | submission = Submission.find(sub_id.to_i) |
|
325 | rescue ActiveRecord::RecordNotFound |
|
328 | rescue ActiveRecord::RecordNotFound |
|
326 | puts "Record not found" |
|
329 | puts "Record not found" |
|
327 | submission = nil |
|
330 | submission = nil |
|
328 | end |
|
331 | end |
|
329 |
|
332 | ||
|
330 | if submission!=nil |
|
333 | if submission!=nil |
|
331 | runner.grade_submission(submission) |
|
334 | runner.grade_submission(submission) |
|
332 | end |
|
335 | end |
You need to be logged in to leave comments.
Login now