# HG changeset patch # User Jittat Fakcharoenphol # Date 2015-02-01 10:32:53 # Node ID 865ba2aed5c0340a6681e4f51180dffb1f9519fc # Parent 7f104b042855c894bc0ef49d9b5435e85d4b69ce grades contest submissions diff --git a/app/controllers/main_controller.rb b/app/controllers/main_controller.rb --- a/app/controllers/main_controller.rb +++ b/app/controllers/main_controller.rb @@ -286,7 +286,7 @@ if (params['output_file']) and (params['output_file']!='') output = params['output_file'].read - @grading_result = grade(output, test_pair.solution) + @grading_result = test_pair.grade(output) prepare_list_information render :action => 'list' and return else @@ -298,30 +298,6 @@ protected - def grade(output, solution) - out_items = output.split("\n") - sol_items = solution.split("\n") - res = '' - f = 0 - s = 0 - sol_items.length.times do |i| - f += 1 - si = sol_items[i].chomp - if out_items[i] - oi = out_items[i].chomp - else - oi = '' - end - if oi == si - res = res + 'P' - s += 1 - else - res = res + '-' - end - end - return { :score => s, :full_score => f, :msg => res } - end - def prepare_announcements(recent=nil) if GraderConfiguration.show_tasks_to?(@user) @announcements = Announcement.find_published(true) diff --git a/app/models/test_pair.rb b/app/models/test_pair.rb --- a/app/models/test_pair.rb +++ b/app/models/test_pair.rb @@ -5,4 +5,29 @@ return TestPair.where(:problem_id => problem.id, :is_private => is_private).first end + + def grade(output) + out_items = output.split("\n") + sol_items = solution.split("\n") + res = '' + f = 0 + s = 0 + sol_items.length.times do |i| + f += 1 + si = sol_items[i].chomp + if out_items[i] + oi = out_items[i].chomp + else + oi = '' + end + if oi == si + res = res + 'P' + s += 1 + else + res = res + '-' + end + end + return { :score => s, :full_score => f, :msg => res } + end + end diff --git a/script/contest_grade_prob.rb b/script/contest_grade_prob.rb new file mode 100644 --- /dev/null +++ b/script/contest_grade_prob.rb @@ -0,0 +1,47 @@ +#!/usr/bin/env ruby + +APP_PATH = File.expand_path('../../config/application', __FILE__) +require File.expand_path('../../config/boot', __FILE__) +require APP_PATH + +# set Rails.env here if desired +Rails.application.require_environment! + +def main + if ARGV.length != 1 + puts "Usage: contest_grade_prob.rb [problem_name]" + exit(0) + end + + problem_name = ARGV[0] + problem = Problem.where(:name => problem_name).first + if !problem + puts "Problem not found" + exit(0) + end + + problem.full_score = 100 + problem.save + + test_pair = TestPair.get_for(problem, true) + + User.all.each do |u| + puts "#{u.login}:" + submissions = Submission.find_all_by_user_problem(u.id, problem.id) + submissions.each do |sub| + result = test_pair.grade(sub.output) + result2 = test_pair.grade(sub.source) + if result2[:score] > result[:score] + result = result2 + puts "Use source field (#{sub.id})" + end + + full_score = result[:full_score] + sub.points = result[:score]*100 / full_score + sub.grader_comment = result[:msg] + sub.save + end + end +end + +main