Description:
merge
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r232:da875364b006 - - 1 file changed: 85 inserted, 0 deleted
@@ -0,0 +1,85 | |||
|
1 | + #!/usr/bin/env ruby | |
|
2 | + | |
|
3 | + def config | |
|
4 | + Grader::Configuration.get_instance | |
|
5 | + end | |
|
6 | + | |
|
7 | + def display_manual | |
|
8 | + puts <<USAGE | |
|
9 | + load_testcases | |
|
10 | + using: load_testcases [problem_name ...] | |
|
11 | + problem_name are list of "short name" of the problems | |
|
12 | + | |
|
13 | + options: | |
|
14 | + --dry-run do nothing, just simulate the run | |
|
15 | + --all import all problem. This might take several minutes | |
|
16 | + | |
|
17 | + USAGE | |
|
18 | + end | |
|
19 | + | |
|
20 | + def process_options_and_stop_file | |
|
21 | + | |
|
22 | + # Process 'help' option | |
|
23 | + if (ARGV.length==1) and (/help/.match(ARGV[0])) | |
|
24 | + display_manual | |
|
25 | + exit(0) | |
|
26 | + end | |
|
27 | + | |
|
28 | + #default options | |
|
29 | + options = { | |
|
30 | + :dry_run => false, | |
|
31 | + } | |
|
32 | + | |
|
33 | + options[:dry_run] = (ARGV.delete('--dry') != nil) | |
|
34 | + options[:all] = (ARGV.delete('--all') != nil) | |
|
35 | + | |
|
36 | + return options | |
|
37 | + end | |
|
38 | + | |
|
39 | + def process_problem(prob,dry_run = false) | |
|
40 | + prob.testcases.destroy_all | |
|
41 | + testcases_root = File.expand_path(GRADER_ROOT+"/../ev/#{prob.name}/test_cases/") | |
|
42 | + num = 1 | |
|
43 | + puts "Processing problem #{prob.name}" | |
|
44 | + loop do | |
|
45 | + file_root = testcases_root + "/#{num}/" | |
|
46 | + puts " checking file #{file_root}" | |
|
47 | + break unless File.exists? file_root | |
|
48 | + input = File.read(file_root + "/input-#{num}.txt") | |
|
49 | + answer = File.read(file_root + "/answer-#{num}.txt") | |
|
50 | + puts " got test case ##{num} of size #{input.size} and #{answer.size}" | |
|
51 | + | |
|
52 | + #THIS IS JUST A PLACE HOLDER | |
|
53 | + group = num #this is wrong!!! fix it!! | |
|
54 | + score = 10 | |
|
55 | + #BEWARE | |
|
56 | + | |
|
57 | + prob.testcases.create(input: input,sol: answer, num: num, score:score,group: group) unless dry_run | |
|
58 | + num += 1 | |
|
59 | + end | |
|
60 | + end | |
|
61 | + | |
|
62 | + ######################################### | |
|
63 | + # main program | |
|
64 | + ######################################### | |
|
65 | + | |
|
66 | + options = process_options_and_stop_file | |
|
67 | + | |
|
68 | + # load grader environment | |
|
69 | + GRADER_ENV = 'grading' | |
|
70 | + require File.join(File.dirname(__FILE__),'config/environment') | |
|
71 | + | |
|
72 | + # boot rails, to be able to use the active record | |
|
73 | + RAILS_ENV = config.rails_env | |
|
74 | + require RAILS_ROOT + '/config/environment' | |
|
75 | + | |
|
76 | + if options[:all] | |
|
77 | + Problem.all.each { |prob| process_problem(prob,options[:all]) } | |
|
78 | + else | |
|
79 | + ARGV.each do |name| | |
|
80 | + prob = Problem.find_by(name: name) | |
|
81 | + process_problem(prob,options[:dry_run]) if prob | |
|
82 | + puts "Cannot find the problem #{name}" unless prob | |
|
83 | + end | |
|
84 | + end | |
|
85 | + |
You need to be logged in to leave comments.
Login now