Description:
added problem list auto update
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r257:76846842a151 - - 3 files changed: 14 inserted, 2 deleted

@@ -183,192 +183,201
183 183 end
184 184
185 185 #
186 186 # actions for Code Jom
187 187 #
188 188 def download_input
189 189 user = User.find(session[:user_id])
190 190
191 191 if Configuration.time_limit_mode? and user.contest_finished?
192 192 redirect_to :action => 'list' and return
193 193 end
194 194
195 195 problem = Problem.find(params[:id])
196 196 if user.can_request_new_test_pair_for? problem
197 197 assignment = user.get_new_test_pair_assignment_for problem
198 198 assignment.save
199 199
200 200 send_data(assignment.test_pair.input,
201 201 { :filename => "#{problem.name}-#{assignment.request_number}.in",
202 202 :type => 'text/plain' })
203 203 else
204 204 recent_assignment = user.get_recent_test_pair_assignment_for problem
205 205 send_data(recent_assignment.test_pair.input,
206 206 { :filename => "#{problem.name}-#{recent_assignment.request_number}.in",
207 207 :type => 'text/plain' })
208 208 end
209 209 end
210 210
211 211 def submit_solution
212 212 problem = Problem.find(params[:id])
213 213 user = User.find(session[:user_id])
214 214 recent_assignment = user.get_recent_test_pair_assignment_for problem
215 215
216 216 if Configuration.time_limit_mode? and user.contest_finished?
217 217 redirect_to :action => 'list' and return
218 218 end
219 219
220 220 if recent_assignment == nil
221 221 flash[:notice] = 'You have not requested for any input data for this problem. Please download an input first.'
222 222 session[:current_problem_id] = problem.id
223 223 redirect_to :action => 'list' and return
224 224 end
225 225
226 226 if recent_assignment.expired?
227 227 flash[:notice] = 'The current input is expired. Please download a new input data.'
228 228 session[:current_problem_id] = problem.id
229 229 redirect_to :action => 'list' and return
230 230 end
231 231
232 232 if recent_assignment.submitted
233 233 flash[:notice] = 'You have already submitted an incorrect solution for this input. Please download a new input data.'
234 234 session[:current_problem_id] = problem.id
235 235 redirect_to :action => 'list' and return
236 236 end
237 237
238 238 if params[:file] == nil
239 239 flash[:notice] = 'You have not submitted any output.'
240 240 session[:current_problem_id] = problem.id
241 241 redirect_to :action => 'list' and return
242 242 end
243 243
244 244 submitted_solution = params[:file].read
245 245 test_pair = recent_assignment.test_pair
246 246 passed = test_pair.grade(submitted_solution)
247 247 points = passed ? 100 : 0
248 248 submission = Submission.new(:user => user,
249 249 :problem => problem,
250 250 :source => submitted_solution,
251 251 :source_filename => params['file'].original_filename,
252 252 :language_id => 0,
253 253 :submitted_at => Time.new.gmtime,
254 254 :graded_at => Time.new.gmtime,
255 255 :points => points)
256 256 submission.save
257 257 recent_assignment.submitted = true
258 258 recent_assignment.save
259 259
260 260 status = user.get_submission_status_for(problem)
261 261 if status == nil
262 262 status = SubmissionStatus.new :user => user, :problem => problem, :submission_count => 0
263 263 end
264 264
265 265 status.submission_count += 1
266 266 status.passed = passed
267 267 status.save
268 268
269 269 if passed
270 270 flash[:notice] = 'Correct solution.'
271 271 user.update_codejom_status
272 272 else
273 273 session[:current_problem_id] = problem.id
274 274 flash[:notice] = 'Incorrect solution.'
275 275 end
276 276 redirect_to :action => 'list'
277 277 end
278 278
279 + def problems
280 + prepare_list_information
281 + render :partial => 'problem_title', :collection => @problems, :as => :problem
282 + end
283 +
284 + def splash
285 + render :text => '<div class="notice">Most recent task:</span>'
286 + end
287 +
279 288 protected
280 289
281 290 def prepare_announcements(recent=nil)
282 291 if Configuration.show_tasks_to?(@user)
283 292 @announcements = Announcement.find_published(true)
284 293 else
285 294 @announcements = Announcement.find_published
286 295 end
287 296 if recent!=nil
288 297 recent_id = recent.to_i
289 298 @announcements = @announcements.find_all { |a| a.id > recent_id }
290 299 end
291 300 end
292 301
293 302 def prepare_timeout_information(problems)
294 303 @submission_timeouts = {}
295 304 problems.each do |problem|
296 305 assignment = @user.get_recent_test_pair_assignment_for(problem)
297 306 if assignment == nil
298 307 timeout = nil
299 308 else
300 309 if (assignment.expired?) or (assignment.submitted)
301 310 timeout = 0
302 311 else
303 312 timeout = assignment.created_at + TEST_ASSIGNMENT_EXPIRATION_DURATION - Time.new.gmtime
304 313 end
305 314 end
306 315 @submission_timeouts[problem.id] = timeout
307 316 end
308 317 @submission_timeouts.each_pair {|k,v| puts "#{k} => #{v}"}
309 318 end
310 319
311 320 def prepare_list_information
312 321 @user = User.find(session[:user_id])
313 322
314 323 all_problems = Problem.find_available_problems
315 324
316 325 passed = {}
317 326 sub_count = {}
318 327 @user.submission_statuses.each do |status|
319 328 if status.passed
320 329 passed[status.problem_id] = true
321 330 end
322 331 sub_count[status.problem_id] = status.submission_count
323 332 end
324 333
325 334 if session.has_key? :current_problem_id
326 335 @current_problem_id = session[:current_problem_id]
327 336 session.delete(:current_problem_id)
328 337 else
329 338 @current_problem_id = nil
330 339 end
331 340
332 341 @problems = all_problems.reject { |problem| passed.has_key? problem.id }
333 342
334 343 prepare_timeout_information(@problems)
335 344
336 345 @prob_submissions = Array.new
337 346 @problems.each do |p|
338 347 if sub_count.has_key? p.id
339 348 @prob_submissions << { :count => sub_count[p.id] }
340 349 else
341 350 @prob_submissions << { :count => 0 }
342 351 end
343 352 end
344 353 prepare_announcements
345 354 end
346 355
347 356 def check_viewability
348 357 @user = User.find(session[:user_id])
349 358 if (!Configuration.show_tasks_to?(@user)) and
350 359 ((action_name=='submission') or (action_name=='submit'))
351 360 redirect_to :action => 'list' and return
352 361 end
353 362 end
354 363
355 364 def prepare_grading_result(submission)
356 365 if Configuration.task_grading_info.has_key? submission.problem.name
357 366 grading_info = Configuration.task_grading_info[submission.problem.name]
358 367 else
359 368 # guess task info from problem.full_score
360 369 cases = submission.problem.full_score / 10
361 370 grading_info = {
362 371 'testruns' => cases,
363 372 'testcases' => cases
364 373 }
365 374 end
366 375 @test_runs = []
367 376 if grading_info['testruns'].is_a? Integer
368 377 trun_count = grading_info['testruns']
369 378 trun_count.times do |i|
370 379 @test_runs << [ read_grading_result(@user.login,
371 380 submission.problem.name,
372 381 submission.id,
373 382 i+1) ]
374 383 end
@@ -1,39 +1,42
1 1 - content_for :head do
2 2 = javascript_include_tag :defaults
3 3 = javascript_include_tag 'announcement_refresh.js'
4 4 = javascript_include_tag 'codejom_timeout.js'
5 5
6 6 = user_title_bar(@user)
7 7
8 8 .announcementbox{:style => (@announcements.length==0 ? "display:none" : "")}
9 9 %span{:class => 'title'}
10 10 Announcements
11 11 #announcementbox-body
12 12 = render :partial => 'announcement', :collection => @announcements
13 13
14 14 %hr/
15 15
16 16 - if (Configuration.contest_mode?) and (@user.site!=nil) and (@user.site.started!=true)
17 17 %p=t 'main.start_soon'
18 18
19 19 - if Configuration.show_tasks_to?(@user)
20 - .problem-list
20 + .problem-list{:id => 'problem-list'}
21 21 = render :partial => 'problem_title', :collection => @problems, :as => :problem
22 22 .problem-content
23 23 %span{:id => "problem-panel-filler", :style => (@current_problem_id!=nil) ? "display:none" : ""}
24 24 %h2
25 25 Welcome to Code Jom
26 26 %br/
27 27 Choose problems from the list on the right.
28 28 = render :partial => 'problem', :collection => @problems
29 29
30 30 %br{:clear=>'both'}/
31 31 %hr/
32 32
33 33 %script{:type => 'text/javascript'}
34 34 = "Announcement.refreshUrl = '#{url_for :controller => 'main', :action => 'announcements'}';"
35 35 Announcement.registerRefreshEventTimer();
36 36 = render :partial => 'submission_timeouts'
37 37 CodejomTimeout.updateProblemMessages();
38 38 CodejomTimeout.registerRefreshEvent();
39 39
40 + = periodically_call_remote(:url => { :action => 'problems' }, :update => 'problem-list')
41 +
42 +
@@ -242,97 +242,97
242 242 font-size: 10px
243 243 line-height: 1.75em
244 244 padding: 0 5px
245 245 color: #444444
246 246 background: #bbbbbb
247 247 font-weight: bold
248 248
249 249 .body
250 250 border: 2px solid #dddddd
251 251 background: #fff8f8
252 252 padding-left: 5px
253 253
254 254 .reply-body
255 255 border: 2px solid #bbbbbb
256 256 background: #fffff8
257 257 padding-left: 5px
258 258
259 259 .stat
260 260 font-size: 10px
261 261 line-height: 1.75em
262 262 padding: 0 5px
263 263 color: #333333
264 264 background: #dddddd
265 265 font-weight: bold
266 266
267 267 .contest-title
268 268 color: white
269 269 text-align: center
270 270 line-height: 2em
271 271
272 272 .registration-desc
273 273 border: 1px dotted gray
274 274 background: #f5f5f5
275 275 padding: 5px
276 276 margin: 10px 0
277 277 font-size: 12px
278 278 line-height: 1.5em
279 279
280 280 .test-desc
281 281 border: 1px dotted gray
282 282 background: #f5f5f5
283 283 padding: 5px
284 284 margin: 10px 0
285 285 font-size: 12px
286 286 line-height: 1.5em
287 287
288 288 .problem-list
289 289 width: 200px
290 290 float: left
291 291
292 292 .problem-bar
293 293 margin-top: 5px
294 294 padding: 5px
295 295 background: #e0e0e0
296 296
297 297 span.problem-title
298 298 font-weight: bold
299 299 font-size: 110%
300 300
301 301 .problem-content
302 302 float: left
303 303 margin-left: 10px
304 304 width: 700px
305 305
306 306 .problem-panel
307 307 border: 1px black solid
308 308 padding: 5px
309 309
310 310 .problem-form
311 311 border: 1px dotted #99aaee
312 312 background: #eeeeff
313 313
314 314 .notice-bar
315 315 margin-top: 3px
316 316 margin-bottom: 3px
317 317 text-align: center
318 318
319 319 span.notice
320 320 color: white
321 321 font-weight: bold
322 322 background: #000070
323 323 padding: 3px 20px 3px 20px
324 324 -moz-border-radius: 2px
325 325 -webkit-border-radius: 5px
326 326 border-radius: 5px
327 327
328 328 table.codejom-problems
329 329 th
330 330 background: #000070
331 331 color: white
332 332 td
333 333 width: 200px
334 334 vertical-align: top
335 335 text-align: center
336 336
337 337 &.random-button
338 - background: lightgrey No newline at end of file
338 + background: lightgrey
You need to be logged in to leave comments. Login now