# HG changeset patch # User Nattee Niparnan # Date 2017-01-05 05:45:11 # Node ID c71544f86b140cf7ff4ae3a2938bc6aa6394ea22 # Parent d275da5f0fc598421cc272d53431dd565013fe47 load testcase script diff --git a/import_problem b/import_problem --- a/import_problem +++ b/import_problem @@ -132,29 +132,29 @@ testrun_info.each do |testrun| tr_num += 1 puts "testrun: #{tr_num}" - + testrun.each do |testcase_info| testcase_num, testcase_fname = testcase_info - + puts "copy #{testcase_fname} to #{testcase_num}" - + create_dir_if_not_exists("#{problem_dir}/test_cases/#{testcase_num}") copy_testcase("#{testcase_dir}",testcase_fname,"#{problem_dir}/test_cases/#{testcase_num}",testcase_num) - + num_testcases += 1 end end - + # generating all_tests.cfg puts "generating testcase config file" - + template = File.open(SCRIPT_DIR + "/templates/all_tests.cfg.erb").read all_test_cfg = ERB.new(template) - + cfg_file = File.open("#{problem_dir}/test_cases/all_tests.cfg","w") cfg_file.puts all_test_cfg.result binding cfg_file.close - + # copy check script if res = /^wrapper:(.*)$/.match(check_script) # wrapper script @@ -162,13 +162,13 @@ script_name = File.basename(check_script_fname) check_wrapper_template = File.open(SCRIPT_DIR + "/templates/check_wrapper").read check_wrapper = ERB.new(check_wrapper_template) - + check_file = File.open("#{problem_dir}/script/check","w") check_file.puts check_wrapper.result binding check_file.close - + File.chmod(0755,"#{problem_dir}/script/check") - + FileUtils.cp("#{check_script_fname}", "#{problem_dir}/script/#{script_name}") else if File.exists?(SCRIPT_DIR + "/templates/check.#{check_script}") @@ -178,24 +178,24 @@ end FileUtils.cp("#{check_script_fname}", "#{problem_dir}/script/check", :preserve => true) end - + # generating test_request directory puts "generating test_request template" FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/script") FileUtils.mkdir_p("#{ev_dir}/test_request/#{problem}/test_cases/1") - + template = File.open(SCRIPT_DIR + "/templates/test_request_all_tests.cfg.erb").read test_request_all_test_cfg = ERB.new(template) - + cfg_file = File.open("#{ev_dir}/test_request/#{problem}/test_cases/all_tests.cfg","w") cfg_file.puts test_request_all_test_cfg.result cfg_file.close - + FileUtils.cp("#{SCRIPT_DIR}/templates/check_empty", "#{ev_dir}/test_request/#{problem}/script/check") FileUtils.cp("#{SCRIPT_DIR}/templates/answer-1.txt", "#{ev_dir}/test_request/#{problem}/test_cases/1") - + puts "done" end diff --git a/load_testcase.rb b/load_testcase.rb new file mode 100755 --- /dev/null +++ b/load_testcase.rb @@ -0,0 +1,85 @@ +#!/usr/bin/env ruby + +def config + Grader::Configuration.get_instance +end + +def display_manual + puts < false, + } + + options[:dry_run] = (ARGV.delete('--dry') != nil) + options[:all] = (ARGV.delete('--all') != nil) + + return options +end + +def process_problem(prob,dry_run = false) + prob.testcases.destroy_all + testcases_root = File.expand_path(GRADER_ROOT+"/../ev/#{prob.name}/test_cases/") + num = 1 + puts "Processing problem #{prob.name}" + loop do + file_root = testcases_root + "/#{num}/" + puts " checking file #{file_root}" + break unless File.exists? file_root + input = File.read(file_root + "/input-#{num}.txt") + answer = File.read(file_root + "/answer-#{num}.txt") + puts " got test case ##{num} of size #{input.size} and #{answer.size}" + + #THIS IS JUST A PLACE HOLDER + group = num #this is wrong!!! fix it!! + score = 10 + #BEWARE + + prob.testcases.create(input: input,sol: answer, num: num, score:score,group: group) unless dry_run + num += 1 + end +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' + +if options[:all] + Problem.all.each { |prob| process_problem(prob,options[:all]) } +else + ARGV.each do |name| + prob = Problem.find_by(name: name) + process_problem(prob,options[:dry_run]) if prob + puts "Cannot find the problem #{name}" unless prob + end +end +