Description:
sends whole submission to result collecter in submission reporter, instead of just user and problem
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r123:57e6d251108e - - 2 files changed: 6 inserted, 5 deleted
@@ -84,109 +84,111 | |||
|
84 | 84 | end |
|
85 | 85 | exit(0) |
|
86 | 86 | end |
|
87 | 87 | |
|
88 | 88 | # Check stop file. |
|
89 | 89 | if check_stopfile |
|
90 | 90 | puts "Stop file exists. Terminated." |
|
91 | 91 | clear_stopfile |
|
92 | 92 | exit(0) |
|
93 | 93 | end |
|
94 | 94 | |
|
95 | 95 | #default options |
|
96 | 96 | options = { |
|
97 | 97 | :mode => 'queue', |
|
98 | 98 | :environment => 'exam', |
|
99 | 99 | :dry_run => false, |
|
100 | 100 | } |
|
101 | 101 | |
|
102 | 102 | # Process mode and environment option |
|
103 | 103 | if ARGV.length >= 1 |
|
104 | 104 | options[:environment] = ARGV.shift |
|
105 | 105 | if ARGV.length >=1 |
|
106 | 106 | options[:mode] = ARGV.shift |
|
107 | 107 | end |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | options[:dry_run] = (ARGV.delete('--dry') != nil) |
|
111 | 111 | if options[:dry_run] and (not ['prob','contest','autonew'].include? options[:mode]) |
|
112 | 112 | puts "Dry run currently works only for 'prob' or 'contest' modes." |
|
113 | 113 | exit(0) |
|
114 | 114 | end |
|
115 | 115 | |
|
116 | 116 | options[:report] = (ARGV.delete('--report') != nil) |
|
117 | 117 | if options[:report] and (not ['prob','contest','autonew'].include? options[:mode]) |
|
118 | 118 | puts "Report currently works only for 'prob' or 'contest' modes." |
|
119 | 119 | exit(0) |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | return options |
|
123 | 123 | end |
|
124 | 124 | |
|
125 | 125 | class ResultCollector |
|
126 | 126 | def initialize |
|
127 | 127 | @results = {} |
|
128 | 128 | @problems = {} |
|
129 | 129 | @users = {} |
|
130 | 130 | end |
|
131 | 131 | |
|
132 |
- def after_save_hook( |
|
|
132 | + def after_save_hook(submission, grading_result) | |
|
133 | 133 | end |
|
134 | 134 | |
|
135 |
- def save( |
|
|
135 | + def save(submission, grading_result) | |
|
136 | + user = submission.user | |
|
137 | + problem = submission.problem | |
|
136 | 138 | if not @problems.has_key? problem.id |
|
137 | 139 | @problems[problem.id] = problem |
|
138 | 140 | end |
|
139 | 141 | if not @users.has_key? user.id |
|
140 | 142 | @users[user.id] = user |
|
141 | 143 | end |
|
142 | 144 | @results[[user.id, problem.id]] = grading_result |
|
143 | 145 | |
|
144 |
- after_save_hook( |
|
|
146 | + after_save_hook(submission, grading_result) | |
|
145 | 147 | end |
|
146 | 148 | |
|
147 | 149 | def print_report_by_user |
|
148 | 150 | puts "---------------------" |
|
149 | 151 | puts " REPORT" |
|
150 | 152 | puts "---------------------" |
|
151 | 153 | |
|
152 | 154 | print "login,email" |
|
153 | 155 | @problems.each_value do |problem| |
|
154 | 156 | print ",#{problem.name}" |
|
155 | 157 | end |
|
156 | 158 | print "\n" |
|
157 | 159 | |
|
158 | 160 | @users.each_value do |user| |
|
159 | 161 | print "#{user.login},#{user.email}" |
|
160 | 162 | @problems.each_value do |problem| |
|
161 | 163 | if @results.has_key? [user.id, problem.id] |
|
162 | 164 | print ",#{@results[[user.id,problem.id]][:points]}" |
|
163 | 165 | else |
|
164 | 166 | print "," |
|
165 | 167 | end |
|
166 | 168 | end |
|
167 | 169 | print "\n" |
|
168 | 170 | end |
|
169 | 171 | end |
|
170 | 172 | end |
|
171 | 173 | |
|
172 | 174 | def grader_general_loop(engine, grader_proc, options) |
|
173 | 175 | runner = Grader::Runner.new(engine, grader_proc) |
|
174 | 176 | while true |
|
175 | 177 | |
|
176 | 178 | if check_stopfile # created by calling grader stop |
|
177 | 179 | clear_stopfile |
|
178 | 180 | log "stopped (with stop file)" |
|
179 | 181 | break |
|
180 | 182 | end |
|
181 | 183 | |
|
182 | 184 | task = yield(runner) |
|
183 | 185 | |
|
184 | 186 | if task==nil |
|
185 | 187 | sleep(1) |
|
186 | 188 | end |
|
187 | 189 | end |
|
188 | 190 | end |
|
189 | 191 | |
|
190 | 192 | def grader_queue_loop(grader_proc, options) |
|
191 | 193 | log "Grader: queue" |
|
192 | 194 | engine = Grader::Engine.new |
@@ -1,94 +1,93 | |||
|
1 | 1 | module Grader |
|
2 | 2 | |
|
3 | 3 | class SubmissionRoomMaker |
|
4 | 4 | def initialize |
|
5 | 5 | @config = Grader::Configuration.get_instance |
|
6 | 6 | end |
|
7 | 7 | |
|
8 | 8 | def produce_grading_room(submission) |
|
9 | 9 | user = submission.user |
|
10 | 10 | problem = submission.problem |
|
11 | 11 | grading_room = "#{@config.user_result_dir}/" + |
|
12 | 12 | "#{user.login}/#{problem.name}/#{submission.id}" |
|
13 | 13 | |
|
14 | 14 | FileUtils.mkdir_p(grading_room) |
|
15 | 15 | grading_room |
|
16 | 16 | end |
|
17 | 17 | |
|
18 | 18 | def find_problem_home(submission) |
|
19 | 19 | problem = submission.problem |
|
20 | 20 | "#{@config.problems_dir}/#{problem.name}" |
|
21 | 21 | end |
|
22 | 22 | |
|
23 | 23 | def save_source(submission,source_name) |
|
24 | 24 | dir = self.produce_grading_room(submission) |
|
25 | 25 | f = File.open("#{dir}/#{source_name}","w") |
|
26 | 26 | f.write(submission.source) |
|
27 | 27 | f.close |
|
28 | 28 | end |
|
29 | 29 | |
|
30 | 30 | def clean_up(submission) |
|
31 | 31 | end |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | class SubmissionReporter |
|
35 | 35 | def initialize(options={}) |
|
36 | 36 | options = {:dry_run => false, :result_collector => nil}.merge(options) |
|
37 | 37 | @config = Grader::Configuration.get_instance |
|
38 | 38 | @dry_run = options[:dry_run] |
|
39 | 39 | @result_collector = options[:result_collector] |
|
40 | 40 | end |
|
41 | 41 | |
|
42 | 42 | def report(sub,test_result_dir) |
|
43 | 43 | result = read_result(test_result_dir) |
|
44 | 44 | if @result_collector |
|
45 |
- @result_collector.save(sub |
|
|
46 | - sub.problem, | |
|
45 | + @result_collector.save(sub, | |
|
47 | 46 | result) |
|
48 | 47 | end |
|
49 | 48 | save_result(sub,result) |
|
50 | 49 | end |
|
51 | 50 | |
|
52 | 51 | def report_error(sub,msg) |
|
53 | 52 | save_result(sub,{:points => 0, |
|
54 | 53 | :comment => "Grading error: #{msg}" }) |
|
55 | 54 | end |
|
56 | 55 | |
|
57 | 56 | protected |
|
58 | 57 | def read_result(test_result_dir) |
|
59 | 58 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
60 | 59 | if FileTest.exist?(cmp_msg_fname) |
|
61 | 60 | cmp_file = File.open(cmp_msg_fname) |
|
62 | 61 | cmp_msg = cmp_file.read |
|
63 | 62 | cmp_file.close |
|
64 | 63 | else |
|
65 | 64 | cmp_msg = "" |
|
66 | 65 | end |
|
67 | 66 | |
|
68 | 67 | result_fname = "#{test_result_dir}/result" |
|
69 | 68 | comment_fname = "#{test_result_dir}/comment" |
|
70 | 69 | if FileTest.exist?(result_fname) |
|
71 | 70 | comment = "" |
|
72 | 71 | begin |
|
73 | 72 | result_file = File.open(result_fname) |
|
74 | 73 | result = result_file.readline.to_i |
|
75 | 74 | result_file.close |
|
76 | 75 | rescue |
|
77 | 76 | result = 0 |
|
78 | 77 | comment = "error reading result file." |
|
79 | 78 | end |
|
80 | 79 | |
|
81 | 80 | begin |
|
82 | 81 | comment_file = File.open(comment_fname) |
|
83 | 82 | comment += comment_file.readline.chomp |
|
84 | 83 | comment_file.close |
|
85 | 84 | rescue |
|
86 | 85 | comment += "" |
|
87 | 86 | end |
|
88 | 87 | |
|
89 | 88 | return {:points => result, |
|
90 | 89 | :comment => comment, |
|
91 | 90 | :cmp_msg => cmp_msg} |
|
92 | 91 | else |
|
93 | 92 | if FileTest.exist?("#{test_result_dir}/a.out") |
|
94 | 93 | return {:points => 0, |
You need to be logged in to leave comments.
Login now