Description:
merge max score from branch algo
Commit status:
[Not Reviewed]
References:
merge java
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r411:05396b121058 - - 9 files changed: 124 inserted, 8 deleted

@@ -0,0 +1,18
1 +
2 + = form_tag({action: :user_stat_max }) do
3 + .submitbox
4 + %table
5 + %tr
6 + %td{colspan: 6, style: 'font-weight: bold'} Query maximum score in submission range
7 + %tr
8 + %td{style: 'width: 120px; font-weight: bold'} Submission ID:
9 + %td{align: 'right'} From date:
10 + %td= text_field_tag 'start_date', params[:start_date]
11 + %td Time:
12 + %td= text_field_tag 'start_time', params[:start_time], style: 'width:40px'
13 + %td= submit_tag 'query'
14 + %tr
15 + %td
16 + %td{colspan: 5} Leave blank date and/or time for no condition
17 + %br/
18 +
@@ -0,0 +1,18
1 +
2 +
3 + = form_tag({action: :user_stat_max }) do
4 + .submitbox
5 + %table
6 + %tr
7 + %td{colspan: 6, style: 'font-weight: bold'} Query maximum score in submission range
8 + %tr
9 + %td{style: 'width: 120px; font-weight: bold'} Submission ID:
10 + %td{align: 'right'} From:
11 + %td= text_field_tag 'since_id', params[:since_id], style: 'width:40px'
12 + %td To:
13 + %td= text_field_tag 'until_id', params[:until_id], style: 'width:40px'
14 + %td= submit_tag 'query'
15 + %tr
16 + %td
17 + %td{colspan: 5} Leave blank for uncondition
18 +
@@ -0,0 +1,44
1 + %h1 User grading results
2 + %h2 Show max scores in submission range
3 +
4 + - if @problem and @problem.errors
5 + =error_messages_for 'problem'
6 +
7 + = render partial: 'submission_range'
8 +
9 + - if @log
10 + %h3 Import log
11 + %pre.import-log
12 + = @log
13 +
14 + %p= link_to '[Show only latest submissions]', controller: :user_admin, action: :user_stat
15 +
16 + %table.info
17 + %thead
18 + %tr.info-head
19 + %th User
20 + %th Name
21 + %th Activated?
22 + %th Logged in
23 + %th Contest(s)
24 + - @problems.each do |p|
25 + %th= p.name
26 + %th Total
27 + %th Passed
28 + %tbody
29 + - @scorearray.each do |sc|
30 + %tr{class: cycle('info-even','info-odd')}
31 + - total,num_passed = 0,0
32 + - sc.each_index do |i|
33 + - if i == 0
34 + %td= sc[i].login
35 + %td= sc[i].full_name
36 + %td= sc[i].activated
37 + %td= sc[i].try(:contest_stat).try(:started_at)!=nil ? 'yes' : 'no'
38 + %td= sc[i].contests.collect {|c| c.name}.join(', ')
39 + - else
40 + %td= sc[i][0]
41 + - total += sc[i][0]
42 + - num_passed += 1 if sc[i][1]
43 + %td= total
44 + %td= num_passed
@@ -108,54 +108,75
108
108
109 def update
109 def update
110 @user = User.find(params[:id])
110 @user = User.find(params[:id])
111 if @user.update_attributes(params[:user])
111 if @user.update_attributes(params[:user])
112 flash[:notice] = 'User was successfully updated.'
112 flash[:notice] = 'User was successfully updated.'
113 redirect_to :action => 'show', :id => @user
113 redirect_to :action => 'show', :id => @user
114 else
114 else
115 render :action => 'edit'
115 render :action => 'edit'
116 end
116 end
117 end
117 end
118
118
119 def destroy
119 def destroy
120 User.find(params[:id]).destroy
120 User.find(params[:id]).destroy
121 redirect_to :action => 'list'
121 redirect_to :action => 'list'
122 end
122 end
123
123
124 def user_stat
124 def user_stat
125 @problems = Problem.find_available_problems
125 @problems = Problem.find_available_problems
126 @users = User.find(:all, :include => [:contests, :contest_stat])
126 @users = User.find(:all, :include => [:contests, :contest_stat])
127 @scorearray = Array.new
127 @scorearray = Array.new
128 @users.each do |u|
128 @users.each do |u|
129 ustat = Array.new
129 ustat = Array.new
130 ustat[0] = u
130 ustat[0] = u
131 @problems.each do |p|
131 @problems.each do |p|
132 - sub = Submission.find_last_by_user_and_problem(u.id,p.id)
132 + sub = Submission.find_last_by_user_and_problem(u.id,p.id)
133 - if (sub!=nil) and (sub.points!=nil)
133 + if (sub!=nil) and (sub.points!=nil)
134 - ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
134 + ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
135 - else
135 + else
136 - ustat << [0,false]
136 + ustat << [0,false]
137 - end
137 + end
138 + end
139 + @scorearray << ustat
140 + end
141 + end
142 +
143 + def user_stat_max
144 + @problems = Problem.find_available_problems
145 + @users = User.find(:all, :include => [:contests, :contest_stat])
146 + @scorearray = Array.new
147 + #set up range from param
148 + since_id = params.fetch(:since_id, 0).to_i
149 + until_id = params.fetch(:until_id, 0).to_i
150 + @users.each do |u|
151 + ustat = Array.new
152 + ustat[0] = u
153 + @problems.each do |p|
154 + max_points = 0
155 + Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
156 + max_points = sub.points if sub and sub.points and (sub.points > max_points)
157 + end
158 + ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
138 end
159 end
139 @scorearray << ustat
160 @scorearray << ustat
140 end
161 end
141 end
162 end
142
163
143 def import
164 def import
144 if params[:file]==''
165 if params[:file]==''
145 flash[:notice] = 'Error importing no file'
166 flash[:notice] = 'Error importing no file'
146 redirect_to :action => 'list' and return
167 redirect_to :action => 'list' and return
147 end
168 end
148 import_from_file(params[:file])
169 import_from_file(params[:file])
149 end
170 end
150
171
151 def random_all_passwords
172 def random_all_passwords
152 users = User.find(:all)
173 users = User.find(:all)
153 @prefix = params[:prefix] || ''
174 @prefix = params[:prefix] || ''
154 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
175 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
155 @changed = false
176 @changed = false
156 if request.request_method == 'POST'
177 if request.request_method == 'POST'
157 @non_admin_users.each do |user|
178 @non_admin_users.each do |user|
158 password = random_password
179 password = random_password
159 user.password = password
180 user.password = password
160 user.password_confirmation = password
181 user.password_confirmation = password
161 user.save
182 user.save
@@ -1,39 +1,40
1 # Methods added to this helper will be available to all templates in the application.
1 # Methods added to this helper will be available to all templates in the application.
2 module ApplicationHelper
2 module ApplicationHelper
3
3
4 def user_header
4 def user_header
5 menu_items = ''
5 menu_items = ''
6 user = User.find(session[:user_id])
6 user = User.find(session[:user_id])
7
7
8 if (user!=nil) and (session[:admin])
8 if (user!=nil) and (session[:admin])
9 # admin menu
9 # admin menu
10 menu_items << "<b>Administrative task:</b> "
10 menu_items << "<b>Administrative task:</b> "
11 append_to menu_items, '[Announcements]', 'announcements', 'index'
11 append_to menu_items, '[Announcements]', 'announcements', 'index'
12 append_to menu_items, '[Msg console]', 'messages', 'console'
12 append_to menu_items, '[Msg console]', 'messages', 'console'
13 append_to menu_items, '[Problems]', 'problems', 'index'
13 append_to menu_items, '[Problems]', 'problems', 'index'
14 append_to menu_items, '[Users]', 'user_admin', 'index'
14 append_to menu_items, '[Users]', 'user_admin', 'index'
15 append_to menu_items, '[Results]', 'user_admin', 'user_stat'
15 append_to menu_items, '[Results]', 'user_admin', 'user_stat'
16 + append_to menu_items, '[Report]', 'report', 'login_stat'
16 append_to menu_items, '[Graders]', 'graders', 'list'
17 append_to menu_items, '[Graders]', 'graders', 'list'
17 append_to menu_items, '[Contests]', 'contest_management', 'index'
18 append_to menu_items, '[Contests]', 'contest_management', 'index'
18 append_to menu_items, '[Sites]', 'sites', 'index'
19 append_to menu_items, '[Sites]', 'sites', 'index'
19 append_to menu_items, '[System config]', 'configurations', 'index'
20 append_to menu_items, '[System config]', 'configurations', 'index'
20 menu_items << "<br/>"
21 menu_items << "<br/>"
21 end
22 end
22
23
23 # main page
24 # main page
24 append_to menu_items, "[#{I18n.t 'menu.main'}]", 'main', 'list'
25 append_to menu_items, "[#{I18n.t 'menu.main'}]", 'main', 'list'
25 append_to menu_items, "[#{I18n.t 'menu.messages'}]", 'messages', 'list'
26 append_to menu_items, "[#{I18n.t 'menu.messages'}]", 'messages', 'list'
26
27
27 if (user!=nil) and (GraderConfiguration.show_tasks_to?(user))
28 if (user!=nil) and (GraderConfiguration.show_tasks_to?(user))
28 append_to menu_items, "[#{I18n.t 'menu.tasks'}]", 'tasks', 'list'
29 append_to menu_items, "[#{I18n.t 'menu.tasks'}]", 'tasks', 'list'
29 append_to menu_items, "[#{I18n.t 'menu.submissions'}]", 'main', 'submission'
30 append_to menu_items, "[#{I18n.t 'menu.submissions'}]", 'main', 'submission'
30 append_to menu_items, "[#{I18n.t 'menu.test'}]", 'test', 'index'
31 append_to menu_items, "[#{I18n.t 'menu.test'}]", 'test', 'index'
31 end
32 end
32 append_to menu_items, "[#{I18n.t 'menu.help'}]", 'main', 'help'
33 append_to menu_items, "[#{I18n.t 'menu.help'}]", 'main', 'help'
33
34
34 if GraderConfiguration['system.user_setting_enabled']
35 if GraderConfiguration['system.user_setting_enabled']
35 append_to menu_items, "[#{I18n.t 'menu.settings'}]", 'users', 'index'
36 append_to menu_items, "[#{I18n.t 'menu.settings'}]", 'users', 'index'
36 end
37 end
37 append_to menu_items, "[#{I18n.t 'menu.log_out'}]", 'main', 'login'
38 append_to menu_items, "[#{I18n.t 'menu.log_out'}]", 'main', 'login'
38
39
39 menu_items.html_safe
40 menu_items.html_safe
@@ -13,48 +13,55
13 validate :must_have_valid_problem
13 validate :must_have_valid_problem
14 validate :must_specify_language
14 validate :must_specify_language
15
15
16 before_save :assign_latest_number_if_new_recond
16 before_save :assign_latest_number_if_new_recond
17
17
18 def self.find_last_by_user_and_problem(user_id, problem_id)
18 def self.find_last_by_user_and_problem(user_id, problem_id)
19 last_sub = find(:first,
19 last_sub = find(:first,
20 :conditions => {:user_id => user_id,
20 :conditions => {:user_id => user_id,
21 :problem_id => problem_id},
21 :problem_id => problem_id},
22 :order => 'number DESC')
22 :order => 'number DESC')
23 return last_sub
23 return last_sub
24 end
24 end
25
25
26 def self.find_all_last_by_problem(problem_id)
26 def self.find_all_last_by_problem(problem_id)
27 # need to put in SQL command, maybe there's a better way
27 # need to put in SQL command, maybe there's a better way
28 Submission.find_by_sql("SELECT * FROM submissions " +
28 Submission.find_by_sql("SELECT * FROM submissions " +
29 "WHERE id = " +
29 "WHERE id = " +
30 "(SELECT MAX(id) FROM submissions AS subs " +
30 "(SELECT MAX(id) FROM submissions AS subs " +
31 "WHERE subs.user_id = submissions.user_id AND " +
31 "WHERE subs.user_id = submissions.user_id AND " +
32 "problem_id = " + problem_id.to_s + " " +
32 "problem_id = " + problem_id.to_s + " " +
33 "GROUP BY user_id) " +
33 "GROUP BY user_id) " +
34 "ORDER BY user_id")
34 "ORDER BY user_id")
35 end
35 end
36
36
37 + def self.find_in_range_by_user_and_problem(user_id, problem_id,since_id,until_id)
38 + records = Submission.where(problem_id: problem_id,user_id: user_id)
39 + records = records.where('id >= ?',since_id) if since_id > 0
40 + records = records.where('id <= ?',until_id) if until_id > 0
41 + records.all
42 + end
43 +
37 def self.find_last_for_all_available_problems(user_id)
44 def self.find_last_for_all_available_problems(user_id)
38 submissions = Array.new
45 submissions = Array.new
39 problems = Problem.find_available_problems
46 problems = Problem.find_available_problems
40 problems.each do |problem|
47 problems.each do |problem|
41 sub = Submission.find_last_by_user_and_problem(user_id, problem.id)
48 sub = Submission.find_last_by_user_and_problem(user_id, problem.id)
42 submissions << sub if sub!=nil
49 submissions << sub if sub!=nil
43 end
50 end
44 submissions
51 submissions
45 end
52 end
46
53
47 def self.find_by_user_problem_number(user_id, problem_id, number)
54 def self.find_by_user_problem_number(user_id, problem_id, number)
48 Submission.find(:first,
55 Submission.find(:first,
49 :conditions => {
56 :conditions => {
50 :user_id => user_id,
57 :user_id => user_id,
51 :problem_id => problem_id,
58 :problem_id => problem_id,
52 :number => number
59 :number => number
53 })
60 })
54 end
61 end
55
62
56 def self.find_all_by_user_problem(user_id, problem_id)
63 def self.find_all_by_user_problem(user_id, problem_id)
57 Submission.find(:all,
64 Submission.find(:all,
58 :conditions => {
65 :conditions => {
59 :user_id => user_id,
66 :user_id => user_id,
60 :problem_id => problem_id,
67 :problem_id => problem_id,
@@ -1,26 +1,28
1 %h1 Login status
1 %h1 Login status
2
2
3
3
4 .task-menu
4 .task-menu
5 Reports
5 Reports
6 %br/
6 %br/
7 = link_to '[Submission]', :action => 'submit_stat'
7 = link_to '[Submission]', :action => 'submit_stat'
8 = link_to '[Login]', :action => 'login_stat'
8 = link_to '[Login]', :action => 'login_stat'
9
9
10 + =render partial: 'date_range'
11 +
10 %table.info
12 %table.info
11 %thead
13 %thead
12 %tr.info-head
14 %tr.info-head
13 %th login
15 %th login
14 %th full name
16 %th full name
15 %th login count
17 %th login count
16 %th earliest
18 %th earliest
17 %th latest
19 %th latest
18 %tbody
20 %tbody
19 - @logins.each do |l|
21 - @logins.each do |l|
20 %tr{class: cycle('info-even','info-odd')}
22 %tr{class: cycle('info-even','info-odd')}
21 %td= l[:login]
23 %td= l[:login]
22 %td= l[:full_name]
24 %td= l[:full_name]
23 %td= l[:count]
25 %td= l[:count]
24 %td= l[:min]
26 %td= l[:min]
25 %td= l[:max]
27 %td= l[:max]
26
28
@@ -1,25 +1,30
1 <h1>User grading results</h1>
1 <h1>User grading results</h1>
2 + <h2>Show scores from latest submission</h2>
3 +
4 + <%= render 'submission_range' %>
5 +
6 + <p>Latest scores</p>
2
7
3 <table class="info">
8 <table class="info">
4 <tr class="info-head">
9 <tr class="info-head">
5 <th>User</th>
10 <th>User</th>
6 <th>Name</th>
11 <th>Name</th>
7 <th>Activated?</th>
12 <th>Activated?</th>
8 <th>Logged in</th>
13 <th>Logged in</th>
9 <th>Contest(s)</th>
14 <th>Contest(s)</th>
10 <% @problems.each do |p| %>
15 <% @problems.each do |p| %>
11 <th><%= p.name %></th>
16 <th><%= p.name %></th>
12 <% end %>
17 <% end %>
13 <th>Total</th>
18 <th>Total</th>
14 <th>Passed</th>
19 <th>Passed</th>
15 </tr>
20 </tr>
16 <% counter = 0 %>
21 <% counter = 0 %>
17 <% @scorearray.each do |sc| %>
22 <% @scorearray.each do |sc| %>
18 <tr class="<%= (counter %2 ==0) ? "info-even" : "info-odd" %>">
23 <tr class="<%= (counter %2 ==0) ? "info-even" : "info-odd" %>">
19 <% total = 0 %>
24 <% total = 0 %>
20 <% num_passed = 0 %>
25 <% num_passed = 0 %>
21 <% sc.each_index do |i| %>
26 <% sc.each_index do |i| %>
22 <% if i==0 %>
27 <% if i==0 %>
23 <td><%= sc[i].login %></td>
28 <td><%= sc[i].login %></td>
24 <td><%= sc[i].full_name %></td>
29 <td><%= sc[i].full_name %></td>
25 <td><%= sc[i].activated %></td>
30 <td><%= sc[i].activated %></td>
@@ -1,34 +1,34
1 CafeGrader::Application.routes.draw do
1 CafeGrader::Application.routes.draw do
2 get "report/login"
2 get "report/login"
3
3
4 - get "logins/list"
5 -
6 resources :contests
4 resources :contests
7
5
8 resources :announcements
6 resources :announcements
9 resources :sites
7 resources :sites
10
8
9 + resources :problems, only: [:show]
10 +
11 # The priority is based upon order of creation:
11 # The priority is based upon order of creation:
12 # first created -> highest priority.
12 # first created -> highest priority.
13
13
14 # Sample of regular route:
14 # Sample of regular route:
15 # match 'products/:id' => 'catalog#view'
15 # match 'products/:id' => 'catalog#view'
16 # Keep in mind you can assign values other than :controller and :action
16 # Keep in mind you can assign values other than :controller and :action
17
17
18 # Sample of named route:
18 # Sample of named route:
19 # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
19 # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
20 # This route can be invoked with purchase_url(:id => product.id)
20 # This route can be invoked with purchase_url(:id => product.id)
21
21
22 # Sample resource route (maps HTTP verbs to controller actions automatically):
22 # Sample resource route (maps HTTP verbs to controller actions automatically):
23 # resources :products
23 # resources :products
24
24
25 # Sample resource route with options:
25 # Sample resource route with options:
26 # resources :products do
26 # resources :products do
27 # member do
27 # member do
28 # get 'short'
28 # get 'short'
29 # post 'toggle'
29 # post 'toggle'
30 # end
30 # end
31 #
31 #
32 # collection do
32 # collection do
33 # get 'sold'
33 # get 'sold'
34 # end
34 # end
You need to be logged in to leave comments. Login now