Description:
my fault, fixing auto full score to properly handle subtask case
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r346:d02b70f6c474 - - 1 file changed: 7 inserted, 2 deleted

@@ -80,104 +80,109
80 File.delete(testdata_filename)
80 File.delete(testdata_filename)
81
81
82 return File.dirname(files[0])
82 return File.dirname(files[0])
83 end
83 end
84
84
85 def save_testdata_file(tempfile)
85 def save_testdata_file(tempfile)
86 ext = TestdataImporter.long_ext(tempfile.original_filename)
86 ext = TestdataImporter.long_ext(tempfile.original_filename)
87 testdata_filename = File.join(Dir.tmpdir,"#{@problem.name}#{ext}")
87 testdata_filename = File.join(Dir.tmpdir,"#{@problem.name}#{ext}")
88
88
89 return nil if tempfile==""
89 return nil if tempfile==""
90
90
91 if tempfile.instance_of?(Tempfile)
91 if tempfile.instance_of?(Tempfile)
92 tempfile.close
92 tempfile.close
93 FileUtils.move(tempfile.path,testdata_filename)
93 FileUtils.move(tempfile.path,testdata_filename)
94 else
94 else
95 File.open(testdata_filename, "wb") do |f|
95 File.open(testdata_filename, "wb") do |f|
96 f.write(tempfile.read)
96 f.write(tempfile.read)
97 end
97 end
98 end
98 end
99
99
100 return testdata_filename
100 return testdata_filename
101 end
101 end
102
102
103 def import_test_pairs(dirname)
103 def import_test_pairs(dirname)
104 test_num = 1
104 test_num = 1
105 while FileTest.exists? "#{dirname}/#{test_num}.in"
105 while FileTest.exists? "#{dirname}/#{test_num}.in"
106 in_filename = "#{dirname}/#{test_num}.in"
106 in_filename = "#{dirname}/#{test_num}.in"
107 sol_filename = "#{dirname}/#{test_num}.sol"
107 sol_filename = "#{dirname}/#{test_num}.sol"
108
108
109 break if not FileTest.exists? sol_filename
109 break if not FileTest.exists? sol_filename
110
110
111 test_pair = TestPair.new(:input => open(in_filename).read,
111 test_pair = TestPair.new(:input => open(in_filename).read,
112 :solution => open(sol_filename).read,
112 :solution => open(sol_filename).read,
113 :problem => @problem)
113 :problem => @problem)
114 break if not test_pair.save
114 break if not test_pair.save
115
115
116 test_num += 1
116 test_num += 1
117 end
117 end
118 return test_num > 1
118 return test_num > 1
119 end
119 end
120
120
121 def import_problem_description(dirname)
121 def import_problem_description(dirname)
122 html_files = Dir["#{dirname}/*.html"]
122 html_files = Dir["#{dirname}/*.html"]
123 markdown_files = Dir["#{dirname}/*.md"] + Dir["#{dirname}/*.markdown"]
123 markdown_files = Dir["#{dirname}/*.md"] + Dir["#{dirname}/*.markdown"]
124 if (html_files.length != 0) or (markdown_files.length != 0)
124 if (html_files.length != 0) or (markdown_files.length != 0)
125 description = @problem.description || Description.new
125 description = @problem.description || Description.new
126
126
127 if html_files.length != 0
127 if html_files.length != 0
128 filename = html_files[0]
128 filename = html_files[0]
129 description.markdowned = false
129 description.markdowned = false
130 else
130 else
131 filename = markdown_files[0]
131 filename = markdown_files[0]
132 description.markdowned = true
132 description.markdowned = true
133 end
133 end
134
134
135 description.body = open(filename).read
135 description.body = open(filename).read
136 description.save
136 description.save
137 @problem.description = description
137 @problem.description = description
138 @problem.save
138 @problem.save
139 return "\nProblem description imported from #{filename}."
139 return "\nProblem description imported from #{filename}."
140 else
140 else
141 return ''
141 return ''
142 end
142 end
143 end
143 end
144
144
145 def import_problem_pdf(dirname)
145 def import_problem_pdf(dirname)
146 pdf_files = Dir["#{dirname}/*.pdf"]
146 pdf_files = Dir["#{dirname}/*.pdf"]
147 puts "CHECKING... #{dirname}"
147 puts "CHECKING... #{dirname}"
148 if pdf_files.length != 0
148 if pdf_files.length != 0
149 puts "HAS PDF FILE"
149 puts "HAS PDF FILE"
150 filename = pdf_files[0]
150 filename = pdf_files[0]
151
151
152 @problem.save if not @problem.id
152 @problem.save if not @problem.id
153 out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}"
153 out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}"
154 if not FileTest.exists? out_dirname
154 if not FileTest.exists? out_dirname
155 Dir.mkdir out_dirname
155 Dir.mkdir out_dirname
156 end
156 end
157
157
158 out_filename = "#{out_dirname}/#{@problem.name}.pdf"
158 out_filename = "#{out_dirname}/#{@problem.name}.pdf"
159
159
160 if FileTest.exists? out_filename
160 if FileTest.exists? out_filename
161 File.delete out_filename
161 File.delete out_filename
162 end
162 end
163
163
164 File.rename(filename, out_filename)
164 File.rename(filename, out_filename)
165 @problem.description_filename = "#{@problem.name}.pdf"
165 @problem.description_filename = "#{@problem.name}.pdf"
166 @problem.save
166 @problem.save
167 return "\nProblem pdf imported from #{filename}."
167 return "\nProblem pdf imported from #{filename}."
168 else
168 else
169 return ""
169 return ""
170 end
170 end
171 end
171 end
172
172
173 #just set the full score to the total number of test case
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
174 #it is not perfect but works on most normal use case
175 def import_full_score(dirname)
175 def import_full_score(dirname)
176 - in_file = Dir["#{dirname}/*.in"]
176 + num = 0
177 - full_score =in_file.length * 10
177 + loop do
178 + num += 1
179 + in_file = Dir["#{dirname}/#{num}*.in"]
180 + break if in_file.length == 0
181 + end
182 + full_score = (num - 1) * 10
178 @problem.full_score = full_score
183 @problem.full_score = full_score
179 @problem.save
184 @problem.save
180 return "\nFull score is set to #{full_score}."
185 return "\nFull score is set to #{full_score}."
181 end
186 end
182
187
183 end
188 end
You need to be logged in to leave comments. Login now