diff --git a/check_similar b/check_similar new file mode 100755 --- /dev/null +++ b/check_similar @@ -0,0 +1,93 @@ +#!/usr/bin/env ruby + +def config + Grader::Configuration.get_instance +end + +def display_manual + puts < false, + } + + + if ARGV.length == 2 + options[:sub1] = ARGV[0].to_i + options[:sub2] = ARGV[1].to_i + elsif ARGV.length == 1 + options[:problem] = ARGV[0] + end + + + return options +end + +def compare(sub1,sub2,full = sub1.problem.full_score) + dis = @jarow.getDistance(sub1.source, sub2.source) + puts [sub1.user.login,"##{sub1.id}",(sub1.points * 100.0 / full).to_i, + sub2.user.login,"##{sub2.id}",(sub2.points * 100.0 / full).to_i, + "#{dis * 100}%"].join(',') +end + +######################################### +# main program +######################################### + +options = process_options_and_stop_file + +# load grader environment +GRADER_ENV = 'grading' +require File.join(File.dirname(__FILE__),'config/environment') + +# boot rails, to be able to use the active record +RAILS_ENV = config.rails_env +require RAILS_ROOT + '/config/environment' + +# load comparator +require 'fuzzystringmatch' +@jarow = FuzzyStringMatch::JaroWinkler.create( :native ) + +if options[:problem] + p = Problem.where(name: options[:problem]).first + unless p + puts "cannot find problem #{options[:problem]}" + exit(0) + end + subs = Submission.where(problem: p) + full_score = p.full_score.to_i + subs.each.with_index do |s1,i| + puts "processing #{i+1} out of #{subs.length}" + subs.each do |s2| + if s1.user != s2.user + compare(s1,s2,full_score) + end + end + end +else + sub1 = Submission.find(options[:sub1]) + sub2 = Submission.find(options[:sub2]) + compare(sub1,sub2) +end + diff --git a/grader-process-check b/grader-process-check new file mode 100755 --- /dev/null +++ b/grader-process-check @@ -0,0 +1,6 @@ +#!/bin/bash +count=`ps aux | grep "cafe_grader" | grep "grader grading queue" | wc -l` +if [ $count -lt 1 ]; then + cd /home/dae/cafe_grader/judge + /home/dae/.rvm/wrappers/ruby-2.3.0/ruby /home/dae/cafe_grader/judge/scripts/grader grading queue > /home/dae/grading.log & +fi diff --git a/import_problem b/import_problem --- a/import_problem +++ b/import_problem @@ -145,6 +145,12 @@ end end + #also include any .txt files + Dir.glob("#{testcase_dir}/*.txt") do |file| + puts "copy data file #{file}" + FileUtils.cp(file,"#{problem_dir}") + end + # generating all_tests.cfg puts "generating testcase config file" diff --git a/load_testcase b/load_testcase --- a/load_testcase +++ b/load_testcase @@ -20,7 +20,7 @@ def process_options_and_stop_file # Process 'help' option - if (ARGV.length==1) and (/help/.match(ARGV[0])) + if (ARGV.length == 0) or ((ARGV.length==1) and (/help/.match(ARGV[0]))) display_manual exit(0) end @@ -74,7 +74,7 @@ require RAILS_ROOT + '/config/environment' if options[:all] - Problem.all.each { |prob| process_problem(prob,options[:all]) } + Problem.all.each { |prob| process_problem(prob,options[:dry_run]) } else ARGV.each do |name| prob = Problem.find_by(name: name) diff --git a/rename_problem b/rename_problem --- a/rename_problem +++ b/rename_problem @@ -8,7 +8,7 @@ def rename_problem(old_problem_name, new_problem_name) - if valid_problem_name(new_problem_name) + unless valid_problem_name(new_problem_name) puts "Bad new problem name: #{new_problem_name}" return end @@ -60,7 +60,7 @@ if name.length==0: return false else - return !(/^[a-zA-Z0-9_\-]+$/ === name) + return (/^[a-zA-Z0-9_\-]+$/ === name) end end diff --git a/std-script/judge b/std-script/judge --- a/std-script/judge +++ b/std-script/judge @@ -140,6 +140,12 @@ if language == "python" then Dir["#{test_result_dir}/*.pyc"].each { |file| FileUtils.cp(file,sandbox_dir)} end } + #additionally copy any extra .txt file + data_files = Dir[problem_home + '/*.txt'] + data_files.each do |file| + FileUtils.cp(file,sandbox_dir) + end + begin execute("#{problem_home}/script/run #{language} #{test_num} ", "Error occured during execution of the run script") rescue diff --git a/templates/check.float b/templates/check.float --- a/templates/check.float +++ b/templates/check.float @@ -47,6 +47,11 @@ ########### THIS IS FOR CHECKING FLOAT with EPSILON error ########## + +def is_float?(fl) + !!Float(fl) rescue false +end + EPSILON = 0.000001 out_items = output_file_content.split @@ -56,10 +61,14 @@ report_wrong.call else out_items.length.times do |i| - out_value = out_items[i].to_f - ans_value = ans_items[i].to_f - if (out_value - ans_value).abs > EPSILON * [out_value.abs,ans_value.abs].max - report_wrong.call + if is_float?(out_items[i]) && is_float?(ans_items[i]) + out_value = out_items[i].to_f + ans_value = ans_items[i].to_f + if (out_value - ans_value).abs > EPSILON * [out_value.abs,ans_value.abs].max + report_wrong.call + end + else + report_wrong.call if out_items[i] != ans_items[i] end end report_correct.call