Description:
MERGED changeset 404:406 from ytopc branch git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@425 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

r197:7e5cbcab36dd - - 3 files changed: 20 inserted, 4 deleted

new file 100644
binary diff hidden
@@ -121,193 +121,202
121 121
122 122 def result
123 123 if !Configuration.show_grading_result
124 124 redirect_to :action => 'list' and return
125 125 end
126 126 @user = User.find(session[:user_id])
127 127 @submission = Submission.find(params[:id])
128 128 if @submission.user!=@user
129 129 flash[:notice] = 'You are not allowed to view result of other users.'
130 130 redirect_to :action => 'list' and return
131 131 end
132 132 prepare_grading_result(@submission)
133 133 end
134 134
135 135 def load_output
136 136 if !Configuration.show_grading_result or params[:num]==nil
137 137 redirect_to :action => 'list' and return
138 138 end
139 139 @user = User.find(session[:user_id])
140 140 @submission = Submission.find(params[:id])
141 141 if @submission.user!=@user
142 142 flash[:notice] = 'You are not allowed to view result of other users.'
143 143 redirect_to :action => 'list' and return
144 144 end
145 145 case_num = params[:num].to_i
146 146 out_filename = output_filename(@user.login,
147 147 @submission.problem.name,
148 148 @submission.id,
149 149 case_num)
150 150 if !FileTest.exists?(out_filename)
151 151 flash[:notice] = 'Output not found.'
152 152 redirect_to :action => 'list' and return
153 153 end
154 154
155 155 response.headers['Content-Type'] = "application/force-download"
156 156 response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\""
157 157 response.headers["X-Sendfile"] = out_filename
158 158 response.headers['Content-length'] = File.size(out_filename)
159 159 render :nothing => true
160 160 end
161 161
162 162 def error
163 163 @user = User.find(session[:user_id])
164 164 end
165 165
166 166 # announcement refreshing and hiding methods
167 167
168 168 def announcements
169 169 if params.has_key? 'recent'
170 170 prepare_announcements(params[:recent])
171 171 else
172 172 prepare_announcements
173 173 end
174 174 render(:partial => 'announcement',
175 175 :collection => @announcements,
176 176 :locals => {:announcement_effect => true})
177 177 end
178 178
179 179 protected
180 180
181 181 def prepare_announcements(recent=nil)
182 182 if Configuration.show_tasks_to?(@user)
183 183 @announcements = Announcement.find_published(true)
184 184 else
185 185 @announcements = Announcement.find_published
186 186 end
187 187 if recent!=nil
188 188 recent_id = recent.to_i
189 189 @announcements = @announcements.find_all { |a| a.id > recent_id }
190 190 end
191 191 end
192 192
193 193 def prepare_list_information
194 194 @problems = Problem.find_available_problems
195 195 @prob_submissions = Array.new
196 196 @user = User.find(session[:user_id])
197 197 @problems.each do |p|
198 198 sub = Submission.find_last_by_user_and_problem(@user.id,p.id)
199 199 if sub!=nil
200 200 @prob_submissions << { :count => sub.number, :submission => sub }
201 201 else
202 202 @prob_submissions << { :count => 0, :submission => nil }
203 203 end
204 204 end
205 205 prepare_announcements
206 206 end
207 207
208 208 def check_viewability
209 209 @user = User.find(session[:user_id])
210 210 if (!Configuration.show_tasks_to?(@user)) and
211 211 ((action_name=='submission') or (action_name=='submit'))
212 212 redirect_to :action => 'list' and return
213 213 end
214 214 end
215 215
216 216 def prepare_grading_result(submission)
217 - grading_info = Configuration.task_grading_info[submission.problem.name]
217 + if Configuration.task_grading_info.has_key? submission.problem.name
218 + grading_info = Configuration.task_grading_info[submission.problem.name]
219 + else
220 + # guess task info from problem.full_score
221 + cases = submission.problem.full_score / 10
222 + grading_info = {
223 + 'testruns' => cases,
224 + 'testcases' => cases
225 + }
226 + end
218 227 @test_runs = []
219 228 if grading_info['testruns'].is_a? Integer
220 229 trun_count = grading_info['testruns']
221 230 trun_count.times do |i|
222 231 @test_runs << [ read_grading_result(@user.login,
223 232 submission.problem.name,
224 233 submission.id,
225 234 i+1) ]
226 235 end
227 236 else
228 237 grading_info['testruns'].keys.sort.each do |num|
229 238 run = []
230 239 testrun = grading_info['testruns'][num]
231 240 testrun.each do |c|
232 241 run << read_grading_result(@user.login,
233 242 submission.problem.name,
234 243 submission.id,
235 244 c)
236 245 end
237 246 @test_runs << run
238 247 end
239 248 end
240 249 end
241 250
242 251 def grading_result_dir(user_name, problem_name, submission_id, case_num)
243 252 return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}"
244 253 end
245 254
246 255 def output_filename(user_name, problem_name, submission_id, case_num)
247 256 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
248 257 return "#{dir}/output.txt"
249 258 end
250 259
251 260 def read_grading_result(user_name, problem_name, submission_id, case_num)
252 261 dir = grading_result_dir(user_name,problem_name, submission_id, case_num)
253 262 result_file_name = "#{dir}/result"
254 263 if !FileTest.exists?(result_file_name)
255 264 return {:num => case_num, :msg => 'program did not run'}
256 265 else
257 266 results = File.open(result_file_name).readlines
258 267 run_stat = extract_running_stat(results)
259 268 output_filename = "#{dir}/output.txt"
260 269 if FileTest.exists?(output_filename)
261 270 output_file = true
262 271 output_size = File.size(output_filename)
263 272 else
264 273 output_file = false
265 274 output_size = 0
266 275 end
267 276
268 277 return {
269 278 :num => case_num,
270 279 :msg => results[0],
271 280 :run_stat => run_stat,
272 281 :output => output_file,
273 282 :output_size => output_size
274 283 }
275 284 end
276 285 end
277 286
278 287 # copied from grader/script/lib/test_request_helper.rb
279 288 def extract_running_stat(results)
280 289 running_stat_line = results[-1]
281 290
282 291 # extract exit status line
283 292 run_stat = ""
284 293 if !(/[Cc]orrect/.match(results[0]))
285 294 run_stat = results[0].chomp
286 295 else
287 296 run_stat = 'Program exited normally'
288 297 end
289 298
290 299 logger.info "Stat line: #{running_stat_line}"
291 300
292 301 # extract running time
293 302 if res = /r(.*)u(.*)s/.match(running_stat_line)
294 303 seconds = (res[1].to_f + res[2].to_f)
295 304 time_stat = "Time used: #{seconds} sec."
296 305 else
297 306 seconds = nil
298 307 time_stat = "Time used: n/a sec."
299 308 end
300 309
301 310 # extract memory usage
302 311 if res = /s(.*)m/.match(running_stat_line)
303 312 memory_used = res[1].to_i
304 313 else
305 314 memory_used = -1
306 315 end
307 316
308 317 return {
309 318 :msg => "#{run_stat}\n#{time_stat}",
310 319 :running_time => seconds,
311 320 :exit_status => run_stat,
312 321 :memory_usage => memory_used
313 322 }
@@ -1,232 +1,239
1 1 /* Main Default */
2 2 body {
3 3 background: white url(../images/topbg.jpg) repeat-x top center;
4 4 font-size: 13px;
5 5 font-family: Tahoma, "sans-serif";
6 6 margin: 10px;
7 7 padding: 10px;
8 8 }
9 9
10 10 /* Form Font */
11 11 input {
12 12 font-family: Tahoma, "sans-serif";
13 13 }
14 14
15 - /* Heading 1/2 */
15 + /* Heading 1&2 */
16 16 h1 {
17 17 font-size: 24px;
18 18 color: #334488;
19 19 line-height: 2em;
20 20 }
21 21
22 22 h2 {
23 23 font-size: 18px;
24 24 color: #5566bb;
25 25 line-height: 1.5em;
26 26 }
27 27
28 28 /* Bar Line Color and Thickness */
29 29 hr {
30 30 border-top: 1px solid #dddddd;
31 31 border-bottom: 1px solid #eeeeee;
32 32 }
33 33
34 34 /* Link + Anchor Color */
35 35 a, a:link, a:visited {
36 36 color: #6666cc;
37 37 text-decoration: none;
38 38 }
39 39
40 40 a:hover, a:focus {
41 41 color: #111166;
42 42 text-decoration: none;
43 43 }
44 44
45 45 /* This is the main menu bad*/
46 46 div.userbar {
47 47 line-height: 1.5em;
48 48 text-align: right;
49 49 font-size: 12px;
50 50 }
51 51
52 52 /* This is the top bar, displaying user's full name */
53 53 div.title {
54 54 // background: #ddddff;
55 55 // border: 1px dashed blue;
56 56 padding: 10px 0px;
57 57 line-height: 1.5em;
58 58 font-size: 13px;
59 59 }
60 60
61 61 div.title span.contest-over-msg {
62 62 font-size: 15px;
63 63 color: red;
64 64 }
65 65
66 66 div.title table {
67 67 width: 100%;
68 + font-weight: bold;
68 69 }
69 70
70 71 div.title td.left-col {
71 72 text-align: left;
72 73 vertical-align: top;
73 74 color: #444444;
74 75 }
75 76
76 77 div.title td.right-col {
77 78 text-align: right;
78 79 vertical-align: top;
79 - font-size: 14px;
80 - font-weight: bold;
80 + font-size: 18px;
81 81 color: #116699;
82 82 }
83 83
84 84 /* Standard table with header and rows with alternating background */
85 85 table.info {
86 86 margin: 10px 0;
87 87 border: 1px solid #666666;
88 88 border-collapse: collapse;
89 89 font-size: 12px;
90 90 }
91 91
92 92 table.info th {
93 93 border: 1px solid #666666;
94 94 line-height: 1.5em;
95 95 padding: 0 0.5em;
96 96 }
97 97
98 98 table.info td {
99 99 border-left: 1px solid #666666;
100 100 border-right: 1px solid #666666;
101 101 line-height: 1.5em;
102 102 padding: 0 0.5em;
103 103 }
104 104
105 105 tr.info-head {
106 106 background: #777777;
107 107 color: white;
108 108 }
109 109
110 110 tr.info-odd {
111 111 background: #eeeeee;
112 112 }
113 113
114 114 tr.info-even {
115 115 background: #f9f9f9;
116 116 }
117 117
118 118 /*******************************
119 119 [Main]
120 120 ********************************/
121 121 div.submitbox {
122 122 background: #eeeeff;
123 123 border: 1px dotted #99aaee;
124 124 padding: 5px;
125 125 margin: 10px 0px;
126 126 color: black;
127 127 font-weight: bold;
128 128 font-size: 13px;
129 129 }
130 130
131 131 div.errorExplanation {
132 132 border: 1px dotted gray;
133 133 color: #bb2222;
134 134 padding: 5px 15px 5px 15px;
135 135 margin-bottom: 5px;
136 136 background-color: white;
137 + font-weight: normal;
138 + }
139 +
140 +
141 + div.errorExplanation h2 {
142 + color: #cc1111;
143 + font-weight: bold;
137 144 }
138 145
139 146 /*******************************
140 147 [Settings]
141 148 ********************************/
142 149 table.uinfo {
143 150 border-collapse: collapse;
144 151 border: 1px solid black;
145 152 font-size: 13px;
146 153 }
147 154
148 155 td.uinfo {
149 156 vertical-align: top;
150 157 border: 1px solid black;
151 158 padding: 5px;
152 159 }
153 160
154 161 th.uinfo {
155 162 background: lightgreen;
156 163 vertical-align: top;
157 164 text-align: right;
158 165 border: 1px solid black;
159 166 padding: 5px;
160 167 }
161 168
162 169 /*******************************
163 170 [Submission]
164 171 ********************************/
165 172 div.compilermsgbody {
166 173 font-family: monospace;
167 174 }
168 175
169 176 div.task-menu {
170 177 text-align: center;
171 178 font-size: 13px;
172 179 line-height: 1.75em;
173 180 font-weight: bold;
174 181 border-top: 1px dashed gray;
175 182 border-bottom: 1px dashed gray;
176 183 margin-top: 2px;
177 184 margin-bottom: 4px;
178 185 }
179 186
180 187 /*******************************
181 188 [Submission]
182 189 ********************************/
183 190 table.taskdesc {
184 191 border: 2px solid #dddddd;
185 192 border-collapse: collapse;
186 193 margin: 10px auto;
187 194 width: 90%;
188 195 font-size: 13px;
189 196 }
190 197
191 198 table.taskdesc p {
192 199 font-size: 13px;
193 200 }
194 201
195 202 table.taskdesc tr.name {
196 203 border: 2px solid #dddddd;
197 204 background: #dddddd;
198 205 color: #333333;
199 206 font-weight: bold;
200 207 font-size: 14px;
201 208 line-height: 1.5em;
202 209 text-align: center;
203 210 }
204 211
205 212 table.taskdesc td.desc-odd {
206 213 padding: 5px;
207 214 padding-left: 20px;
208 215 background: #fefeee;
209 216 }
210 217
211 218 table.taskdesc td.desc-even {
212 219 padding: 5px;
213 220 padding-left: 20px;
214 221 background: #feeefe;
215 222 }
216 223
217 224 /**********************
218 225 Announcement
219 226 ***********************/
220 227
221 228 div.announcementbox {
222 229 margin: 10px 0px;
223 230 background: #bbddee;
224 231 padding: 1px;
225 232 }
226 233
227 234 div.announcementbox span.title {
228 235 font-weight: bold;
229 236 color: #224455;
230 237 padding-left: 10px;
231 238 line-height: 1.6em;
232 239 }
You need to be logged in to leave comments. Login now