Description:
add last 20 submissions status
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r461:43d522bf3ca9 - - 2 files changed: 23 inserted, 1 deleted

@@ -1,118 +1,119
1 class GradersController < ApplicationController
1 class GradersController < ApplicationController
2
2
3 before_filter :admin_authorization, except: [ :submission ]
3 before_filter :admin_authorization, except: [ :submission ]
4 before_filter(only: [:submission]) {
4 before_filter(only: [:submission]) {
5 return false unless authenticate
5 return false unless authenticate
6
6
7 if GraderConfiguration["right.user_view_submission"]
7 if GraderConfiguration["right.user_view_submission"]
8 return true;
8 return true;
9 end
9 end
10
10
11 admin_authorization
11 admin_authorization
12 }
12 }
13
13
14 verify :method => :post, :only => ['clear_all',
14 verify :method => :post, :only => ['clear_all',
15 'start_exam',
15 'start_exam',
16 'start_grading',
16 'start_grading',
17 'stop_all',
17 'stop_all',
18 'clear_terminated'],
18 'clear_terminated'],
19 :redirect_to => {:action => 'index'}
19 :redirect_to => {:action => 'index'}
20
20
21 def index
21 def index
22 redirect_to :action => 'list'
22 redirect_to :action => 'list'
23 end
23 end
24
24
25 def list
25 def list
26 @grader_processes = GraderProcess.find_running_graders
26 @grader_processes = GraderProcess.find_running_graders
27 @stalled_processes = GraderProcess.find_stalled_process
27 @stalled_processes = GraderProcess.find_stalled_process
28
28
29 @terminated_processes = GraderProcess.find_terminated_graders
29 @terminated_processes = GraderProcess.find_terminated_graders
30
30
31 @last_task = Task.find(:first,
31 @last_task = Task.find(:first,
32 :order => 'created_at DESC')
32 :order => 'created_at DESC')
33 @last_test_request = TestRequest.find(:first,
33 @last_test_request = TestRequest.find(:first,
34 :order => 'created_at DESC')
34 :order => 'created_at DESC')
35 + @submission = Submission.order("id desc").limit(20)
35 end
36 end
36
37
37 def clear
38 def clear
38 grader_proc = GraderProcess.find(params[:id])
39 grader_proc = GraderProcess.find(params[:id])
39 grader_proc.destroy if grader_proc!=nil
40 grader_proc.destroy if grader_proc!=nil
40 redirect_to :action => 'list'
41 redirect_to :action => 'list'
41 end
42 end
42
43
43 def clear_terminated
44 def clear_terminated
44 GraderProcess.find_terminated_graders.each do |p|
45 GraderProcess.find_terminated_graders.each do |p|
45 p.destroy
46 p.destroy
46 end
47 end
47 redirect_to :action => 'list'
48 redirect_to :action => 'list'
48 end
49 end
49
50
50 def clear_all
51 def clear_all
51 GraderProcess.find(:all).each do |p|
52 GraderProcess.find(:all).each do |p|
52 p.destroy
53 p.destroy
53 end
54 end
54 redirect_to :action => 'list'
55 redirect_to :action => 'list'
55 end
56 end
56
57
57 def view
58 def view
58 if params[:type]=='Task'
59 if params[:type]=='Task'
59 redirect_to :action => 'task', :id => params[:id]
60 redirect_to :action => 'task', :id => params[:id]
60 else
61 else
61 redirect_to :action => 'test_request', :id => params[:id]
62 redirect_to :action => 'test_request', :id => params[:id]
62 end
63 end
63 end
64 end
64
65
65 def test_request
66 def test_request
66 @test_request = TestRequest.find(params[:id])
67 @test_request = TestRequest.find(params[:id])
67 end
68 end
68
69
69 def task
70 def task
70 @task = Task.find(params[:id])
71 @task = Task.find(params[:id])
71 end
72 end
72
73
73 def submission
74 def submission
74 @submission = Submission.find(params[:id])
75 @submission = Submission.find(params[:id])
75 formatter = Rouge::Formatters::HTML.new(css_class: 'highlight', line_numbers: true )
76 formatter = Rouge::Formatters::HTML.new(css_class: 'highlight', line_numbers: true )
76 lexer = case @submission.language.name
77 lexer = case @submission.language.name
77 when "c" then Rouge::Lexers::C.new
78 when "c" then Rouge::Lexers::C.new
78 when "cpp" then Rouge::Lexers::Cpp.new
79 when "cpp" then Rouge::Lexers::Cpp.new
79 when "pas" then Rouge::Lexers::Pas.new
80 when "pas" then Rouge::Lexers::Pas.new
80 when "ruby" then Rouge::Lexers::Ruby.new
81 when "ruby" then Rouge::Lexers::Ruby.new
81 when "python" then Rouge::Lexers::Python.new
82 when "python" then Rouge::Lexers::Python.new
82 when "java" then Rouge::Lexers::Java.new
83 when "java" then Rouge::Lexers::Java.new
83 when "php" then Rouge::Lexers::PHP.new
84 when "php" then Rouge::Lexers::PHP.new
84 end
85 end
85 @formatted_code = formatter.format(lexer.lex(@submission.source))
86 @formatted_code = formatter.format(lexer.lex(@submission.source))
86 @css_style = Rouge::Themes::ThankfulEyes.render(scope: '.highlight')
87 @css_style = Rouge::Themes::ThankfulEyes.render(scope: '.highlight')
87
88
88 end
89 end
89
90
90 # various grader controls
91 # various grader controls
91
92
92 def stop
93 def stop
93 grader_proc = GraderProcess.find(params[:id])
94 grader_proc = GraderProcess.find(params[:id])
94 GraderScript.stop_grader(grader_proc.pid)
95 GraderScript.stop_grader(grader_proc.pid)
95 flash[:notice] = 'Grader stopped. It may not disappear now, but it should disappear shortly.'
96 flash[:notice] = 'Grader stopped. It may not disappear now, but it should disappear shortly.'
96 redirect_to :action => 'list'
97 redirect_to :action => 'list'
97 end
98 end
98
99
99 def stop_all
100 def stop_all
100 GraderScript.stop_graders(GraderProcess.find_running_graders +
101 GraderScript.stop_graders(GraderProcess.find_running_graders +
101 GraderProcess.find_stalled_process)
102 GraderProcess.find_stalled_process)
102 flash[:notice] = 'Graders stopped. They may not disappear now, but they should disappear shortly.'
103 flash[:notice] = 'Graders stopped. They may not disappear now, but they should disappear shortly.'
103 redirect_to :action => 'list'
104 redirect_to :action => 'list'
104 end
105 end
105
106
106 def start_grading
107 def start_grading
107 GraderScript.start_grader('grading')
108 GraderScript.start_grader('grading')
108 flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request'
109 flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request'
109 redirect_to :action => 'list'
110 redirect_to :action => 'list'
110 end
111 end
111
112
112 def start_exam
113 def start_exam
113 GraderScript.start_grader('exam')
114 GraderScript.start_grader('exam')
114 flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request'
115 flash[:notice] = '2 graders in grading env started, one for grading queue tasks, another for grading test request'
115 redirect_to :action => 'list'
116 redirect_to :action => 'list'
116 end
117 end
117
118
118 end
119 end
@@ -1,51 +1,72
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="60"/>
3 <meta http-equiv ="refresh" content="60"/>
4
4
5 %h1 Grader information
5 %h1 Grader information
6
6
7 = link_to '[Refresh]', :action => 'list'
7 = link_to '[Refresh]', :action => 'list'
8 %br/
8 %br/
9
9
10 .submitbox
10 .submitbox
11 .item
11 .item
12 Grader control:
12 Grader control:
13 .item
13 .item
14 = form_for :clear, :url => {:action => 'start_grading'} do |f|
14 = form_for :clear, :url => {:action => 'start_grading'} do |f|
15 = submit_tag 'Start graders in grading env'
15 = submit_tag 'Start graders in grading env'
16 .item
16 .item
17 = form_for :clear, :url => {:action => 'start_exam'} do |f|
17 = form_for :clear, :url => {:action => 'start_exam'} do |f|
18 = submit_tag 'Start graders in exam env'
18 = submit_tag 'Start graders in exam env'
19 .item
19 .item
20 = form_for :clear, :url => {:action => 'stop_all'} do |f|
20 = form_for :clear, :url => {:action => 'stop_all'} do |f|
21 = submit_tag 'Stop all running graders'
21 = submit_tag 'Stop all running graders'
22 .item
22 .item
23 = form_for :clear, :url => {:action => 'clear_all'} do |f|
23 = form_for :clear, :url => {:action => 'clear_all'} do |f|
24 = submit_tag 'Clear all data'
24 = submit_tag 'Clear all data'
25 %br{:style => 'clear:both'}/
25 %br{:style => 'clear:both'}/
26
26
27 + %div{style: 'width:500px; float: left;'}
27 - if @last_task
28 - if @last_task
28 Last task:
29 Last task:
29 = link_to "#{@last_task.id}", :action => 'view', :id => @last_task.id, :type => 'Task'
30 = link_to "#{@last_task.id}", :action => 'view', :id => @last_task.id, :type => 'Task'
30
31
31 %br/
32 %br/
32
33
33 - if @last_test_request
34 - if @last_test_request
34 Last test_request:
35 Last test_request:
35 = link_to "#{@last_test_request.id}", :action => 'view', :id => @last_test_request.id, :type => 'TestRequest'
36 = link_to "#{@last_test_request.id}", :action => 'view', :id => @last_test_request.id, :type => 'TestRequest'
36
37
37 -
38 %h2 Current graders
38 %h2 Current graders
39
39
40 = render :partial => 'grader_list', :locals => {:grader_list => @grader_processes}
40 = render :partial => 'grader_list', :locals => {:grader_list => @grader_processes}
41
41
42 %h2 Stalled graders
42 %h2 Stalled graders
43
43
44 = render :partial => 'grader_list', :locals => {:grader_list => @stalled_processes}
44 = render :partial => 'grader_list', :locals => {:grader_list => @stalled_processes}
45
45
46 %h2 Terminated graders
46 %h2 Terminated graders
47
47
48 = form_for :clear, :url => {:action => 'clear_terminated'} do |f|
48 = form_for :clear, :url => {:action => 'clear_terminated'} do |f|
49 = submit_tag 'Clear data for terminated graders'
49 = submit_tag 'Clear data for terminated graders'
50
50
51 = render :partial => 'grader_list', :locals => {:grader_list => @terminated_processes}
51 = render :partial => 'grader_list', :locals => {:grader_list => @terminated_processes}
52 + %div{}
53 + %h2 Last 20 submissions
54 + %table.graders
55 + %thead
56 + %th ID
57 + %th User
58 + %th Problem
59 + %th Submitted
60 + %th Graded
61 + %th Result
62 + %tbody
63 + - @submission.each do |sub|
64 + %tr.inactive
65 + %td= link_to sub.id, controller: 'graders' ,action: 'submission', id: sub.id
66 + %td= sub.try(:user).try(:full_name)
67 + %td= sub.try(:problem).try(:full_name)
68 + %td= "#{time_ago_in_words(sub.submitted_at)} ago"
69 + %td= "#{time_ago_in_words(sub.graded_at)} ago"
70 + %td= sub.grader_comment
71 +
72 +
You need to be logged in to leave comments. Login now