Description:
checks solution by lines
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r384:7f104b042855 - - 1 file changed: 9 inserted, 3 deleted
@@ -254,104 +254,110 | |||
|
254 | 254 | if !problem.available |
|
255 | 255 | flash[:notice] = 'Error: problem is not available' |
|
256 | 256 | redirect_to :action => 'list' |
|
257 | 257 | else |
|
258 | 258 | test_pair = TestPair.get_for(problem, true) |
|
259 | 259 | |
|
260 | 260 | user = User.find(session[:user_id]) |
|
261 | 261 | assignment = user.get_test_pair_assignment_for(problem) |
|
262 | 262 | |
|
263 | 263 | if !assignment |
|
264 | 264 | assignment = TestPairAssignment.create_for(user, problem, test_pair) |
|
265 | 265 | assignment.save |
|
266 | 266 | end |
|
267 | 267 | |
|
268 | 268 | send_data(test_pair.input, |
|
269 | 269 | {:filename => problem.name + '-input.txt', |
|
270 | 270 | :type => 'text/plain'}) |
|
271 | 271 | end |
|
272 | 272 | end |
|
273 | 273 | |
|
274 | 274 | def verifying_submit |
|
275 | 275 | user = User.find(session[:user_id]) |
|
276 | 276 | problem_id = params[:id] |
|
277 | 277 | problem = Problem.find(problem_id) |
|
278 | 278 | |
|
279 | 279 | if !problem or !problem.available |
|
280 | 280 | flash[:notice] = 'Error: problem is not available' |
|
281 | 281 | redirect_to :action => 'list' and return |
|
282 | 282 | end |
|
283 | 283 | |
|
284 | 284 | @current_problem = problem |
|
285 | 285 | test_pair = TestPair.get_for(problem, false) |
|
286 | 286 | if (params['output_file']) and (params['output_file']!='') |
|
287 | 287 | output = params['output_file'].read |
|
288 | 288 | |
|
289 | 289 | @grading_result = grade(output, test_pair.solution) |
|
290 | 290 | prepare_list_information |
|
291 | 291 | render :action => 'list' and return |
|
292 | 292 | else |
|
293 | 293 | flash[:notice] = 'Error: output file errors' |
|
294 | 294 | prepare_list_information |
|
295 | 295 | render :action => 'list' and return |
|
296 | 296 | end |
|
297 | 297 | end |
|
298 | 298 | |
|
299 | 299 | protected |
|
300 | 300 | |
|
301 | 301 | def grade(output, solution) |
|
302 | - out_items = output.split | |
|
303 | - sol_items = solution.split | |
|
302 | + out_items = output.split("\n") | |
|
303 | + sol_items = solution.split("\n") | |
|
304 | 304 | res = '' |
|
305 | 305 | f = 0 |
|
306 | 306 | s = 0 |
|
307 | 307 | sol_items.length.times do |i| |
|
308 | 308 | f += 1 |
|
309 |
- i |
|
|
309 | + si = sol_items[i].chomp | |
|
310 | + if out_items[i] | |
|
311 | + oi = out_items[i].chomp | |
|
312 | + else | |
|
313 | + oi = '' | |
|
314 | + end | |
|
315 | + if oi == si | |
|
310 | 316 | res = res + 'P' |
|
311 | 317 | s += 1 |
|
312 | 318 | else |
|
313 | 319 | res = res + '-' |
|
314 | 320 | end |
|
315 | 321 | end |
|
316 | 322 | return { :score => s, :full_score => f, :msg => res } |
|
317 | 323 | end |
|
318 | 324 | |
|
319 | 325 | def prepare_announcements(recent=nil) |
|
320 | 326 | if GraderConfiguration.show_tasks_to?(@user) |
|
321 | 327 | @announcements = Announcement.find_published(true) |
|
322 | 328 | else |
|
323 | 329 | @announcements = Announcement.find_published |
|
324 | 330 | end |
|
325 | 331 | if recent!=nil |
|
326 | 332 | recent_id = recent.to_i |
|
327 | 333 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
328 | 334 | end |
|
329 | 335 | end |
|
330 | 336 | |
|
331 | 337 | def prepare_timeout_information(problems) |
|
332 | 338 | @submission_timeouts = {} |
|
333 | 339 | problems.each do |problem| |
|
334 | 340 | assignment = @user.get_test_pair_assignment_for(problem) |
|
335 | 341 | if assignment == nil |
|
336 | 342 | timeout = nil |
|
337 | 343 | else |
|
338 | 344 | if (assignment.expired?) or (assignment.submitted) |
|
339 | 345 | timeout = 0 |
|
340 | 346 | else |
|
341 | 347 | timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime |
|
342 | 348 | end |
|
343 | 349 | end |
|
344 | 350 | @submission_timeouts[problem.id] = timeout |
|
345 | 351 | end |
|
346 | 352 | end |
|
347 | 353 | |
|
348 | 354 | def prepare_list_information |
|
349 | 355 | @user = User.find(session[:user_id]) |
|
350 | 356 | if not GraderConfiguration.multicontests? |
|
351 | 357 | @problems = @user.available_problems |
|
352 | 358 | else |
|
353 | 359 | @contest_problems = @user.available_problems_group_by_contests |
|
354 | 360 | @problems = @user.available_problems |
|
355 | 361 | end |
|
356 | 362 | @prob_submissions = {} |
|
357 | 363 | @problems.each do |p| |
You need to be logged in to leave comments.
Login now