Description:
let testdata importer set the full score
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r345:d3662f88d75c - - 1 file changed: 11 inserted, 0 deleted

@@ -13,48 +13,49
13 13 memory_limit,
14 14 import_to_db=false)
15 15
16 16 dirname = extract(tempfile)
17 17 return false if not dirname
18 18 if not import_to_db
19 19 @log_msg = GraderScript.call_import_problem(@problem.name,
20 20 dirname,
21 21 time_limit,
22 22 memory_limit)
23 23 else
24 24 # Import test data to test pairs.
25 25
26 26 @problem.test_pairs.clear
27 27 if import_test_pairs(dirname)
28 28 test_pair_count = TestPair.count :conditions => "problem_id = #{@problem.id}"
29 29 @log_msg = "Importing test pair successful. (#{test_pair_count} test pairs imported)"
30 30 else
31 31 @log_msg = "Importing test pair failed. (0 test pairs imported)"
32 32 end
33 33 end
34 34
35 35 @log_msg << import_problem_description(dirname)
36 36 @log_msg << import_problem_pdf(dirname)
37 + @log_msg << import_full_score(dirname)
37 38
38 39 return true
39 40 end
40 41
41 42 protected
42 43
43 44 def self.long_ext(filename)
44 45 i = filename.index('.')
45 46 len = filename.length
46 47 return filename.slice(i..len)
47 48 end
48 49
49 50 def extract(tempfile)
50 51 testdata_filename = save_testdata_file(tempfile)
51 52 ext = TestdataImporter.long_ext(tempfile.original_filename)
52 53
53 54 extract_dir = File.join(GraderScript.raw_dir, @problem.name)
54 55 if File.exists? extract_dir
55 56 backup_count = 0
56 57 begin
57 58 backup_count += 1
58 59 backup_dirname = "#{extract_dir}.backup.#{backup_count}"
59 60 end while File.exists? backup_dirname
60 61 File.rename(extract_dir, backup_dirname)
@@ -148,25 +149,35
148 149 puts "HAS PDF FILE"
149 150 filename = pdf_files[0]
150 151
151 152 @problem.save if not @problem.id
152 153 out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}"
153 154 if not FileTest.exists? out_dirname
154 155 Dir.mkdir out_dirname
155 156 end
156 157
157 158 out_filename = "#{out_dirname}/#{@problem.name}.pdf"
158 159
159 160 if FileTest.exists? out_filename
160 161 File.delete out_filename
161 162 end
162 163
163 164 File.rename(filename, out_filename)
164 165 @problem.description_filename = "#{@problem.name}.pdf"
165 166 @problem.save
166 167 return "\nProblem pdf imported from #{filename}."
167 168 else
168 169 return ""
169 170 end
170 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}."
181 + end
182 +
172 183 end
You need to be logged in to leave comments. Login now