Description:
let testdata importer set the full score
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r345:d3662f88d75c - - 1 file changed: 11 inserted, 0 deleted
@@ -13,48 +13,49 | |||||
|
13 | memory_limit, |
|
13 | memory_limit, |
|
14 | import_to_db=false) |
|
14 | import_to_db=false) |
|
15 |
|
15 | ||
|
16 | dirname = extract(tempfile) |
|
16 | dirname = extract(tempfile) |
|
17 | return false if not dirname |
|
17 | return false if not dirname |
|
18 | if not import_to_db |
|
18 | if not import_to_db |
|
19 | @log_msg = GraderScript.call_import_problem(@problem.name, |
|
19 | @log_msg = GraderScript.call_import_problem(@problem.name, |
|
20 | dirname, |
|
20 | dirname, |
|
21 | time_limit, |
|
21 | time_limit, |
|
22 | memory_limit) |
|
22 | memory_limit) |
|
23 | else |
|
23 | else |
|
24 | # Import test data to test pairs. |
|
24 | # Import test data to test pairs. |
|
25 |
|
25 | ||
|
26 | @problem.test_pairs.clear |
|
26 | @problem.test_pairs.clear |
|
27 | if import_test_pairs(dirname) |
|
27 | if import_test_pairs(dirname) |
|
28 | test_pair_count = TestPair.count :conditions => "problem_id = #{@problem.id}" |
|
28 | test_pair_count = TestPair.count :conditions => "problem_id = #{@problem.id}" |
|
29 | @log_msg = "Importing test pair successful. (#{test_pair_count} test pairs imported)" |
|
29 | @log_msg = "Importing test pair successful. (#{test_pair_count} test pairs imported)" |
|
30 | else |
|
30 | else |
|
31 | @log_msg = "Importing test pair failed. (0 test pairs imported)" |
|
31 | @log_msg = "Importing test pair failed. (0 test pairs imported)" |
|
32 | end |
|
32 | end |
|
33 | end |
|
33 | end |
|
34 |
|
34 | ||
|
35 | @log_msg << import_problem_description(dirname) |
|
35 | @log_msg << import_problem_description(dirname) |
|
36 | @log_msg << import_problem_pdf(dirname) |
|
36 | @log_msg << import_problem_pdf(dirname) |
|
|
37 | + @log_msg << import_full_score(dirname) | ||
|
37 |
|
38 | ||
|
38 | return true |
|
39 | return true |
|
39 | end |
|
40 | end |
|
40 |
|
41 | ||
|
41 | protected |
|
42 | protected |
|
42 |
|
43 | ||
|
43 | def self.long_ext(filename) |
|
44 | def self.long_ext(filename) |
|
44 | i = filename.index('.') |
|
45 | i = filename.index('.') |
|
45 | len = filename.length |
|
46 | len = filename.length |
|
46 | return filename.slice(i..len) |
|
47 | return filename.slice(i..len) |
|
47 | end |
|
48 | end |
|
48 |
|
49 | ||
|
49 | def extract(tempfile) |
|
50 | def extract(tempfile) |
|
50 | testdata_filename = save_testdata_file(tempfile) |
|
51 | testdata_filename = save_testdata_file(tempfile) |
|
51 | ext = TestdataImporter.long_ext(tempfile.original_filename) |
|
52 | ext = TestdataImporter.long_ext(tempfile.original_filename) |
|
52 |
|
53 | ||
|
53 | extract_dir = File.join(GraderScript.raw_dir, @problem.name) |
|
54 | extract_dir = File.join(GraderScript.raw_dir, @problem.name) |
|
54 | if File.exists? extract_dir |
|
55 | if File.exists? extract_dir |
|
55 | backup_count = 0 |
|
56 | backup_count = 0 |
|
56 | begin |
|
57 | begin |
|
57 | backup_count += 1 |
|
58 | backup_count += 1 |
|
58 | backup_dirname = "#{extract_dir}.backup.#{backup_count}" |
|
59 | backup_dirname = "#{extract_dir}.backup.#{backup_count}" |
|
59 | end while File.exists? backup_dirname |
|
60 | end while File.exists? backup_dirname |
|
60 | File.rename(extract_dir, backup_dirname) |
|
61 | File.rename(extract_dir, backup_dirname) |
@@ -148,25 +149,35 | |||||
|
148 | puts "HAS PDF FILE" |
|
149 | puts "HAS PDF FILE" |
|
149 | filename = pdf_files[0] |
|
150 | filename = pdf_files[0] |
|
150 |
|
151 | ||
|
151 | @problem.save if not @problem.id |
|
152 | @problem.save if not @problem.id |
|
152 | out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}" |
|
153 | out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}" |
|
153 | if not FileTest.exists? out_dirname |
|
154 | if not FileTest.exists? out_dirname |
|
154 | Dir.mkdir out_dirname |
|
155 | Dir.mkdir out_dirname |
|
155 | end |
|
156 | end |
|
156 |
|
157 | ||
|
157 | out_filename = "#{out_dirname}/#{@problem.name}.pdf" |
|
158 | out_filename = "#{out_dirname}/#{@problem.name}.pdf" |
|
158 |
|
159 | ||
|
159 | if FileTest.exists? out_filename |
|
160 | if FileTest.exists? out_filename |
|
160 | File.delete out_filename |
|
161 | File.delete out_filename |
|
161 | end |
|
162 | end |
|
162 |
|
163 | ||
|
163 | File.rename(filename, out_filename) |
|
164 | File.rename(filename, out_filename) |
|
164 | @problem.description_filename = "#{@problem.name}.pdf" |
|
165 | @problem.description_filename = "#{@problem.name}.pdf" |
|
165 | @problem.save |
|
166 | @problem.save |
|
166 | return "\nProblem pdf imported from #{filename}." |
|
167 | return "\nProblem pdf imported from #{filename}." |
|
167 | else |
|
168 | else |
|
168 | return "" |
|
169 | return "" |
|
169 | end |
|
170 | end |
|
170 | end |
|
171 | end |
|
171 |
|
172 | ||
|
|
173 | + #just set the full score to the total number of test case | ||
|
|
174 | + #it is not perfect but works on most normal use case | ||
|
|
175 | + def import_full_score(dirname) | ||
|
|
176 | + in_file = Dir["#{dirname}/*.in"] | ||
|
|
177 | + full_score =in_file.length * 10 | ||
|
|
178 | + @problem.full_score = full_score | ||
|
|
179 | + @problem.save | ||
|
|
180 | + return "\nFull score is set to #{full_score}." | ||
|
172 | end |
|
181 | end |
|
|
182 | + | ||
|
|
183 | + end |
You need to be logged in to leave comments.
Login now