Description:
git-svn-id: http://theory.cpe.ku.ac.th/grader/cli/trunk/scripts@20 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
r7:d40f897fb488 - - 3 files changed: 33 inserted, 8 deleted
@@ -21,6 +21,8 | |||
|
21 | 21 | |
|
22 | 22 | def call_judge(problem_home,language,problem_out_dir,fname) |
|
23 | 23 | ENV['PROBLEM_HOME'] = problem_home |
|
24 | + | |
|
25 | + puts problem_out_dir | |
|
24 | 26 | Dir.chdir problem_out_dir |
|
25 | 27 | cmd = "#{problem_home}/script/judge #{language} #{fname}" |
|
26 | 28 | # puts "CMD: #{cmd}" |
@@ -29,13 +31,21 | |||
|
29 | 31 | |
|
30 | 32 | def read_result(test_result_dir) |
|
31 | 33 | cmp_msg_fname = "#{test_result_dir}/compiler_message" |
|
32 |
- cmp_ |
|
|
34 | + cmp_file = File.open(cmp_msg_fname) | |
|
35 | + cmp_msg = cmp_file.read | |
|
36 | + cmp_file.close | |
|
33 | 37 | |
|
34 | 38 | result_fname = "#{test_result_dir}/result" |
|
35 | 39 | comment_fname = "#{test_result_dir}/comment" |
|
36 | 40 | if FileTest.exist?(result_fname) |
|
37 |
- result = File.open(result_fname) |
|
|
38 | - comment = File.open(comment_fname).readline.chomp | |
|
41 | + result_file = File.open(result_fname) | |
|
42 | + result = result_file.readline.to_i | |
|
43 | + result_file.close | |
|
44 | + | |
|
45 | + comment_file = File.open(comment_fname) | |
|
46 | + comment = comment_file.readline.chomp | |
|
47 | + comment_file.close | |
|
48 | + | |
|
39 | 49 | return {:points => result, |
|
40 | 50 | :comment => comment, |
|
41 | 51 | :cmp_msg => cmp_msg} |
@@ -47,14 +57,21 | |||
|
47 | 57 | end |
|
48 | 58 | |
|
49 | 59 | def save_result(submission,result) |
|
60 | + problem = Problem.find(submission.problem_id) | |
|
50 | 61 | submission.graded_at = Time.now |
|
51 | 62 | submission.points = result[:points] |
|
52 | - submission.grader_comment = report_comment(result[:comment]) | |
|
63 | + if submission.points == problem.full_score | |
|
64 | + submission.grader_comment = 'PASSED: ' + report_comment(result[:comment]) | |
|
65 | + else | |
|
66 | + submission.grader_comment = 'FAILED: ' + report_comment(result[:comment]) | |
|
67 | + end | |
|
53 | 68 | submission.compiler_message = result[:cmp_msg] |
|
54 | 69 | submission.save |
|
55 | 70 | end |
|
56 | 71 | |
|
57 | 72 | def grade(submission_id) |
|
73 | + current_dir = `pwd`.chomp | |
|
74 | + | |
|
58 | 75 | sub = Submission.find(submission_id) |
|
59 | 76 | user = sub.user |
|
60 | 77 | problem = sub.problem |
@@ -79,10 +96,12 | |||
|
79 | 96 | save_source(sub,problem_out_dir,source_name) |
|
80 | 97 | call_judge(problem_home,language,problem_out_dir,source_name) |
|
81 | 98 | save_result(sub,read_result("#{problem_out_dir}/test-result")) |
|
99 | + | |
|
100 | + Dir.chdir(current_dir) | |
|
82 | 101 | end |
|
83 | 102 | |
|
84 | 103 | def stop_grader |
|
85 | - File.open(File.dirname(__FILE__) + '/stop','w') | |
|
104 | + File.open(File.dirname(__FILE__) + '/stop','w').close | |
|
86 | 105 | end |
|
87 | 106 | |
|
88 | 107 | def check_stopfile |
@@ -121,8 +140,6 | |||
|
121 | 140 | RAILS_ENV = 'development' |
|
122 | 141 | require RAILS_APP_DIR + '/config/environment' |
|
123 | 142 | |
|
124 | - current_dir = `pwd` | |
|
125 | - | |
|
126 | 143 | talk 'Grader queue' |
|
127 | 144 | while true |
|
128 | 145 | if check_stopfile # created by calling grader stop |
@@ -38,7 +38,11 | |||
|
38 | 38 | result_file = File.new(result_file_name, "r") |
|
39 | 39 | result_file_lines = result_file.readlines |
|
40 | 40 | run_score = run_score + result_file_lines[1].to_i |
|
41 | - run_comment += char_comment(result_file_lines[0]) | |
|
41 | + # run_comment += char_comment(result_file_lines[0]) | |
|
42 | + result_file_lines.each do |l| | |
|
43 | + run_comment += l | |
|
44 | + end | |
|
45 | + run_comment += "----\n" | |
|
42 | 46 | result_file.close |
|
43 | 47 | end |
|
44 | 48 |
You need to be logged in to leave comments.
Login now