Description:
add selectable checker (for now, only 'text' and 'float') in the problem import
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r402:7f3e18dca393 - - 4 files changed: 25 inserted, 3 deleted
@@ -22,93 +22,100 | |||
|
22 | 22 | import_params, problem = Problem.extract_params_and_check(params, |
|
23 | 23 | org_problem) |
|
24 | 24 | |
|
25 | 25 | if !problem.errors.empty? |
|
26 | 26 | return problem, 'Error importing' |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | problem.full_score = 100 |
|
30 | 30 | problem.date_added = Time.new |
|
31 | 31 | problem.test_allowed = true |
|
32 | 32 | problem.output_only = false |
|
33 | 33 | problem.available = false |
|
34 | 34 | |
|
35 | 35 | if not problem.save |
|
36 | 36 | return problem, 'Error importing' |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | import_to_db = params.has_key? :import_to_db |
|
40 | 40 | |
|
41 | 41 | importer = TestdataImporter.new(problem) |
|
42 | 42 | |
|
43 | 43 | if not importer.import_from_file(import_params[:file], |
|
44 | 44 | import_params[:time_limit], |
|
45 | 45 | import_params[:memory_limit], |
|
46 | + import_params[:checker_name], | |
|
46 | 47 | import_to_db) |
|
47 | 48 | problem.errors.add_to_base('Import error.') |
|
48 | 49 | end |
|
49 | 50 | |
|
50 | 51 | return problem, importer.log_msg |
|
51 | 52 | end |
|
52 | 53 | |
|
53 | 54 | def self.download_file_basedir |
|
54 | 55 | return "#{Rails.root}/data/tasks" |
|
55 | 56 | end |
|
56 | 57 | |
|
57 | 58 | protected |
|
58 | 59 | |
|
59 | 60 | def self.to_i_or_default(st, default) |
|
60 | 61 | if st!='' |
|
61 | 62 | result = st.to_i |
|
62 | 63 | end |
|
63 | 64 | result ||= default |
|
64 | 65 | end |
|
65 | 66 | |
|
66 | 67 | def self.to_f_or_default(st, default) |
|
67 | 68 | if st!='' |
|
68 | 69 | result = st.to_f |
|
69 | 70 | end |
|
70 | 71 | result ||= default |
|
71 | 72 | end |
|
72 | 73 | |
|
73 | 74 | def self.extract_params_and_check(params, problem) |
|
74 | 75 | time_limit = Problem.to_f_or_default(params[:time_limit], |
|
75 | 76 | DEFAULT_TIME_LIMIT) |
|
76 | 77 | memory_limit = Problem.to_i_or_default(params[:memory_limit], |
|
77 | 78 | DEFAULT_MEMORY_LIMIT) |
|
78 | 79 | |
|
79 | 80 | if time_limit<=0 or time_limit >60 |
|
80 | 81 | problem.errors.add_to_base('Time limit out of range.') |
|
81 | 82 | end |
|
82 | 83 | |
|
83 | 84 | if memory_limit==0 and params[:memory_limit]!='0' |
|
84 | 85 | problem.errors.add_to_base('Memory limit format errors.') |
|
85 | 86 | elsif memory_limit<=0 or memory_limit >512 |
|
86 | 87 | problem.errors.add_to_base('Memory limit out of range.') |
|
87 | 88 | end |
|
88 | 89 | |
|
89 | 90 | if params[:file]==nil or params[:file]=='' |
|
90 | 91 | problem.errors.add_to_base('No testdata file.') |
|
91 | 92 | end |
|
92 | 93 | |
|
94 | + checker_name = 'text' | |
|
95 | + if ['text','float'].include? params[:checker] | |
|
96 | + checker_name = params[:checker] | |
|
97 | + end | |
|
98 | + | |
|
93 | 99 | file = params[:file] |
|
94 | 100 | |
|
95 | 101 | if !problem.errors.empty? |
|
96 | 102 | return nil, problem |
|
97 | 103 | end |
|
98 | 104 | |
|
99 | 105 | problem.name = params[:name] |
|
100 | 106 | if params[:full_name]!='' |
|
101 | 107 | problem.full_name = params[:full_name] |
|
102 | 108 | else |
|
103 | 109 | problem.full_name = params[:name] |
|
104 | 110 | end |
|
105 | 111 | |
|
106 | 112 | return [{ |
|
107 | 113 | :time_limit => time_limit, |
|
108 | 114 | :memory_limit => memory_limit, |
|
109 | - :file => file | |
|
115 | + :file => file, | |
|
116 | + :checker_name => checker_name | |
|
110 | 117 | }, |
|
111 | 118 | problem] |
|
112 | 119 | end |
|
113 | 120 | |
|
114 | 121 | end |
@@ -11,48 +11,61 | |||
|
11 | 11 | = form_tag({:action => 'do_import'}, :multipart => true) do |
|
12 | 12 | .submitbox |
|
13 | 13 | %table |
|
14 | 14 | %tr |
|
15 | 15 | %td Name: |
|
16 | 16 | %td= text_field_tag 'name' |
|
17 | 17 | %tr |
|
18 | 18 | %td Full name: |
|
19 | 19 | %td |
|
20 | 20 | = text_field_tag 'full_name' |
|
21 | 21 | %span{:class => 'help'} Leave blank to use the same value as the name above. |
|
22 | 22 | %tr |
|
23 | 23 | %td Testdata file: |
|
24 | 24 | %td= file_field_tag 'file' |
|
25 | 25 | %tr |
|
26 | 26 | %td |
|
27 | 27 | %td |
|
28 | 28 | %span{:class => 'help'} |
|
29 | 29 | In .zip, .tgz, tar.gz, .tar format. |
|
30 | 30 | It should includes inputs (e.g., 1.in, 2a.in, 2b.in) |
|
31 | 31 | and solutions (e.g., 1.sol, 2a.sol, 2b.sol). |
|
32 | 32 | %br/ |
|
33 | 33 | You may put task description in *.html for raw html |
|
34 | 34 | and *.md or *.markdown for markdown. |
|
35 | + %br/ | |
|
36 | + You may also put a pdf file for the task description | |
|
37 | + %tr | |
|
38 | + %td Checker: | |
|
39 | + %td= select_tag 'checker', options_for_select([['Text checker','text'],['Float checker','float']], 'text') | |
|
40 | + %tr | |
|
41 | + %td | |
|
42 | + %td | |
|
43 | + %span{:class => 'help'} | |
|
44 | + "Text" checker checks if the text (including numbers) is the same, ignoring any whitespace | |
|
45 | + %br/ | |
|
46 | + "Float" checker checks if all numbers is within EPSILON error using formula |a-b| < EPSILON * max(|a|,|b|) | |
|
47 | + | |
|
35 | 48 | - if @allow_test_pair_import |
|
36 | 49 | %tr |
|
37 | 50 | %td |
|
38 | 51 | %td |
|
39 | 52 | = check_box_tag 'import_to_db' |
|
40 | 53 | Import test data to database (for a test-pair task) |
|
41 | 54 | %tr |
|
42 | 55 | %td Time limit: |
|
43 | 56 | %td |
|
44 | 57 | = text_field_tag 'time_limit' |
|
45 | 58 | %span{:class => 'help'} In seconds. Leave blank to use 1 sec. |
|
46 | 59 | %tr |
|
47 | 60 | %td Memory limit: |
|
48 | 61 | %td |
|
49 | 62 | = text_field_tag 'memory_limit' |
|
50 | 63 | %span{:class => 'help'} In MB. Leave blank to use 32MB. |
|
51 | 64 | %tr |
|
52 | 65 | %td |
|
53 | 66 | %td= submit_tag 'Import problem' |
|
54 | 67 | |
|
55 | 68 | - if @log |
|
56 | 69 | %h3 Import log |
|
57 | 70 | %pre.import-log |
|
58 | 71 | = @log |
@@ -29,30 +29,30 | |||
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | def self.start_grader(env) |
|
32 | 32 | GraderScript.call_grader "#{env} queue &" |
|
33 | 33 | GraderScript.call_grader "#{env} test_request &" |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def self.call_import_problem(problem_name, |
|
37 | 37 | problem_dir, |
|
38 | 38 | time_limit=1, |
|
39 | 39 | memory_limit=32, |
|
40 | 40 | checker_name='text') |
|
41 | 41 | if GraderScript.grader_control_enabled? |
|
42 | 42 | cur_dir = `pwd`.chomp |
|
43 | 43 | Dir.chdir(GRADER_ROOT_DIR) |
|
44 | 44 | |
|
45 | 45 | script_name = File.join(GRADER_ROOT_DIR, "scripts/import_problem") |
|
46 | 46 | cmd = "#{script_name} #{problem_name} #{problem_dir} #{checker_name}" + |
|
47 | 47 | " -t #{time_limit} -m #{memory_limit}" |
|
48 | 48 | |
|
49 | 49 | output = `#{cmd}` |
|
50 | 50 | |
|
51 | 51 | Dir.chdir(cur_dir) |
|
52 | 52 | |
|
53 | - return output | |
|
53 | + return "import CMD: #{cmd}\n" + output | |
|
54 | 54 | end |
|
55 | 55 | return '' |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | end |
@@ -1,46 +1,48 | |||
|
1 | 1 | require 'tmpdir' |
|
2 | 2 | |
|
3 | 3 | class TestdataImporter |
|
4 | 4 | |
|
5 | 5 | attr :log_msg |
|
6 | 6 | |
|
7 | 7 | def initialize(problem) |
|
8 | 8 | @problem = problem |
|
9 | 9 | end |
|
10 | 10 | |
|
11 | 11 | def import_from_file(tempfile, |
|
12 | 12 | time_limit, |
|
13 | 13 | memory_limit, |
|
14 | + checker_name='text', | |
|
14 | 15 | import_to_db=false) |
|
15 | 16 | |
|
16 | 17 | dirname = extract(tempfile) |
|
17 | 18 | return false if not dirname |
|
18 | 19 | if not import_to_db |
|
19 | 20 | @log_msg = GraderScript.call_import_problem(@problem.name, |
|
20 | 21 | dirname, |
|
21 | 22 | time_limit, |
|
22 |
- memory_limit |
|
|
23 | + memory_limit, | |
|
24 | + checker_name) | |
|
23 | 25 | else |
|
24 | 26 | # Import test data to test pairs. |
|
25 | 27 | |
|
26 | 28 | @problem.test_pairs.clear |
|
27 | 29 | if import_test_pairs(dirname) |
|
28 | 30 | test_pair_count = TestPair.count :conditions => "problem_id = #{@problem.id}" |
|
29 | 31 | @log_msg = "Importing test pair successful. (#{test_pair_count} test pairs imported)" |
|
30 | 32 | else |
|
31 | 33 | @log_msg = "Importing test pair failed. (0 test pairs imported)" |
|
32 | 34 | end |
|
33 | 35 | end |
|
34 | 36 | |
|
35 | 37 | @log_msg << import_problem_description(dirname) |
|
36 | 38 | @log_msg << import_problem_pdf(dirname) |
|
37 | 39 | @log_msg << import_full_score(dirname) |
|
38 | 40 | |
|
39 | 41 | return true |
|
40 | 42 | end |
|
41 | 43 | |
|
42 | 44 | protected |
|
43 | 45 | |
|
44 | 46 | def self.long_ext(filename) |
|
45 | 47 | i = filename.index('.') |
|
46 | 48 | len = filename.length |
You need to be logged in to leave comments.
Login now