Description:
[web] allow check script to inject the comment git-svn-id: http://theory.cpe.ku.ac.th/grader/judge/trunk/scripts@152 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r40:fdbf2dc47aa1 - - 1 file changed: 4 inserted, 2 deleted

@@ -1,86 +1,88
1 #!/usr/bin/ruby
1 #!/usr/bin/ruby
2
2
3 CORRECT_MARK = 'P'
3 CORRECT_MARK = 'P'
4 INCORRECT_MARK = '-'
4 INCORRECT_MARK = '-'
5 TIMEOUT_MARK = 'T'
5 TIMEOUT_MARK = 'T'
6 RUN_ERROR_MARK = 'x'
6 RUN_ERROR_MARK = 'x'
7
7
8 def log(str='')
8 def log(str='')
9 if ENV['TALKATIVE']!=nil
9 if ENV['TALKATIVE']!=nil
10 puts str
10 puts str
11 end
11 end
12 if ENV['GRADER_LOGGING']!=nil
12 if ENV['GRADER_LOGGING']!=nil
13 log_fname = ENV['GRADER_LOGGING']
13 log_fname = ENV['GRADER_LOGGING']
14 fp = File.open(log_fname,"a")
14 fp = File.open(log_fname,"a")
15 fp.puts("grade: #{Time.new.strftime("%H:%M")} #{str}")
15 fp.puts("grade: #{Time.new.strftime("%H:%M")} #{str}")
16 fp.close
16 fp.close
17 end
17 end
18 end
18 end
19
19
20 def char_comment(comment)
20 def char_comment(comment)
21 - if comment =~ /[iI]ncorrect/
21 + if comment =~ /[Ii]ncorrect/
22 INCORRECT_MARK
22 INCORRECT_MARK
23 elsif comment =~ /[Cc]orrect/
23 elsif comment =~ /[Cc]orrect/
24 CORRECT_MARK
24 CORRECT_MARK
25 elsif comment =~ /[Tt]ime/
25 elsif comment =~ /[Tt]ime/
26 TIMEOUT_MARK
26 TIMEOUT_MARK
27 + elsif res = /^[Cc]omment:(.*)$/.match(comment)
28 + res[1]
27 else
29 else
28 RUN_ERROR_MARK # these are run time errors
30 RUN_ERROR_MARK # these are run time errors
29 end
31 end
30 end
32 end
31
33
32 problem_home = ENV['PROBLEM_HOME']
34 problem_home = ENV['PROBLEM_HOME']
33 require "#{problem_home}/script/test_dsl.rb"
35 require "#{problem_home}/script/test_dsl.rb"
34 load "#{problem_home}/test_cases/all_tests.cfg"
36 load "#{problem_home}/test_cases/all_tests.cfg"
35 problem = Problem.get_instance
37 problem = Problem.get_instance
36
38
37 if problem.well_formed? == false
39 if problem.well_formed? == false
38 log "The problem specification is not well formed."
40 log "The problem specification is not well formed."
39 exit(127)
41 exit(127)
40 end
42 end
41
43
42 all_score = 0
44 all_score = 0
43 all_comment = ''
45 all_comment = ''
44 (1..(problem.runs.length-1)).each do |k|
46 (1..(problem.runs.length-1)).each do |k|
45 log "grade run #{k}"
47 log "grade run #{k}"
46 run = problem.runs[k]
48 run = problem.runs[k]
47 run_score = 0
49 run_score = 0
48 run_comment = ''
50 run_comment = ''
49 run_comment_short = ''
51 run_comment_short = ''
50 run.tests.each do |test_num|
52 run.tests.each do |test_num|
51 result_file_name = "#{test_num}/result"
53 result_file_name = "#{test_num}/result"
52 if not File.exists?(result_file_name)
54 if not File.exists?(result_file_name)
53 run_comment += "result file for test #{test_num} not found\n"
55 run_comment += "result file for test #{test_num} not found\n"
54 run_comment_short += RUN_ERROR_MARK
56 run_comment_short += RUN_ERROR_MARK
55 log "Cannot find the file #{test_num}/result!"
57 log "Cannot find the file #{test_num}/result!"
56 else
58 else
57 result_file = File.new(result_file_name, "r")
59 result_file = File.new(result_file_name, "r")
58 result_file_lines = result_file.readlines
60 result_file_lines = result_file.readlines
59 if result_file_lines.length>=2
61 if result_file_lines.length>=2
60 run_score = run_score + result_file_lines[1].to_i
62 run_score = run_score + result_file_lines[1].to_i
61 run_comment += result_file_lines[0]
63 run_comment += result_file_lines[0]
62 - run_comment_short += char_comment(result_file_lines[0])
64 + run_comment_short += char_comment(result_file_lines[0].chomp)
63 else
65 else
64 run_comment += "result file for test #{test_num} error\n"
66 run_comment += "result file for test #{test_num} error\n"
65 run_comment_short += RUN_ERROR_MARK
67 run_comment_short += RUN_ERROR_MARK
66 log "Error in #{test_num}/result!"
68 log "Error in #{test_num}/result!"
67 end
69 end
68 result_file.close
70 result_file.close
69 end
71 end
70 end
72 end
71
73
72 # find total score for this run
74 # find total score for this run
73 run_total_score = 0
75 run_total_score = 0
74 problem = Problem.get_instance
76 problem = Problem.get_instance
75 run.tests.each { |test_num| run_total_score += problem.get_score(test_num) }
77 run.tests.each { |test_num| run_total_score += problem.get_score(test_num) }
76
78
77 if run_total_score!=run_score # fail in some test cases, fail the run
79 if run_total_score!=run_score # fail in some test cases, fail the run
78 run_score = 0
80 run_score = 0
79 end
81 end
80
82
81 run_result_file = File.new("result-#{k}", "w")
83 run_result_file = File.new("result-#{k}", "w")
82 run_result_file.write run_score
84 run_result_file.write run_score
83 run_result_file.write "\n"
85 run_result_file.write "\n"
84 run_result_file.close
86 run_result_file.close
85
87
86 run_comment_file = File.new("comment-#{k}", "w")
88 run_comment_file = File.new("comment-#{k}", "w")
You need to be logged in to leave comments. Login now