Description:
add warning for check git-svn-id: http://theory.cpe.ku.ac.th/grader/cli/trunk/scripts@22 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

r9:8595e5379ca6 - - 2 files changed: 44 inserted, 12 deleted

@@ -104,57 +104,85
104 File.open(File.dirname(__FILE__) + '/stop','w').close
104 File.open(File.dirname(__FILE__) + '/stop','w').close
105 end
105 end
106
106
107 def check_stopfile
107 def check_stopfile
108 FileTest.exist?(File.dirname(__FILE__) + '/stop')
108 FileTest.exist?(File.dirname(__FILE__) + '/stop')
109 end
109 end
110
110
111 def clear_stopfile
111 def clear_stopfile
112 system("rm " + File.dirname(__FILE__) + '/stop')
112 system("rm " + File.dirname(__FILE__) + '/stop')
113 end
113 end
114
114
115 # reading environment and options
115 # reading environment and options
116 if (ARGV.length >= 1) and (ARGV[0]=='stop')
116 if (ARGV.length >= 1) and (ARGV[0]=='stop')
117 stop_grader
117 stop_grader
118 puts "stop file created"
118 puts "stop file created"
119 exit(0)
119 exit(0)
120 end
120 end
121
121
122 if check_stopfile
122 if check_stopfile
123 puts "stop file exists"
123 puts "stop file exists"
124 clear_stopfile
124 clear_stopfile
125 exit(0)
125 exit(0)
126 end
126 end
127
127
128 + grader_mode = 'queue'
128 if ARGV.length >= 1
129 if ARGV.length >= 1
129 GRADER_ENV = ARGV[0]
130 GRADER_ENV = ARGV[0]
131 + if ARGV.length >=2
132 + grader_mode = ARGV[1]
133 + end
130 else
134 else
131 GRADER_ENV = 'exam'
135 GRADER_ENV = 'exam'
132 end
136 end
133
137
134 puts "environment: #{GRADER_ENV}"
138 puts "environment: #{GRADER_ENV}"
135 require File.dirname(__FILE__) + "/environment.rb"
139 require File.dirname(__FILE__) + "/environment.rb"
136
140
137 #main program
141 #main program
138 talk 'Reading rails environment'
142 talk 'Reading rails environment'
139
143
140 RAILS_ENV = 'development'
144 RAILS_ENV = 'development'
141 require RAILS_APP_DIR + '/config/environment'
145 require RAILS_APP_DIR + '/config/environment'
142
146
143 - talk 'Grader queue'
147 + case grader_mode
144 - while true
148 + when "queue"
145 - if check_stopfile # created by calling grader stop
149 + talk 'Grader queue'
146 - clear_stopfile
150 + while true
147 - puts "stopped"
151 + if check_stopfile # created by calling grader stop
152 + clear_stopfile
153 + puts "stopped"
154 + exit(0)
155 + end
156 +
157 + task = Task.find(:first, :order => 'created_at')
158 + if task!=nil
159 + grade(task.submission_id)
160 + task.destroy
161 + else
162 + sleep(1)
163 + end
164 + end
165 +
166 + when "prob"
167 + prob = Problem.find_by_name(ARGV[2])
168 + if prob==nil
169 + puts "cannot find problem: #{ARGV[2]}"
148 exit(0)
170 exit(0)
149 end
171 end
150 -
172 + users = User.find(:all)
151 - task = Task.find(:first, :order => 'created_at')
173 + users.each do |u|
152 - if task!=nil
174 + puts "user: #{u.login}"
153 - grade(task.submission_id)
175 + last_sub = Submission.find(:first,
154 - task.destroy
176 + :conditions => "user_id = #{u.id} and " +
155 - else
177 + "problem_id = #{prob.id}",
156 - sleep(1)
178 + :order => 'submitted_at DESC')
179 + if last_sub!=nil
180 + grade(last_sub.id)
181 + end
157 end
182 end
158 end
183 end
159
184
160
185
186 +
187 +
188 +
@@ -23,37 +23,41
23 answer_file = File.new("#{problem_home}/test_cases/#{test_num}/answer-#{test_num}.txt")
23 answer_file = File.new("#{problem_home}/test_cases/#{test_num}/answer-#{test_num}.txt")
24 result_file = File.new("check_result", "w")
24 result_file = File.new("check_result", "w")
25
25
26 output_file_content = output_file.read
26 output_file_content = output_file.read
27 answer_file_content = answer_file.read
27 answer_file_content = answer_file.read
28
28
29 report_correct = lambda {
29 report_correct = lambda {
30 result_file.write "Correct\n"
30 result_file.write "Correct\n"
31 result_file.write problem.get_score(test_num)
31 result_file.write problem.get_score(test_num)
32 result_file.write "\n"
32 result_file.write "\n"
33 result_file.close
33 result_file.close
34 exit(0)
34 exit(0)
35 }
35 }
36
36
37 report_wrong = lambda {
37 report_wrong = lambda {
38 result_file.write "Incorrect\n"
38 result_file.write "Incorrect\n"
39 result_file.write "0\n"
39 result_file.write "0\n"
40 result_file.close
40 result_file.close
41 exit(0)
41 exit(0)
42 }
42 }
43
43
44 ##################
44 ##################
45 # Your code here #
45 # Your code here #
46 ##################
46 ##################
47 +
48 + puts "YOU HAVE TO EDIT THE CHECKING CODE HERE: #{__FILE__}"
49 + exit(127)
50 +
47 num_pattern = /^[0-9]*/
51 num_pattern = /^[0-9]*/
48 if (output_file_content =~ num_pattern) == nil
52 if (output_file_content =~ num_pattern) == nil
49 report_wrong.call
53 report_wrong.call
50 end
54 end
51
55
52 output_i = output_file_content.to_i
56 output_i = output_file_content.to_i
53 answer_i = answer_file_content.to_i
57 answer_i = answer_file_content.to_i
54
58
55 if output_i == answer_i
59 if output_i == answer_i
56 report_correct.call
60 report_correct.call
57 else
61 else
58 report_wrong.call
62 report_wrong.call
59 end
63 end
You need to be logged in to leave comments. Login now