Description:
[grader] hack on language for output-only task
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@190 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r50:6e02aa1a5841 - - 1 file changed: 10 inserted, 3 deleted
@@ -1,85 +1,92 | |||
|
1 | 1 | require 'fileutils' |
|
2 | 2 | |
|
3 | 3 | module Grader |
|
4 | 4 | |
|
5 | 5 | # |
|
6 | 6 | # A grader engine grades a submission, against anything: a test |
|
7 | 7 | # data, or a user submitted test data. It uses two helpers objects: |
|
8 | 8 | # room_maker and reporter. |
|
9 | 9 | # |
|
10 | 10 | class Engine |
|
11 | 11 | |
|
12 | 12 | attr_writer :room_maker |
|
13 | 13 | attr_writer :reporter |
|
14 | 14 | |
|
15 | 15 | def initialize(room_maker=nil, reporter=nil) |
|
16 | 16 | @config = Grader::Configuration.get_instance |
|
17 | 17 | |
|
18 | 18 | @room_maker = room_maker || Grader::SubmissionRoomMaker.new |
|
19 | 19 | @reporter = reporter || Grader::SubmissionReporter.new |
|
20 | 20 | end |
|
21 | 21 | |
|
22 | 22 | # takes a submission, asks room_maker to produce grading directories, |
|
23 | 23 | # calls grader scripts, and asks reporter to save the result |
|
24 | 24 | def grade(submission) |
|
25 | 25 | current_dir = `pwd`.chomp |
|
26 | 26 | |
|
27 | 27 | user = submission.user |
|
28 | 28 | problem = submission.problem |
|
29 | 29 | |
|
30 | 30 | # TODO: will have to create real exception for this |
|
31 | 31 | if user==nil or problem == nil |
|
32 | 32 | @reporter.report_error(submission,"Grading error: problem with submission") |
|
33 | 33 | #raise "engine: user or problem is nil" |
|
34 | 34 | end |
|
35 | - | |
|
36 | - language = submission.language.name | |
|
37 |
- |
|
|
35 | + | |
|
36 | + # TODO: this is another hack so that output only task can be judged | |
|
37 | + if submission.language!=nil | |
|
38 | + language = submission.language.name | |
|
39 | + lang_ext = submission.language.ext | |
|
40 | + else | |
|
41 | + language = 'c' | |
|
42 | + lang_ext = 'c' | |
|
43 | + end | |
|
44 | + | |
|
38 | 45 | # FIX THIS |
|
39 | 46 | talk 'some hack on language' |
|
40 | 47 | if language == 'cpp' |
|
41 | 48 | language = 'c++' |
|
42 | 49 | end |
|
43 | 50 | |
|
44 | 51 | # COMMENT: should it be only source.ext? |
|
45 | 52 | if problem!=nil |
|
46 | 53 | source_name = "#{problem.name}.#{lang_ext}" |
|
47 | 54 | else |
|
48 | 55 | source_name = "source.#{lang_ext}" |
|
49 | 56 | end |
|
50 | 57 | |
|
51 | 58 | begin |
|
52 | 59 | grading_dir = @room_maker.produce_grading_room(submission) |
|
53 | 60 | @room_maker.save_source(submission,source_name) |
|
54 | 61 | problem_home = @room_maker.find_problem_home(submission) |
|
55 | 62 | |
|
56 | 63 | # puts "GRADING DIR: #{grading_dir}" |
|
57 | 64 | # puts "PROBLEM DIR: #{problem_home}" |
|
58 | 65 | |
|
59 | 66 | copy_log = copy_script(problem_home) |
|
60 | 67 | |
|
61 | 68 | call_judge(problem_home,language,grading_dir,source_name) |
|
62 | 69 | |
|
63 | 70 | @reporter.report(submission,"#{grading_dir}/test-result") |
|
64 | 71 | |
|
65 | 72 | clear_script(copy_log,problem_home) |
|
66 | 73 | |
|
67 | 74 | rescue RuntimeError => msg |
|
68 | 75 | @reporter.report_error(submission,"Grading error: #{msg}") |
|
69 | 76 | |
|
70 | 77 | ensure |
|
71 | 78 | @room_maker.clean_up(submission) |
|
72 | 79 | Dir.chdir(current_dir) # this is really important |
|
73 | 80 | end |
|
74 | 81 | end |
|
75 | 82 | |
|
76 | 83 | protected |
|
77 | 84 | |
|
78 | 85 | def talk(str) |
|
79 | 86 | if @config.talkative |
|
80 | 87 | puts str |
|
81 | 88 | end |
|
82 | 89 | end |
|
83 | 90 | |
|
84 | 91 | def call_judge(problem_home,language,grading_dir,fname) |
|
85 | 92 | ENV['PROBLEM_HOME'] = problem_home |
You need to be logged in to leave comments.
Login now