Description:
[web] test request stops at 30 min before end, auto refresh grader process status git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@258 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

r128:f40baf68cc55 - - 4 files changed: 20 inserted, 3 deleted

@@ -5,55 +5,62
5 5 before_filter :authenticate, :check_viewability
6 6
7 7 #
8 8 # COMMENT OUT: filter in each action instead
9 9 #
10 10 # before_filter :verify_time_limit, :only => [:submit]
11 11
12 12 verify :method => :post, :only => [:submit],
13 13 :redirect_to => { :action => :index }
14 14
15 15 def index
16 16 prepare_index_information
17 17 end
18 18
19 19 def submit
20 20 @user = User.find(session[:user_id])
21 21
22 22 @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request])
23 23
24 24 if @submitted_test_request.errors.length != 0
25 25 prepare_index_information
26 26 render :action => 'index' and return
27 27 end
28 28
29 - if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' and
30 - @user.site!=nil and @user.site.finished?
29 + if Configuration[SYSTEM_MODE_CONF_KEY]=='contest'
30 + if @user.site!=nil and @user.site.finished?
31 31 @submitted_test_request.errors.add_to_base('Contest is over.')
32 32 prepare_index_information
33 33 render :action => 'index' and return
34 34 end
35 35
36 + if !Configuration.allow_test_request(@user)
37 + prepare_index_information
38 + flash[:notice] = 'Test request is not allowed during the last 30 minutes'
39 + redirect_to :action => 'index' and return
40 + end
41 + end
42 +
36 43 if @submitted_test_request.save
37 44 redirect_to :action => 'index'
38 45 else
39 46 prepare_index_information
40 47 render :action => 'index'
41 48 end
42 49 end
43 50
44 51 def read
45 52 user = User.find(session[:user_id])
46 53 begin
47 54 test_request = TestRequest.find(params[:id])
48 55 rescue
49 56 test_request = nil
50 57 end
51 58 if test_request==nil or test_request.user_id != user.id
52 59 flash[:notice] = 'Invalid output'
53 60 redirect_to :action => 'index'
54 61 return
55 62 end
56 63 if test_request.output_file_name!=nil
57 64 data = File.open(test_request.output_file_name).read(2048)
58 65 if data==nil
59 66 data=""
@@ -26,45 +26,54
26 26 @@configurations = nil
27 27 end
28 28
29 29 #
30 30 # View decision
31 31 #
32 32 def self.show_submitbox_to?(user)
33 33 mode = get(SYSTEM_MODE_CONF_KEY)
34 34 return false if mode=='analysis'
35 35 if (mode=='contest')
36 36 return false if (user.site!=nil) and
37 37 ((user.site.started==false) or (user.site.finished?))
38 38 end
39 39 return true
40 40 end
41 41
42 42 def self.show_tasks_to?(user)
43 43 mode = get(SYSTEM_MODE_CONF_KEY)
44 44 if (mode=='contest')
45 45 return false if (user.site!=nil) and (user.site.started==false)
46 46 end
47 47 return true
48 48 end
49 49
50 + def self.allow_test_request(user)
51 + mode = get(SYSTEM_MODE_CONF_KEY)
52 + if (mode=='contest')
53 + return false if (user.site!=nil) and ((user.site.started==false) or
54 + (user.site.time_left < 30.minutes))
55 + end
56 + return false if mode=='analysis'
57 + return true
58 + end
50 59
51 60 protected
52 61 def self.read_config
53 62 @@configurations = {}
54 63 Configuration.find(:all).each do |conf|
55 64 key = conf.key
56 65 val = conf.value
57 66 case conf.value_type
58 67 when 'string'
59 68 @@configurations[key] = val
60 69
61 70 when 'integer'
62 71 @@configurations[key] = val.to_i
63 72
64 73 when 'boolean'
65 74 @@configurations[key] = (val=='true')
66 75 end
67 76 end
68 77 end
69 78
70 79 end
@@ -1,24 +1,25
1 1 - content_for :head do
2 2 = stylesheet_link_tag 'graders'
3 + <meta http-equiv ="refresh" content="10"/>
3 4
4 5 %h2 (Under Experiments)
5 6
6 7 - form_for :clear, nil, :url => {:action => 'clear_all'} do |f|
7 8 = submit_tag 'Clear all data'
8 9
9 10 Last task:
10 11 = link_to "#{@last_task.id}", :action => 'view', :id => @last_task.id, :type => 'Task'
11 12
12 13 %br/
13 14
14 15 Last test_request:
15 16 = link_to "#{@last_test_request.id}", :action => 'view', :id => @last_test_request.id, :type => 'TestRequest'
16 17
17 18
18 19 %h3 Current graders
19 20
20 21 = render :partial => 'grader_list', :locals => {:grader_list => @grader_processes}
21 22
22 23 %h3 Stalled graders
23 24
24 25 = render :partial => 'grader_list', :locals => {:grader_list => @stalled_processes}
@@ -14,49 +14,49
14 14 <script type="text/javascript">
15 15 var submissionCount = new Array();
16 16 <% @submissions.each do |submission| %>
17 17 submissionCount[<%= submission.problem_id %>]=<%= submission.number %>;
18 18 <% end %>
19 19
20 20 function updateSubmissionList() {
21 21 currentProb = document.getElementById("test_request_problem_id").value;
22 22 count = submissionCount[currentProb];
23 23 submissionSelect = document.getElementById("test_request_submission_number");
24 24 old_len = submissionSelect.length;
25 25 // clear the box
26 26 for(i=0; i<old_len; i++)
27 27 submissionSelect.remove(0);
28 28 for(i=count; i>=1; i--) {
29 29 try {
30 30 submissionSelect.add(new Option(""+i,""+i,false,false),null);
31 31 } catch(ex) {
32 32 submissionSelect.add(new Option(""+i,""+i,false,false));
33 33 }
34 34 }
35 35 }
36 36 </script>
37 37
38 - <% if Configuration.show_submitbox_to?(@user) %>
38 + <% if Configuration.show_submitbox_to?(@user) and Configuration.allow_test_request(@user) %>
39 39 <div class="submitbox">
40 40 <%= error_messages_for 'submitted_test_request' %>
41 41 <% form_for :test_request, nil,
42 42 :url => { :action => 'submit'},
43 43 :html => { :multipart => true } do |f| %>
44 44 <table>
45 45 <tr>
46 46 <td>Task:</td>
47 47 <td>
48 48 <%= select(:test_request,
49 49 :problem_id,
50 50 @problems.collect {|p| [p.name, p.id]}, {},
51 51 { :onclick => "updateSubmissionList();" }) %>
52 52 </td>
53 53 </tr>
54 54 <tr>
55 55 <td>Submission:</td>
56 56 <td>
57 57 <%= select(:test_request,
58 58 :submission_number,
59 59 ((1..@submissions[0].number).collect {|n| [n,n]}).reverse) %>
60 60 </td>
61 61 </tr>
62 62 <tr>
You need to be logged in to leave comments. Login now