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: 24 inserted, 7 deleted

@@ -1,108 +1,115
1 class TestController < ApplicationController
1 class TestController < ApplicationController
2
2
3 SYSTEM_MODE_CONF_KEY = 'system.mode'
3 SYSTEM_MODE_CONF_KEY = 'system.mode'
4
4
5 before_filter :authenticate, :check_viewability
5 before_filter :authenticate, :check_viewability
6
6
7 #
7 #
8 # COMMENT OUT: filter in each action instead
8 # COMMENT OUT: filter in each action instead
9 #
9 #
10 # before_filter :verify_time_limit, :only => [:submit]
10 # before_filter :verify_time_limit, :only => [:submit]
11
11
12 verify :method => :post, :only => [:submit],
12 verify :method => :post, :only => [:submit],
13 :redirect_to => { :action => :index }
13 :redirect_to => { :action => :index }
14
14
15 def index
15 def index
16 prepare_index_information
16 prepare_index_information
17 end
17 end
18
18
19 def submit
19 def submit
20 @user = User.find(session[:user_id])
20 @user = User.find(session[:user_id])
21
21
22 @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request])
22 @submitted_test_request = TestRequest.new_from_form_params(@user,params[:test_request])
23
23
24 if @submitted_test_request.errors.length != 0
24 if @submitted_test_request.errors.length != 0
25 prepare_index_information
25 prepare_index_information
26 render :action => 'index' and return
26 render :action => 'index' and return
27 end
27 end
28
28
29 - if Configuration[SYSTEM_MODE_CONF_KEY]=='contest' and
29 + if Configuration[SYSTEM_MODE_CONF_KEY]=='contest'
30 - @user.site!=nil and @user.site.finished?
30 + if @user.site!=nil and @user.site.finished?
31 - @submitted_test_request.errors.add_to_base('Contest is over.')
31 + @submitted_test_request.errors.add_to_base('Contest is over.')
32 - prepare_index_information
32 + prepare_index_information
33 - render :action => 'index' and return
33 + render :action => 'index' and return
34 + end
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
34 end
41 end
35
42
36 if @submitted_test_request.save
43 if @submitted_test_request.save
37 redirect_to :action => 'index'
44 redirect_to :action => 'index'
38 else
45 else
39 prepare_index_information
46 prepare_index_information
40 render :action => 'index'
47 render :action => 'index'
41 end
48 end
42 end
49 end
43
50
44 def read
51 def read
45 user = User.find(session[:user_id])
52 user = User.find(session[:user_id])
46 begin
53 begin
47 test_request = TestRequest.find(params[:id])
54 test_request = TestRequest.find(params[:id])
48 rescue
55 rescue
49 test_request = nil
56 test_request = nil
50 end
57 end
51 if test_request==nil or test_request.user_id != user.id
58 if test_request==nil or test_request.user_id != user.id
52 flash[:notice] = 'Invalid output'
59 flash[:notice] = 'Invalid output'
53 redirect_to :action => 'index'
60 redirect_to :action => 'index'
54 return
61 return
55 end
62 end
56 if test_request.output_file_name!=nil
63 if test_request.output_file_name!=nil
57 data = File.open(test_request.output_file_name).read(2048)
64 data = File.open(test_request.output_file_name).read(2048)
58 if data==nil
65 if data==nil
59 data=""
66 data=""
60 end
67 end
61 send_data(data,
68 send_data(data,
62 {:filename => 'output.txt',
69 {:filename => 'output.txt',
63 :type => 'text/plain'})
70 :type => 'text/plain'})
64 return
71 return
65 end
72 end
66 redirect_to :action => 'index'
73 redirect_to :action => 'index'
67 end
74 end
68
75
69 def result
76 def result
70 @user = User.find(session[:user_id])
77 @user = User.find(session[:user_id])
71 begin
78 begin
72 @test_request = TestRequest.find(params[:id])
79 @test_request = TestRequest.find(params[:id])
73 rescue
80 rescue
74 @test_request = nil
81 @test_request = nil
75 end
82 end
76 if @test_request==nil or @test_request.user_id != @user.id
83 if @test_request==nil or @test_request.user_id != @user.id
77 flash[:notice] = 'Invalid request'
84 flash[:notice] = 'Invalid request'
78 redirect_to :action => 'index'
85 redirect_to :action => 'index'
79 return
86 return
80 end
87 end
81 end
88 end
82
89
83 protected
90 protected
84
91
85 def prepare_index_information
92 def prepare_index_information
86 @user = User.find(session[:user_id])
93 @user = User.find(session[:user_id])
87 @submissions = Submission.find_last_for_all_available_problems(@user.id)
94 @submissions = Submission.find_last_for_all_available_problems(@user.id)
88 all_problems = @submissions.collect { |submission| submission.problem }
95 all_problems = @submissions.collect { |submission| submission.problem }
89 @problems = []
96 @problems = []
90 all_problems.each do |problem|
97 all_problems.each do |problem|
91 if problem.test_allowed
98 if problem.test_allowed
92 @problems << problem
99 @problems << problem
93 end
100 end
94 end
101 end
95 @test_requests = @user.test_requests
102 @test_requests = @user.test_requests
96 end
103 end
97
104
98 def check_viewability
105 def check_viewability
99 user = User.find(session[:user_id])
106 user = User.find(session[:user_id])
100 if !Configuration.show_tasks_to?(user)
107 if !Configuration.show_tasks_to?(user)
101 redirect_to :controller => 'main', :action => 'list'
108 redirect_to :controller => 'main', :action => 'list'
102 end
109 end
103 if (!Configuration.show_submitbox_to?(user)) and (action_name=='submit')
110 if (!Configuration.show_submitbox_to?(user)) and (action_name=='submit')
104 redirect_to :controller => 'test', :action => 'index'
111 redirect_to :controller => 'test', :action => 'index'
105 end
112 end
106 end
113 end
107
114
108 end
115 end
@@ -1,70 +1,79
1 #
1 #
2 # This class also contains various login of the system.
2 # This class also contains various login of the system.
3 #
3 #
4 class Configuration < ActiveRecord::Base
4 class Configuration < ActiveRecord::Base
5
5
6 SYSTEM_MODE_CONF_KEY = 'system.mode'
6 SYSTEM_MODE_CONF_KEY = 'system.mode'
7
7
8 @@configurations = nil
8 @@configurations = nil
9
9
10 def self.get(key)
10 def self.get(key)
11 if @@configurations == nil
11 if @@configurations == nil
12 self.read_config
12 self.read_config
13 end
13 end
14 return @@configurations[key]
14 return @@configurations[key]
15 end
15 end
16
16
17 def self.[](key)
17 def self.[](key)
18 self.get(key)
18 self.get(key)
19 end
19 end
20
20
21 def self.reload
21 def self.reload
22 self.read_config
22 self.read_config
23 end
23 end
24
24
25 def self.clear
25 def self.clear
26 @@configurations = nil
26 @@configurations = nil
27 end
27 end
28
28
29 #
29 #
30 # View decision
30 # View decision
31 #
31 #
32 def self.show_submitbox_to?(user)
32 def self.show_submitbox_to?(user)
33 mode = get(SYSTEM_MODE_CONF_KEY)
33 mode = get(SYSTEM_MODE_CONF_KEY)
34 return false if mode=='analysis'
34 return false if mode=='analysis'
35 if (mode=='contest')
35 if (mode=='contest')
36 return false if (user.site!=nil) and
36 return false if (user.site!=nil) and
37 ((user.site.started==false) or (user.site.finished?))
37 ((user.site.started==false) or (user.site.finished?))
38 end
38 end
39 return true
39 return true
40 end
40 end
41
41
42 def self.show_tasks_to?(user)
42 def self.show_tasks_to?(user)
43 mode = get(SYSTEM_MODE_CONF_KEY)
43 mode = get(SYSTEM_MODE_CONF_KEY)
44 if (mode=='contest')
44 if (mode=='contest')
45 return false if (user.site!=nil) and (user.site.started==false)
45 return false if (user.site!=nil) and (user.site.started==false)
46 end
46 end
47 return true
47 return true
48 end
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 protected
60 protected
52 def self.read_config
61 def self.read_config
53 @@configurations = {}
62 @@configurations = {}
54 Configuration.find(:all).each do |conf|
63 Configuration.find(:all).each do |conf|
55 key = conf.key
64 key = conf.key
56 val = conf.value
65 val = conf.value
57 case conf.value_type
66 case conf.value_type
58 when 'string'
67 when 'string'
59 @@configurations[key] = val
68 @@configurations[key] = val
60
69
61 when 'integer'
70 when 'integer'
62 @@configurations[key] = val.to_i
71 @@configurations[key] = val.to_i
63
72
64 when 'boolean'
73 when 'boolean'
65 @@configurations[key] = (val=='true')
74 @@configurations[key] = (val=='true')
66 end
75 end
67 end
76 end
68 end
77 end
69
78
70 end
79 end
@@ -1,24 +1,25
1 - content_for :head do
1 - content_for :head do
2 = stylesheet_link_tag 'graders'
2 = stylesheet_link_tag 'graders'
3 + <meta http-equiv ="refresh" content="10"/>
3
4
4 %h2 (Under Experiments)
5 %h2 (Under Experiments)
5
6
6 - form_for :clear, nil, :url => {:action => 'clear_all'} do |f|
7 - form_for :clear, nil, :url => {:action => 'clear_all'} do |f|
7 = submit_tag 'Clear all data'
8 = submit_tag 'Clear all data'
8
9
9 Last task:
10 Last task:
10 = link_to "#{@last_task.id}", :action => 'view', :id => @last_task.id, :type => 'Task'
11 = link_to "#{@last_task.id}", :action => 'view', :id => @last_task.id, :type => 'Task'
11
12
12 %br/
13 %br/
13
14
14 Last test_request:
15 Last test_request:
15 = link_to "#{@last_test_request.id}", :action => 'view', :id => @last_test_request.id, :type => 'TestRequest'
16 = link_to "#{@last_test_request.id}", :action => 'view', :id => @last_test_request.id, :type => 'TestRequest'
16
17
17
18
18 %h3 Current graders
19 %h3 Current graders
19
20
20 = render :partial => 'grader_list', :locals => {:grader_list => @grader_processes}
21 = render :partial => 'grader_list', :locals => {:grader_list => @grader_processes}
21
22
22 %h3 Stalled graders
23 %h3 Stalled graders
23
24
24 = render :partial => 'grader_list', :locals => {:grader_list => @stalled_processes}
25 = render :partial => 'grader_list', :locals => {:grader_list => @stalled_processes}
@@ -1,112 +1,112
1 <%= user_title_bar(@user) %>
1 <%= user_title_bar(@user) %>
2
2
3 <h2>Test Interface</h2>
3 <h2>Test Interface</h2>
4
4
5 <p>
5 <p>
6 <b>Note:</b> Test interface will be disabled in the last 30 minutes
6 <b>Note:</b> Test interface will be disabled in the last 30 minutes
7 of the contest time on your site.
7 of the contest time on your site.
8 </p>
8 </p>
9
9
10 <% if @problems.length==0 %>
10 <% if @problems.length==0 %>
11 There is no submission
11 There is no submission
12 <% else %>
12 <% else %>
13
13
14 <script type="text/javascript">
14 <script type="text/javascript">
15 var submissionCount = new Array();
15 var submissionCount = new Array();
16 <% @submissions.each do |submission| %>
16 <% @submissions.each do |submission| %>
17 submissionCount[<%= submission.problem_id %>]=<%= submission.number %>;
17 submissionCount[<%= submission.problem_id %>]=<%= submission.number %>;
18 <% end %>
18 <% end %>
19
19
20 function updateSubmissionList() {
20 function updateSubmissionList() {
21 currentProb = document.getElementById("test_request_problem_id").value;
21 currentProb = document.getElementById("test_request_problem_id").value;
22 count = submissionCount[currentProb];
22 count = submissionCount[currentProb];
23 submissionSelect = document.getElementById("test_request_submission_number");
23 submissionSelect = document.getElementById("test_request_submission_number");
24 old_len = submissionSelect.length;
24 old_len = submissionSelect.length;
25 // clear the box
25 // clear the box
26 for(i=0; i<old_len; i++)
26 for(i=0; i<old_len; i++)
27 submissionSelect.remove(0);
27 submissionSelect.remove(0);
28 for(i=count; i>=1; i--) {
28 for(i=count; i>=1; i--) {
29 try {
29 try {
30 submissionSelect.add(new Option(""+i,""+i,false,false),null);
30 submissionSelect.add(new Option(""+i,""+i,false,false),null);
31 } catch(ex) {
31 } catch(ex) {
32 submissionSelect.add(new Option(""+i,""+i,false,false));
32 submissionSelect.add(new Option(""+i,""+i,false,false));
33 }
33 }
34 }
34 }
35 }
35 }
36 </script>
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 <div class="submitbox">
39 <div class="submitbox">
40 <%= error_messages_for 'submitted_test_request' %>
40 <%= error_messages_for 'submitted_test_request' %>
41 <% form_for :test_request, nil,
41 <% form_for :test_request, nil,
42 :url => { :action => 'submit'},
42 :url => { :action => 'submit'},
43 :html => { :multipart => true } do |f| %>
43 :html => { :multipart => true } do |f| %>
44 <table>
44 <table>
45 <tr>
45 <tr>
46 <td>Task:</td>
46 <td>Task:</td>
47 <td>
47 <td>
48 <%= select(:test_request,
48 <%= select(:test_request,
49 :problem_id,
49 :problem_id,
50 @problems.collect {|p| [p.name, p.id]}, {},
50 @problems.collect {|p| [p.name, p.id]}, {},
51 { :onclick => "updateSubmissionList();" }) %>
51 { :onclick => "updateSubmissionList();" }) %>
52 </td>
52 </td>
53 </tr>
53 </tr>
54 <tr>
54 <tr>
55 <td>Submission:</td>
55 <td>Submission:</td>
56 <td>
56 <td>
57 <%= select(:test_request,
57 <%= select(:test_request,
58 :submission_number,
58 :submission_number,
59 ((1..@submissions[0].number).collect {|n| [n,n]}).reverse) %>
59 ((1..@submissions[0].number).collect {|n| [n,n]}).reverse) %>
60 </td>
60 </td>
61 </tr>
61 </tr>
62 <tr>
62 <tr>
63 <td>Input data:</td>
63 <td>Input data:</td>
64 <td>
64 <td>
65 <%= f.file_field :input_file %>
65 <%= f.file_field :input_file %>
66 </td>
66 </td>
67 <td>
67 <td>
68 (combined size should not exceed 2MB)
68 (combined size should not exceed 2MB)
69 </td>
69 </td>
70 </tr>
70 </tr>
71 <tr>
71 <tr>
72 <td>
72 <td>
73 Additional file<sup><span style="color:red">*</span></sup>:
73 Additional file<sup><span style="color:red">*</span></sup>:
74 </td>
74 </td>
75 <td>
75 <td>
76 <%= f.file_field :additional_file %>
76 <%= f.file_field :additional_file %>
77 </td>
77 </td>
78 <td>
78 <td>
79 <small>
79 <small>
80 * This option works <u>only</u> for task max.
80 * This option works <u>only</u> for task max.
81 You can use this to submit <tt>questions.txt</tt>.<br/>
81 You can use this to submit <tt>questions.txt</tt>.<br/>
82 The file shall be copied to the execution directory before your program runs.
82 The file shall be copied to the execution directory before your program runs.
83 </small>
83 </small>
84 </td>
84 </td>
85 </tr>
85 </tr>
86 <tr>
86 <tr>
87 <td colspan="2">
87 <td colspan="2">
88 <%= submit_tag 'submit' %>
88 <%= submit_tag 'submit' %>
89 </td>
89 </td>
90 </tr>
90 </tr>
91 </table>
91 </table>
92 <% end %>
92 <% end %>
93 </div>
93 </div>
94 <% end %>
94 <% end %>
95
95
96 <h3>Previous requests</h3>
96 <h3>Previous requests</h3>
97
97
98 <table class="info">
98 <table class="info">
99 <tr class="info-head">
99 <tr class="info-head">
100 <th>at</th>
100 <th>at</th>
101 <th>problem</th>
101 <th>problem</th>
102 <th>sub #</th>
102 <th>sub #</th>
103 <th>status</th>
103 <th>status</th>
104 <th>output (first 2kb)</th>
104 <th>output (first 2kb)</th>
105 <th>compiler message</th>
105 <th>compiler message</th>
106 <th>detail</th>
106 <th>detail</th>
107 </tr>
107 </tr>
108 <%= render :partial => 'test_request', :collection => @test_requests %>
108 <%= render :partial => 'test_request', :collection => @test_requests %>
109 </table>
109 </table>
110
110
111 <% end %>
111 <% end %>
112
112
You need to be logged in to leave comments. Login now