Description:
grades contest submissions
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r385:865ba2aed5c0 - - 3 files changed: 73 inserted, 25 deleted
@@ -0,0 +1,47 | |||
|
1 | + #!/usr/bin/env ruby | |
|
2 | + | |
|
3 | + APP_PATH = File.expand_path('../../config/application', __FILE__) | |
|
4 | + require File.expand_path('../../config/boot', __FILE__) | |
|
5 | + require APP_PATH | |
|
6 | + | |
|
7 | + # set Rails.env here if desired | |
|
8 | + Rails.application.require_environment! | |
|
9 | + | |
|
10 | + def main | |
|
11 | + if ARGV.length != 1 | |
|
12 | + puts "Usage: contest_grade_prob.rb [problem_name]" | |
|
13 | + exit(0) | |
|
14 | + end | |
|
15 | + | |
|
16 | + problem_name = ARGV[0] | |
|
17 | + problem = Problem.where(:name => problem_name).first | |
|
18 | + if !problem | |
|
19 | + puts "Problem not found" | |
|
20 | + exit(0) | |
|
21 | + end | |
|
22 | + | |
|
23 | + problem.full_score = 100 | |
|
24 | + problem.save | |
|
25 | + | |
|
26 | + test_pair = TestPair.get_for(problem, true) | |
|
27 | + | |
|
28 | + User.all.each do |u| | |
|
29 | + puts "#{u.login}:" | |
|
30 | + submissions = Submission.find_all_by_user_problem(u.id, problem.id) | |
|
31 | + submissions.each do |sub| | |
|
32 | + result = test_pair.grade(sub.output) | |
|
33 | + result2 = test_pair.grade(sub.source) | |
|
34 | + if result2[:score] > result[:score] | |
|
35 | + result = result2 | |
|
36 | + puts "Use source field (#{sub.id})" | |
|
37 | + end | |
|
38 | + | |
|
39 | + full_score = result[:full_score] | |
|
40 | + sub.points = result[:score]*100 / full_score | |
|
41 | + sub.grader_comment = result[:msg] | |
|
42 | + sub.save | |
|
43 | + end | |
|
44 | + end | |
|
45 | + end | |
|
46 | + | |
|
47 | + main |
@@ -286,7 +286,7 | |||
|
286 | 286 | if (params['output_file']) and (params['output_file']!='') |
|
287 | 287 | output = params['output_file'].read |
|
288 | 288 | |
|
289 |
- @grading_result = grade(output |
|
|
289 | + @grading_result = test_pair.grade(output) | |
|
290 | 290 | prepare_list_information |
|
291 | 291 | render :action => 'list' and return |
|
292 | 292 | else |
@@ -298,30 +298,6 | |||
|
298 | 298 | |
|
299 | 299 | protected |
|
300 | 300 | |
|
301 | - def grade(output, solution) | |
|
302 | - out_items = output.split("\n") | |
|
303 | - sol_items = solution.split("\n") | |
|
304 | - res = '' | |
|
305 | - f = 0 | |
|
306 | - s = 0 | |
|
307 | - sol_items.length.times do |i| | |
|
308 | - f += 1 | |
|
309 | - si = sol_items[i].chomp | |
|
310 | - if out_items[i] | |
|
311 | - oi = out_items[i].chomp | |
|
312 | - else | |
|
313 | - oi = '' | |
|
314 | - end | |
|
315 | - if oi == si | |
|
316 | - res = res + 'P' | |
|
317 | - s += 1 | |
|
318 | - else | |
|
319 | - res = res + '-' | |
|
320 | - end | |
|
321 | - end | |
|
322 | - return { :score => s, :full_score => f, :msg => res } | |
|
323 | - end | |
|
324 | - | |
|
325 | 301 | def prepare_announcements(recent=nil) |
|
326 | 302 | if GraderConfiguration.show_tasks_to?(@user) |
|
327 | 303 | @announcements = Announcement.find_published(true) |
@@ -5,4 +5,29 | |||
|
5 | 5 | return TestPair.where(:problem_id => problem.id, |
|
6 | 6 | :is_private => is_private).first |
|
7 | 7 | end |
|
8 | + | |
|
9 | + def grade(output) | |
|
10 | + out_items = output.split("\n") | |
|
11 | + sol_items = solution.split("\n") | |
|
12 | + res = '' | |
|
13 | + f = 0 | |
|
14 | + s = 0 | |
|
15 | + sol_items.length.times do |i| | |
|
16 | + f += 1 | |
|
17 | + si = sol_items[i].chomp | |
|
18 | + if out_items[i] | |
|
19 | + oi = out_items[i].chomp | |
|
20 | + else | |
|
21 | + oi = '' | |
|
22 | + end | |
|
23 | + if oi == si | |
|
24 | + res = res + 'P' | |
|
25 | + s += 1 | |
|
26 | + else | |
|
27 | + res = res + '-' | |
|
28 | + end | |
|
29 | + end | |
|
30 | + return { :score => s, :full_score => f, :msg => res } | |
|
31 | + end | |
|
32 | + | |
|
8 | 33 | end |
You need to be logged in to leave comments.
Login now