Description:
[grader] +grade submission
git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@264 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
r61:3dcc15f24294 - - 3 files changed: 34 inserted, 0 deleted
@@ -170,20 +170,43 | |||||
|
170 | ARGV.shift |
|
170 | ARGV.shift |
|
171 | ARGV.shift |
|
171 | ARGV.shift |
|
172 |
|
172 | ||
|
173 | ARGV.each do |prob_name| |
|
173 | ARGV.each do |prob_name| |
|
174 | prob = Problem.find_by_name(prob_name) |
|
174 | prob = Problem.find_by_name(prob_name) |
|
175 | if prob==nil |
|
175 | if prob==nil |
|
176 | puts "cannot find problem: #{prob_name}" |
|
176 | puts "cannot find problem: #{prob_name}" |
|
177 | else |
|
177 | else |
|
178 | runner.grade_problem(prob) |
|
178 | runner.grade_problem(prob) |
|
179 | end |
|
179 | end |
|
180 | end |
|
180 | end |
|
181 |
|
181 | ||
|
|
182 | + when "sub" | ||
|
|
183 | + engine = Grader::Engine.new | ||
|
|
184 | + runner = Grader::Runner.new(engine, grader_proc) | ||
|
|
185 | + | ||
|
|
186 | + grader_proc.report_active if grader_proc!=nil | ||
|
|
187 | + | ||
|
|
188 | + ARGV.shift | ||
|
|
189 | + ARGV.shift | ||
|
|
190 | + | ||
|
|
191 | + ARGV.each do |sub_id| | ||
|
|
192 | + puts "Grading #{sub_id}" | ||
|
|
193 | + begin | ||
|
|
194 | + submission = Submission.find(sub_id.to_i) | ||
|
|
195 | + rescue ActiveRecord::RecordNotFound | ||
|
|
196 | + puts "Record not found" | ||
|
|
197 | + submission = nil | ||
|
|
198 | + end | ||
|
|
199 | + | ||
|
|
200 | + if submission!=nil | ||
|
|
201 | + runner.grade_submission(submission) | ||
|
|
202 | + end | ||
|
|
203 | + end | ||
|
|
204 | + | ||
|
182 | else |
|
205 | else |
|
183 | display_manual |
|
206 | display_manual |
|
184 | exit(0) |
|
207 | exit(0) |
|
185 | end |
|
208 | end |
|
186 |
|
209 | ||
|
187 | # report inactive |
|
210 | # report inactive |
|
188 | grader_proc.report_inactive if grader_proc!=nil |
|
211 | grader_proc.report_inactive if grader_proc!=nil |
|
189 |
|
212 |
@@ -29,24 +29,29 | |||||
|
29 | users.each do |u| |
|
29 | users.each do |u| |
|
30 | puts "user: #{u.login}" |
|
30 | puts "user: #{u.login}" |
|
31 | last_sub = Submission.find(:first, |
|
31 | last_sub = Submission.find(:first, |
|
32 | :conditions => "user_id = #{u.id} and " + |
|
32 | :conditions => "user_id = #{u.id} and " + |
|
33 | "problem_id = #{problem.id}", |
|
33 | "problem_id = #{problem.id}", |
|
34 | :order => 'submitted_at DESC') |
|
34 | :order => 'submitted_at DESC') |
|
35 | if last_sub!=nil |
|
35 | if last_sub!=nil |
|
36 | @engine.grade(last_sub) |
|
36 | @engine.grade(last_sub) |
|
37 | end |
|
37 | end |
|
38 | end |
|
38 | end |
|
39 | end |
|
39 | end |
|
40 |
|
40 | ||
|
|
41 | + def grade_submission(submission) | ||
|
|
42 | + puts "Submission: #{submission.id} by #{submission.user.full_name}" | ||
|
|
43 | + @engine.grade(submission) | ||
|
|
44 | + end | ||
|
|
45 | + | ||
|
41 | def grade_oldest_test_request |
|
46 | def grade_oldest_test_request |
|
42 | test_request = TestRequest.get_inqueue_and_change_status(Task::STATUS_GRADING) |
|
47 | test_request = TestRequest.get_inqueue_and_change_status(Task::STATUS_GRADING) |
|
43 | if test_request!=nil |
|
48 | if test_request!=nil |
|
44 | @grader_process.report_active(test_request) if @grader_process!=nil |
|
49 | @grader_process.report_active(test_request) if @grader_process!=nil |
|
45 |
|
50 | ||
|
46 | @engine.grade(test_request) |
|
51 | @engine.grade(test_request) |
|
47 | test_request.status_complete! |
|
52 | test_request.status_complete! |
|
48 | @grader_process.report_inactive(test_request) if @grader_process!=nil |
|
53 | @grader_process.report_inactive(test_request) if @grader_process!=nil |
|
49 | end |
|
54 | end |
|
50 | return test_request |
|
55 | return test_request |
|
51 | end |
|
56 | end |
|
52 |
|
57 |
@@ -94,38 +94,44 | |||||
|
94 |
|
94 | ||
|
95 | require "#{problem_home}/script/test_dsl.rb" |
|
95 | require "#{problem_home}/script/test_dsl.rb" |
|
96 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
96 | load "#{problem_home}/test_cases/all_tests.cfg" |
|
97 | problem = Problem.get_instance |
|
97 | problem = Problem.get_instance |
|
98 |
|
98 | ||
|
99 | if problem.well_formed? == false |
|
99 | if problem.well_formed? == false |
|
100 | log "The problem specification is not well formed." |
|
100 | log "The problem specification is not well formed." |
|
101 | exit(127) |
|
101 | exit(127) |
|
102 | end |
|
102 | end |
|
103 |
|
103 | ||
|
104 | # Doing the testing. |
|
104 | # Doing the testing. |
|
105 | (1..(problem.num_tests)).each do |test_num| |
|
105 | (1..(problem.num_tests)).each do |test_num| |
|
|
106 | + | ||
|
|
107 | + $stdout.print "[#{test_num}]" | ||
|
|
108 | + $stdout.flush | ||
|
|
109 | + | ||
|
106 | log "Test number: #{test_num}" |
|
110 | log "Test number: #{test_num}" |
|
107 | execute("cp #{test_result_dir}/a.out #{sandbox_dir}", "Cannot copy the compiled program into #{sandbox_dir}") |
|
111 | execute("cp #{test_result_dir}/a.out #{sandbox_dir}", "Cannot copy the compiled program into #{sandbox_dir}") |
|
108 | begin |
|
112 | begin |
|
109 | execute("#{problem_home}/script/run #{language} #{test_num}", "Error occured during execution of the run script") |
|
113 | execute("#{problem_home}/script/run #{language} #{test_num}", "Error occured during execution of the run script") |
|
110 | rescue |
|
114 | rescue |
|
111 | # do nothing |
|
115 | # do nothing |
|
112 | end |
|
116 | end |
|
113 | execute("mkdir #{test_result_dir}/#{test_num}", "Cannot create directory #{test_result_dir}/#{test_num}") |
|
117 | execute("mkdir #{test_result_dir}/#{test_num}", "Cannot create directory #{test_result_dir}/#{test_num}") |
|
114 | execute("mv #{sandbox_dir}/result #{test_result_dir}/#{test_num}", "Cannot copy the result file into #{test_result_dir}/#{test_num}") |
|
118 | execute("mv #{sandbox_dir}/result #{test_result_dir}/#{test_num}", "Cannot copy the result file into #{test_result_dir}/#{test_num}") |
|
115 | execute("mv #{sandbox_dir}/comment #{test_result_dir}/#{test_num}", "Cannot copy the comment file into #{test_result_dir}/#{test_num}") |
|
119 | execute("mv #{sandbox_dir}/comment #{test_result_dir}/#{test_num}", "Cannot copy the comment file into #{test_result_dir}/#{test_num}") |
|
116 | execute("mv #{sandbox_dir}/output.txt #{test_result_dir}/#{test_num}", "Cannot copy the output file into #{test_result_dir}/#{test_num}") |
|
120 | execute("mv #{sandbox_dir}/output.txt #{test_result_dir}/#{test_num}", "Cannot copy the output file into #{test_result_dir}/#{test_num}") |
|
117 | execute("rm -Rf #{sandbox_dir}/*", "Cannot clear #{sandbox_dir}") |
|
121 | execute("rm -Rf #{sandbox_dir}/*", "Cannot clear #{sandbox_dir}") |
|
118 | end |
|
122 | end |
|
119 |
|
123 | ||
|
|
124 | + $stdout.print "[done]\n" | ||
|
|
125 | + | ||
|
120 | # Grade |
|
126 | # Grade |
|
121 | log |
|
127 | log |
|
122 | log "Grading..." |
|
128 | log "Grading..." |
|
123 | begin |
|
129 | begin |
|
124 | Dir.chdir test_result_dir |
|
130 | Dir.chdir test_result_dir |
|
125 | rescue |
|
131 | rescue |
|
126 | log "ERROR: Cannot change directory to #{test_result_dir}." |
|
132 | log "ERROR: Cannot change directory to #{test_result_dir}." |
|
127 | exit(127) |
|
133 | exit(127) |
|
128 | end |
|
134 | end |
|
129 | execute("#{problem_home}/script/grade", "An error occured during grading!") |
|
135 | execute("#{problem_home}/script/grade", "An error occured during grading!") |
|
130 |
|
136 | ||
|
131 | log |
|
137 | log |
You need to be logged in to leave comments.
Login now