Description:
fig bugs in login report
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r858:21c0ea2ca2c0 - - 2 files changed: 7 inserted, 6 deleted
@@ -1,264 +1,262 | |||||
|
1 | require 'ipaddr' |
|
1 | require 'ipaddr' |
|
2 | require "securerandom" |
|
2 | require "securerandom" |
|
3 |
|
3 | ||
|
4 | class ApplicationController < ActionController::Base |
|
4 | class ApplicationController < ActionController::Base |
|
5 | protect_from_forgery |
|
5 | protect_from_forgery |
|
6 |
|
6 | ||
|
7 | before_action :current_user |
|
7 | before_action :current_user |
|
8 | before_action :nav_announcement |
|
8 | before_action :nav_announcement |
|
9 | before_action :unique_visitor_id |
|
9 | before_action :unique_visitor_id |
|
10 |
|
10 | ||
|
11 | SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' |
|
11 | SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' |
|
12 | MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login' |
|
12 | MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login' |
|
13 | WHITELIST_IGNORE_CONF_KEY = 'right.whitelist_ignore' |
|
13 | WHITELIST_IGNORE_CONF_KEY = 'right.whitelist_ignore' |
|
14 | WHITELIST_IP_CONF_KEY = 'right.whitelist_ip' |
|
14 | WHITELIST_IP_CONF_KEY = 'right.whitelist_ip' |
|
15 |
|
15 | ||
|
16 | #report and redirect for unauthorized activities |
|
16 | #report and redirect for unauthorized activities |
|
17 | def unauthorized_redirect(notice = 'You are not authorized to view the page you requested') |
|
17 | def unauthorized_redirect(notice = 'You are not authorized to view the page you requested') |
|
18 | flash[:notice] = notice |
|
18 | flash[:notice] = notice |
|
19 | redirect_to login_main_path |
|
19 | redirect_to login_main_path |
|
20 | end |
|
20 | end |
|
21 |
|
21 | ||
|
22 | # Returns the current logged-in user (if any). |
|
22 | # Returns the current logged-in user (if any). |
|
23 | def current_user |
|
23 | def current_user |
|
24 | return nil unless session[:user_id] |
|
24 | return nil unless session[:user_id] |
|
25 | @current_user ||= User.find(session[:user_id]) |
|
25 | @current_user ||= User.find(session[:user_id]) |
|
26 | end |
|
26 | end |
|
27 |
|
27 | ||
|
28 | def nav_announcement |
|
28 | def nav_announcement |
|
29 | @nav_announcement = Announcement.where(on_nav_bar: true) |
|
29 | @nav_announcement = Announcement.where(on_nav_bar: true) |
|
30 | end |
|
30 | end |
|
31 |
|
31 | ||
|
32 | def admin_authorization |
|
32 | def admin_authorization |
|
33 | return false unless check_valid_login |
|
33 | return false unless check_valid_login |
|
34 | user = User.includes(:roles).find(session[:user_id]) |
|
34 | user = User.includes(:roles).find(session[:user_id]) |
|
35 | unless user.admin? |
|
35 | unless user.admin? |
|
36 | unauthorized_redirect |
|
36 | unauthorized_redirect |
|
37 | return false |
|
37 | return false |
|
38 | end |
|
38 | end |
|
39 | return true |
|
39 | return true |
|
40 | end |
|
40 | end |
|
41 |
|
41 | ||
|
42 | #admin always count as every roles |
|
42 | #admin always count as every roles |
|
43 | def role_authorization(roles) |
|
43 | def role_authorization(roles) |
|
44 | return false unless check_valid_login |
|
44 | return false unless check_valid_login |
|
45 | user = User.find(session[:user_id]) |
|
45 | user = User.find(session[:user_id]) |
|
46 | return true if user.admin? |
|
46 | return true if user.admin? |
|
47 | roles.each do |r| |
|
47 | roles.each do |r| |
|
48 | return true if user.has_role?(r) |
|
48 | return true if user.has_role?(r) |
|
49 | end |
|
49 | end |
|
50 | unauthorized_redirect |
|
50 | unauthorized_redirect |
|
51 | end |
|
51 | end |
|
52 |
|
52 | ||
|
53 | def authorization_by_roles(allowed_roles) |
|
53 | def authorization_by_roles(allowed_roles) |
|
54 | return false unless check_valid_login |
|
54 | return false unless check_valid_login |
|
55 | unless @current_user.roles.detect { |role| allowed_roles.member?(role.name) } |
|
55 | unless @current_user.roles.detect { |role| allowed_roles.member?(role.name) } |
|
56 | unauthorized_redirect |
|
56 | unauthorized_redirect |
|
57 | return false |
|
57 | return false |
|
58 | end |
|
58 | end |
|
59 | end |
|
59 | end |
|
60 |
|
60 | ||
|
61 | def testcase_authorization |
|
61 | def testcase_authorization |
|
62 | #admin always has privileged |
|
62 | #admin always has privileged |
|
63 | if @current_user.admin? |
|
63 | if @current_user.admin? |
|
64 | return true |
|
64 | return true |
|
65 | end |
|
65 | end |
|
66 |
|
66 | ||
|
67 | unauthorized_redirect unless GraderConfiguration["right.view_testcase"] |
|
67 | unauthorized_redirect unless GraderConfiguration["right.view_testcase"] |
|
68 | end |
|
68 | end |
|
69 |
|
69 | ||
|
70 | def unique_visitor_id |
|
70 | def unique_visitor_id |
|
71 | unless cookies.encrypted[:uuid] |
|
71 | unless cookies.encrypted[:uuid] |
|
72 | value = SecureRandom.uuid |
|
72 | value = SecureRandom.uuid |
|
73 | cookies.encrypted[:uuid] = { value: value, expires: 20.year } |
|
73 | cookies.encrypted[:uuid] = { value: value, expires: 20.year } |
|
74 | end |
|
74 | end |
|
75 | - puts "encrypt " + cookies.encrypted[:uuid] |
|
||
|
76 | - puts cookies[:uuid] |
|
||
|
77 | end |
|
75 | end |
|
78 |
|
76 | ||
|
79 | protected |
|
77 | protected |
|
80 |
|
78 | ||
|
81 | #redirect to root (and also force logout) |
|
79 | #redirect to root (and also force logout) |
|
82 | #if the user is not logged_in or the system is in "ADMIN ONLY" mode |
|
80 | #if the user is not logged_in or the system is in "ADMIN ONLY" mode |
|
83 | def check_valid_login |
|
81 | def check_valid_login |
|
84 | #check if logged in |
|
82 | #check if logged in |
|
85 | unless session[:user_id] |
|
83 | unless session[:user_id] |
|
86 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
84 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
87 | unauthorized_redirect('You need to login but you cannot log in at this time') |
|
85 | unauthorized_redirect('You need to login but you cannot log in at this time') |
|
88 | else |
|
86 | else |
|
89 | unauthorized_redirect('You need to login') |
|
87 | unauthorized_redirect('You need to login') |
|
90 | end |
|
88 | end |
|
91 | return false |
|
89 | return false |
|
92 | end |
|
90 | end |
|
93 |
|
91 | ||
|
94 | # check if run in single user mode |
|
92 | # check if run in single user mode |
|
95 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
93 | if GraderConfiguration[SINGLE_USER_MODE_CONF_KEY] |
|
96 | if @current_user==nil || (!@current_user.admin?) |
|
94 | if @current_user==nil || (!@current_user.admin?) |
|
97 | unauthorized_redirect('You cannot log in at this time') |
|
95 | unauthorized_redirect('You cannot log in at this time') |
|
98 | return false |
|
96 | return false |
|
99 | end |
|
97 | end |
|
100 | end |
|
98 | end |
|
101 |
|
99 | ||
|
102 | # check if the user is enabled |
|
100 | # check if the user is enabled |
|
103 | unless @current_user.enabled? || @current_user.admin? |
|
101 | unless @current_user.enabled? || @current_user.admin? |
|
104 | unauthorized_redirect 'Your account is disabled' |
|
102 | unauthorized_redirect 'Your account is disabled' |
|
105 | return false |
|
103 | return false |
|
106 | end |
|
104 | end |
|
107 |
|
105 | ||
|
108 | # check if user ip is allowed |
|
106 | # check if user ip is allowed |
|
109 | unless @current_user.admin? || GraderConfiguration[WHITELIST_IGNORE_CONF_KEY] |
|
107 | unless @current_user.admin? || GraderConfiguration[WHITELIST_IGNORE_CONF_KEY] |
|
110 | unless is_request_ip_allowed? |
|
108 | unless is_request_ip_allowed? |
|
111 | unauthorized_redirect 'Your IP is not allowed to login at this time.' |
|
109 | unauthorized_redirect 'Your IP is not allowed to login at this time.' |
|
112 | return false |
|
110 | return false |
|
113 | end |
|
111 | end |
|
114 | end |
|
112 | end |
|
115 |
|
113 | ||
|
116 | if GraderConfiguration.multicontests? |
|
114 | if GraderConfiguration.multicontests? |
|
117 | return true if @current_user.admin? |
|
115 | return true if @current_user.admin? |
|
118 | begin |
|
116 | begin |
|
119 | if @current_user.contest_stat(true).forced_logout |
|
117 | if @current_user.contest_stat(true).forced_logout |
|
120 | flash[:notice] = 'You have been automatically logged out.' |
|
118 | flash[:notice] = 'You have been automatically logged out.' |
|
121 | redirect_to :controller => 'main', :action => 'index' |
|
119 | redirect_to :controller => 'main', :action => 'index' |
|
122 | end |
|
120 | end |
|
123 | rescue |
|
121 | rescue |
|
124 | end |
|
122 | end |
|
125 | end |
|
123 | end |
|
126 | return true |
|
124 | return true |
|
127 | end |
|
125 | end |
|
128 |
|
126 | ||
|
129 | #redirect to root (and also force logout) |
|
127 | #redirect to root (and also force logout) |
|
130 | #if the user use different ip from the previous connection |
|
128 | #if the user use different ip from the previous connection |
|
131 | # only applicable when MULTIPLE_IP_LOGIN options is false only |
|
129 | # only applicable when MULTIPLE_IP_LOGIN options is false only |
|
132 | def authenticate_by_ip_address |
|
130 | def authenticate_by_ip_address |
|
133 | #this assume that we have already authenticate normally |
|
131 | #this assume that we have already authenticate normally |
|
134 | unless GraderConfiguration[MULTIPLE_IP_LOGIN_CONF_KEY] |
|
132 | unless GraderConfiguration[MULTIPLE_IP_LOGIN_CONF_KEY] |
|
135 | user = User.find(session[:user_id]) |
|
133 | user = User.find(session[:user_id]) |
|
136 | if (!user.admin? && user.last_ip && user.last_ip != request.remote_ip) |
|
134 | if (!user.admin? && user.last_ip && user.last_ip != request.remote_ip) |
|
137 | flash[:notice] = "You cannot use the system from #{request.remote_ip}. Your last ip is #{user.last_ip}" |
|
135 | flash[:notice] = "You cannot use the system from #{request.remote_ip}. Your last ip is #{user.last_ip}" |
|
138 | redirect_to :controller => 'main', :action => 'login' |
|
136 | redirect_to :controller => 'main', :action => 'login' |
|
139 | return false |
|
137 | return false |
|
140 | end |
|
138 | end |
|
141 | unless user.last_ip |
|
139 | unless user.last_ip |
|
142 | user.last_ip = request.remote_ip |
|
140 | user.last_ip = request.remote_ip |
|
143 | user.save |
|
141 | user.save |
|
144 | end |
|
142 | end |
|
145 | end |
|
143 | end |
|
146 | return true |
|
144 | return true |
|
147 | end |
|
145 | end |
|
148 |
|
146 | ||
|
149 | def authorization |
|
147 | def authorization |
|
150 | return false unless check_valid_login |
|
148 | return false unless check_valid_login |
|
151 | user = User.find(session[:user_id]) |
|
149 | user = User.find(session[:user_id]) |
|
152 | unless user.roles.detect { |role| |
|
150 | unless user.roles.detect { |role| |
|
153 | role.rights.detect{ |right| |
|
151 | role.rights.detect{ |right| |
|
154 | right.controller == self.class.controller_name and |
|
152 | right.controller == self.class.controller_name and |
|
155 | (right.action == 'all' || right.action == action_name) |
|
153 | (right.action == 'all' || right.action == action_name) |
|
156 | } |
|
154 | } |
|
157 | } |
|
155 | } |
|
158 | flash[:notice] = 'You are not authorized to view the page you requested' |
|
156 | flash[:notice] = 'You are not authorized to view the page you requested' |
|
159 | #request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login') |
|
157 | #request.env['HTTP_REFERER'] ? (redirect_to :back) : (redirect_to :controller => 'login') |
|
160 | redirect_to :controller => 'main', :action => 'login' |
|
158 | redirect_to :controller => 'main', :action => 'login' |
|
161 | return false |
|
159 | return false |
|
162 | end |
|
160 | end |
|
163 | end |
|
161 | end |
|
164 |
|
162 | ||
|
165 | def verify_time_limit |
|
163 | def verify_time_limit |
|
166 | return true if session[:user_id]==nil |
|
164 | return true if session[:user_id]==nil |
|
167 | user = User.find(session[:user_id], :include => :site) |
|
165 | user = User.find(session[:user_id], :include => :site) |
|
168 | return true if user==nil || user.site == nil |
|
166 | return true if user==nil || user.site == nil |
|
169 | if user.contest_finished? |
|
167 | if user.contest_finished? |
|
170 | flash[:notice] = 'Error: the contest you are participating is over.' |
|
168 | flash[:notice] = 'Error: the contest you are participating is over.' |
|
171 | redirect_to :back |
|
169 | redirect_to :back |
|
172 | return false |
|
170 | return false |
|
173 | end |
|
171 | end |
|
174 | return true |
|
172 | return true |
|
175 | end |
|
173 | end |
|
176 |
|
174 | ||
|
177 | def is_request_ip_allowed? |
|
175 | def is_request_ip_allowed? |
|
178 | unless GraderConfiguration[WHITELIST_IGNORE_CONF_KEY] |
|
176 | unless GraderConfiguration[WHITELIST_IGNORE_CONF_KEY] |
|
179 | user_ip = IPAddr.new(request.remote_ip) |
|
177 | user_ip = IPAddr.new(request.remote_ip) |
|
180 | allowed = GraderConfiguration[WHITELIST_IP_CONF_KEY] || '' |
|
178 | allowed = GraderConfiguration[WHITELIST_IP_CONF_KEY] || '' |
|
181 |
|
179 | ||
|
182 | allowed.delete(' ').split(',').each do |ips| |
|
180 | allowed.delete(' ').split(',').each do |ips| |
|
183 | allow_ips = IPAddr.new(ips) |
|
181 | allow_ips = IPAddr.new(ips) |
|
184 | if allow_ips.include?(user_ip) |
|
182 | if allow_ips.include?(user_ip) |
|
185 | return true |
|
183 | return true |
|
186 | end |
|
184 | end |
|
187 | end |
|
185 | end |
|
188 | return false |
|
186 | return false |
|
189 | end |
|
187 | end |
|
190 | return true |
|
188 | return true |
|
191 | end |
|
189 | end |
|
192 |
|
190 | ||
|
193 | #function for datatable ajax query |
|
191 | #function for datatable ajax query |
|
194 | #return record,total_count,filter_count |
|
192 | #return record,total_count,filter_count |
|
195 | def process_query_record(record, |
|
193 | def process_query_record(record, |
|
196 | total_count: nil, |
|
194 | total_count: nil, |
|
197 | select: '', |
|
195 | select: '', |
|
198 | global_search: [], |
|
196 | global_search: [], |
|
199 | no_search: false, |
|
197 | no_search: false, |
|
200 | force_order: '', |
|
198 | force_order: '', |
|
201 | date_filter: '', date_param_since: 'date_since',date_param_until: 'date_until', |
|
199 | date_filter: '', date_param_since: 'date_since',date_param_until: 'date_until', |
|
202 | hard_limit: nil) |
|
200 | hard_limit: nil) |
|
203 | arel_table = record.model.arel_table |
|
201 | arel_table = record.model.arel_table |
|
204 |
|
202 | ||
|
205 | if !no_search && params['search'] |
|
203 | if !no_search && params['search'] |
|
206 | global_value = record.model.sanitize_sql(params['search']['value'].strip.downcase) |
|
204 | global_value = record.model.sanitize_sql(params['search']['value'].strip.downcase) |
|
207 | if !global_value.blank? |
|
205 | if !global_value.blank? |
|
208 | global_value.split.each do |value| |
|
206 | global_value.split.each do |value| |
|
209 | global_where = global_search.map{|f| "LOWER(#{f}) like '%#{value}%'"}.join(' OR ') |
|
207 | global_where = global_search.map{|f| "LOWER(#{f}) like '%#{value}%'"}.join(' OR ') |
|
210 | record = record.where(global_where) |
|
208 | record = record.where(global_where) |
|
211 | end |
|
209 | end |
|
212 | end |
|
210 | end |
|
213 |
|
211 | ||
|
214 | params['columns'].each do |i, col| |
|
212 | params['columns'].each do |i, col| |
|
215 | if !col['search']['value'].blank? |
|
213 | if !col['search']['value'].blank? |
|
216 | record = record.where(arel_table[col['name']].lower.matches("%#{col['search']['value'].strip.downcase}%")) |
|
214 | record = record.where(arel_table[col['name']].lower.matches("%#{col['search']['value'].strip.downcase}%")) |
|
217 | end |
|
215 | end |
|
218 | end |
|
216 | end |
|
219 | end |
|
217 | end |
|
220 |
|
218 | ||
|
221 | if !date_filter.blank? |
|
219 | if !date_filter.blank? |
|
222 | param_since = params[date_param_since] |
|
220 | param_since = params[date_param_since] |
|
223 | param_until = params[date_param_until] |
|
221 | param_until = params[date_param_until] |
|
224 | date_since = Time.zone.parse( param_since ) || Time.new(1,1,1) rescue Time.new(1,1,1) |
|
222 | date_since = Time.zone.parse( param_since ) || Time.new(1,1,1) rescue Time.new(1,1,1) |
|
225 | date_until = Time.zone.parse( param_until ) || Time.zone.now() rescue Time.zone.now() |
|
223 | date_until = Time.zone.parse( param_until ) || Time.zone.now() rescue Time.zone.now() |
|
226 | date_range = date_since..(date_until.end_of_day) |
|
224 | date_range = date_since..(date_until.end_of_day) |
|
227 | record = record.where(date_filter.to_sym => date_range) |
|
225 | record = record.where(date_filter.to_sym => date_range) |
|
228 | end |
|
226 | end |
|
229 |
|
227 | ||
|
230 | if force_order.blank? |
|
228 | if force_order.blank? |
|
231 | if params['order'] |
|
229 | if params['order'] |
|
232 | params['order'].each do |i, o| |
|
230 | params['order'].each do |i, o| |
|
233 | colName = params['columns'][o['column']]['name'] |
|
231 | colName = params['columns'][o['column']]['name'] |
|
234 | colName = "#{record.model.table_name}.#{colName}" if colName.upcase == 'ID' |
|
232 | colName = "#{record.model.table_name}.#{colName}" if colName.upcase == 'ID' |
|
235 | record = record.order("#{colName} #{o['dir'].casecmp('desc') != 0 ? 'ASC' : 'DESC'}") unless colName.blank? |
|
233 | record = record.order("#{colName} #{o['dir'].casecmp('desc') != 0 ? 'ASC' : 'DESC'}") unless colName.blank? |
|
236 | end |
|
234 | end |
|
237 | end |
|
235 | end |
|
238 | else |
|
236 | else |
|
239 | record = record.order(force_order) |
|
237 | record = record.order(force_order) |
|
240 | end |
|
238 | end |
|
241 |
|
239 | ||
|
242 | filterCount = record.count(record.model.primary_key) |
|
240 | filterCount = record.count(record.model.primary_key) |
|
243 | # if .group() is used, filterCount might be like {id_1: count_1, id_2: count_2, ...} |
|
241 | # if .group() is used, filterCount might be like {id_1: count_1, id_2: count_2, ...} |
|
244 | # so we should count the result again.. |
|
242 | # so we should count the result again.. |
|
245 | if filterCount.is_a? Hash |
|
243 | if filterCount.is_a? Hash |
|
246 | filterCount = filterCount.count |
|
244 | filterCount = filterCount.count |
|
247 | end |
|
245 | end |
|
248 |
|
246 | ||
|
249 |
|
247 | ||
|
250 | record = record.offset(params['start'] || 0) |
|
248 | record = record.offset(params['start'] || 0) |
|
251 | record = record.limit(hard_limit) |
|
249 | record = record.limit(hard_limit) |
|
252 | if (params['length']) |
|
250 | if (params['length']) |
|
253 | limit = params['length'].to_i |
|
251 | limit = params['length'].to_i |
|
254 | limit == hard_limit if (hard_limit && hard_limit < limit) |
|
252 | limit == hard_limit if (hard_limit && hard_limit < limit) |
|
255 | record = record.limit(limit) |
|
253 | record = record.limit(limit) |
|
256 | end |
|
254 | end |
|
257 | if (!select.blank?) |
|
255 | if (!select.blank?) |
|
258 | record = record.select(select) |
|
256 | record = record.select(select) |
|
259 | end |
|
257 | end |
|
260 |
|
258 | ||
|
261 | return record, total_count || record.model.count, filterCount |
|
259 | return record, total_count || record.model.count, filterCount |
|
262 | end |
|
260 | end |
|
263 |
|
261 | ||
|
264 | end |
|
262 | end |
@@ -1,357 +1,360 | |||||
|
1 | require 'csv' |
|
1 | require 'csv' |
|
2 |
|
2 | ||
|
3 | class ReportController < ApplicationController |
|
3 | class ReportController < ApplicationController |
|
4 |
|
4 | ||
|
5 | before_action :check_valid_login |
|
5 | before_action :check_valid_login |
|
6 |
|
6 | ||
|
7 | before_action :admin_authorization, only: [:login_stat,:submission, :submission_query, |
|
7 | before_action :admin_authorization, only: [:login_stat,:submission, :submission_query, |
|
8 | :login, :login_detail_query, :login_summary_query, |
|
8 | :login, :login_detail_query, :login_summary_query, |
|
9 | :stuck, :cheat_report, :cheat_scrutinize, :show_max_score, :current_score] |
|
9 | :stuck, :cheat_report, :cheat_scrutinize, :show_max_score, :current_score] |
|
10 |
|
10 | ||
|
11 | before_action(only: [:problem_hof]) { |c| |
|
11 | before_action(only: [:problem_hof]) { |c| |
|
12 | return false unless check_valid_login |
|
12 | return false unless check_valid_login |
|
13 |
|
13 | ||
|
14 | admin_authorization unless GraderConfiguration["right.user_view_submission"] |
|
14 | admin_authorization unless GraderConfiguration["right.user_view_submission"] |
|
15 | } |
|
15 | } |
|
16 |
|
16 | ||
|
17 | def max_score |
|
17 | def max_score |
|
18 | end |
|
18 | end |
|
19 |
|
19 | ||
|
20 | def current_score |
|
20 | def current_score |
|
21 | @problems = Problem.available_problems |
|
21 | @problems = Problem.available_problems |
|
22 | if params[:group_id] && params[:users] == 'group' |
|
22 | if params[:group_id] && params[:users] == 'group' |
|
23 | @group = Group.find(params[:group_id]) |
|
23 | @group = Group.find(params[:group_id]) |
|
24 | @users = @group.users.where(enabled: true) |
|
24 | @users = @group.users.where(enabled: true) |
|
25 | else |
|
25 | else |
|
26 | @users = User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
26 | @users = User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
27 | end |
|
27 | end |
|
28 | @scorearray = calculate_max_score(@problems, @users,0,0,true) |
|
28 | @scorearray = calculate_max_score(@problems, @users,0,0,true) |
|
29 |
|
29 | ||
|
30 | #rencer accordingly |
|
30 | #rencer accordingly |
|
31 | if params[:button] == 'download' then |
|
31 | if params[:button] == 'download' then |
|
32 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
32 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
33 | send_data csv, filename: 'max_score.csv' |
|
33 | send_data csv, filename: 'max_score.csv' |
|
34 | else |
|
34 | else |
|
35 | #render template: 'user_admin/user_stat' |
|
35 | #render template: 'user_admin/user_stat' |
|
36 | render 'current_score' |
|
36 | render 'current_score' |
|
37 | end |
|
37 | end |
|
38 | end |
|
38 | end |
|
39 |
|
39 | ||
|
40 | def show_max_score |
|
40 | def show_max_score |
|
41 | #process parameters |
|
41 | #process parameters |
|
42 | #problems |
|
42 | #problems |
|
43 | @problems = [] |
|
43 | @problems = [] |
|
44 | if params[:problem_id] |
|
44 | if params[:problem_id] |
|
45 | params[:problem_id].each do |id| |
|
45 | params[:problem_id].each do |id| |
|
46 | next unless id.strip != "" |
|
46 | next unless id.strip != "" |
|
47 | pid = Problem.find_by_id(id.to_i) |
|
47 | pid = Problem.find_by_id(id.to_i) |
|
48 | @problems << pid if pid |
|
48 | @problems << pid if pid |
|
49 | end |
|
49 | end |
|
50 | end |
|
50 | end |
|
51 |
|
51 | ||
|
52 | #users |
|
52 | #users |
|
53 | @users = if params[:users] == "group" then |
|
53 | @users = if params[:users] == "group" then |
|
54 | Group.find(params[:group_id]).users.all |
|
54 | Group.find(params[:group_id]).users.all |
|
55 | elsif params[:users] == 'enabled' |
|
55 | elsif params[:users] == 'enabled' |
|
56 | User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
56 | User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
57 | else |
|
57 | else |
|
58 | User.includes(:contests).includes(:contest_stat) |
|
58 | User.includes(:contests).includes(:contest_stat) |
|
59 | end |
|
59 | end |
|
60 |
|
60 | ||
|
61 | #set up range from param |
|
61 | #set up range from param |
|
62 | @since_id = params.fetch(:from_id, 0).to_i |
|
62 | @since_id = params.fetch(:from_id, 0).to_i |
|
63 | @until_id = params.fetch(:to_id, 0).to_i |
|
63 | @until_id = params.fetch(:to_id, 0).to_i |
|
64 | @since_id = nil if @since_id == 0 |
|
64 | @since_id = nil if @since_id == 0 |
|
65 | @until_id = nil if @until_id == 0 |
|
65 | @until_id = nil if @until_id == 0 |
|
66 |
|
66 | ||
|
67 | #calculate the routine |
|
67 | #calculate the routine |
|
68 | @scorearray = calculate_max_score(@problems, @users, @since_id, @until_id) |
|
68 | @scorearray = calculate_max_score(@problems, @users, @since_id, @until_id) |
|
69 |
|
69 | ||
|
70 | #rencer accordingly |
|
70 | #rencer accordingly |
|
71 | if params[:button] == 'download' then |
|
71 | if params[:button] == 'download' then |
|
72 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
72 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
73 | send_data csv, filename: 'max_score.csv' |
|
73 | send_data csv, filename: 'max_score.csv' |
|
74 | else |
|
74 | else |
|
75 | #render template: 'user_admin/user_stat' |
|
75 | #render template: 'user_admin/user_stat' |
|
76 | render 'max_score' |
|
76 | render 'max_score' |
|
77 | end |
|
77 | end |
|
78 |
|
78 | ||
|
79 | end |
|
79 | end |
|
80 |
|
80 | ||
|
81 | def score |
|
81 | def score |
|
82 | if params[:commit] == 'download csv' |
|
82 | if params[:commit] == 'download csv' |
|
83 | @problems = Problem.all |
|
83 | @problems = Problem.all |
|
84 | else |
|
84 | else |
|
85 | @problems = Problem.available_problems |
|
85 | @problems = Problem.available_problems |
|
86 | end |
|
86 | end |
|
87 | @users = User.includes(:contests, :contest_stat).where(enabled: true) |
|
87 | @users = User.includes(:contests, :contest_stat).where(enabled: true) |
|
88 | @scorearray = Array.new |
|
88 | @scorearray = Array.new |
|
89 | @users.each do |u| |
|
89 | @users.each do |u| |
|
90 | ustat = Array.new |
|
90 | ustat = Array.new |
|
91 | ustat[0] = u |
|
91 | ustat[0] = u |
|
92 | @problems.each do |p| |
|
92 | @problems.each do |p| |
|
93 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
93 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
94 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
94 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
95 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
95 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
96 | else |
|
96 | else |
|
97 | ustat << [0,false] |
|
97 | ustat << [0,false] |
|
98 | end |
|
98 | end |
|
99 | end |
|
99 | end |
|
100 | @scorearray << ustat |
|
100 | @scorearray << ustat |
|
101 | end |
|
101 | end |
|
102 | if params[:commit] == 'download csv' then |
|
102 | if params[:commit] == 'download csv' then |
|
103 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
103 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
104 | send_data csv, filename: 'last_score.csv' |
|
104 | send_data csv, filename: 'last_score.csv' |
|
105 | else |
|
105 | else |
|
106 | render template: 'user_admin/user_stat' |
|
106 | render template: 'user_admin/user_stat' |
|
107 | end |
|
107 | end |
|
108 |
|
108 | ||
|
109 | end |
|
109 | end |
|
110 |
|
110 | ||
|
111 | def login |
|
111 | def login |
|
112 | end |
|
112 | end |
|
113 |
|
113 | ||
|
114 | def login_summary_query |
|
114 | def login_summary_query |
|
115 | @users = Array.new |
|
115 | @users = Array.new |
|
116 |
|
116 | ||
|
117 | date_and_time = '%Y-%m-%d %H:%M' |
|
117 | date_and_time = '%Y-%m-%d %H:%M' |
|
118 | begin |
|
118 | begin |
|
119 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
119 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
120 | @since_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
120 | @since_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
121 | rescue |
|
121 | rescue |
|
122 |
- @since_time = |
|
122 | + @since_time = Time.zone.now |
|
123 | end |
|
123 | end |
|
|
124 | + puts @since_time | ||
|
124 | begin |
|
125 | begin |
|
125 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
126 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
126 | @until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
127 | @until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
127 | rescue |
|
128 | rescue |
|
128 | @until_time = DateTime.new(3000,1,1) |
|
129 | @until_time = DateTime.new(3000,1,1) |
|
129 | end |
|
130 | end |
|
130 |
|
131 | ||
|
131 | record = User |
|
132 | record = User |
|
132 | .left_outer_joins(:logins).group('users.id') |
|
133 | .left_outer_joins(:logins).group('users.id') |
|
133 | .where("logins.created_at >= ? AND logins.created_at <= ?",@since_time, @until_time) |
|
134 | .where("logins.created_at >= ? AND logins.created_at <= ?",@since_time, @until_time) |
|
134 | case params[:users] |
|
135 | case params[:users] |
|
135 | when 'enabled' |
|
136 | when 'enabled' |
|
136 | record = record.where(enabled: true) |
|
137 | record = record.where(enabled: true) |
|
137 | when 'group' |
|
138 | when 'group' |
|
138 | record = record.joins(:groups).where(groups: {id: params[:groups]}) if params[:groups] |
|
139 | record = record.joins(:groups).where(groups: {id: params[:groups]}) if params[:groups] |
|
139 | end |
|
140 | end |
|
140 |
|
141 | ||
|
141 | record = record.pluck("users.id,users.login,users.full_name,count(logins.created_at),min(logins.created_at),max(logins.created_at)") |
|
142 | record = record.pluck("users.id,users.login,users.full_name,count(logins.created_at),min(logins.created_at),max(logins.created_at)") |
|
142 | record.each do |user| |
|
143 | record.each do |user| |
|
143 | x = Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
144 | x = Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
144 | user[0],@since_time,@until_time) |
|
145 | user[0],@since_time,@until_time) |
|
145 | .pluck(:ip_address).uniq |
|
146 | .pluck(:ip_address).uniq |
|
|
147 | + puts user[4] | ||
|
|
148 | + puts user[5] | ||
|
146 | @users << { id: user[0], |
|
149 | @users << { id: user[0], |
|
147 | login: user[1], |
|
150 | login: user[1], |
|
148 | full_name: user[2], |
|
151 | full_name: user[2], |
|
149 | count: user[3], |
|
152 | count: user[3], |
|
150 | - min: user[4], |
|
153 | + min: user[4].in_time_zone, |
|
151 | - max: user[5], |
|
154 | + max: user[5].in_time_zone, |
|
152 | ip: x |
|
155 | ip: x |
|
153 | } |
|
156 | } |
|
154 | end |
|
157 | end |
|
155 | end |
|
158 | end |
|
156 |
|
159 | ||
|
157 | def login_detail_query |
|
160 | def login_detail_query |
|
158 | @logins = Array.new |
|
161 | @logins = Array.new |
|
159 |
|
162 | ||
|
160 | date_and_time = '%Y-%m-%d %H:%M' |
|
163 | date_and_time = '%Y-%m-%d %H:%M' |
|
161 | begin |
|
164 | begin |
|
162 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
165 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
163 | @since_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
166 | @since_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
164 | rescue |
|
167 | rescue |
|
165 |
- @since_time = |
|
168 | + @since_time = Time.zone.now |
|
166 | end |
|
169 | end |
|
167 | begin |
|
170 | begin |
|
168 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
171 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
169 | @until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
172 | @until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
170 | rescue |
|
173 | rescue |
|
171 | @until_time = DateTime.new(3000,1,1) |
|
174 | @until_time = DateTime.new(3000,1,1) |
|
172 | end |
|
175 | end |
|
173 |
|
176 | ||
|
174 | @logins = Login.includes(:user).where("logins.created_at >= ? AND logins.created_at <= ?",@since_time, @until_time) |
|
177 | @logins = Login.includes(:user).where("logins.created_at >= ? AND logins.created_at <= ?",@since_time, @until_time) |
|
175 | case params[:users] |
|
178 | case params[:users] |
|
176 | when 'enabled' |
|
179 | when 'enabled' |
|
177 | @logins = @logins.where(users: {enabled: true}) |
|
180 | @logins = @logins.where(users: {enabled: true}) |
|
178 | when 'group' |
|
181 | when 'group' |
|
179 | @logins = @logins.joins(user: :groups).where(user: {groups: {id: params[:groups]}}) if params[:groups] |
|
182 | @logins = @logins.joins(user: :groups).where(user: {groups: {id: params[:groups]}}) if params[:groups] |
|
180 | end |
|
183 | end |
|
181 | end |
|
184 | end |
|
182 |
|
185 | ||
|
183 | def submission |
|
186 | def submission |
|
184 | end |
|
187 | end |
|
185 |
|
188 | ||
|
186 | def submission_query |
|
189 | def submission_query |
|
187 | @submissions = Submission |
|
190 | @submissions = Submission |
|
188 | .includes(:problem).includes(:user).includes(:language) |
|
191 | .includes(:problem).includes(:user).includes(:language) |
|
189 |
|
192 | ||
|
190 | case params[:users] |
|
193 | case params[:users] |
|
191 | when 'enabled' |
|
194 | when 'enabled' |
|
192 | @submissions = @submissions.where(users: {enabled: true}) |
|
195 | @submissions = @submissions.where(users: {enabled: true}) |
|
193 | when 'group' |
|
196 | when 'group' |
|
194 | @submissions = @submissions.joins(user: :groups).where(user: {groups: {id: params[:groups]}}) if params[:groups] |
|
197 | @submissions = @submissions.joins(user: :groups).where(user: {groups: {id: params[:groups]}}) if params[:groups] |
|
195 | end |
|
198 | end |
|
196 |
|
199 | ||
|
197 | case params[:problems] |
|
200 | case params[:problems] |
|
198 | when 'enabled' |
|
201 | when 'enabled' |
|
199 | @submissions = @submissions.where(problems: {available: true}) |
|
202 | @submissions = @submissions.where(problems: {available: true}) |
|
200 | when 'selected' |
|
203 | when 'selected' |
|
201 | @submissions = @submissions.where(problem_id: params[:problem_id]) |
|
204 | @submissions = @submissions.where(problem_id: params[:problem_id]) |
|
202 | end |
|
205 | end |
|
203 |
|
206 | ||
|
204 | #set default |
|
207 | #set default |
|
205 | params[:since_datetime] = Date.today.to_s if params[:since_datetime].blank? |
|
208 | params[:since_datetime] = Date.today.to_s if params[:since_datetime].blank? |
|
206 |
|
209 | ||
|
207 | @submissions, @recordsTotal, @recordsFiltered = process_query_record( @submissions, |
|
210 | @submissions, @recordsTotal, @recordsFiltered = process_query_record( @submissions, |
|
208 | global_search: ['user.login','user.full_name','problem.name','problem.full_name','points'], |
|
211 | global_search: ['user.login','user.full_name','problem.name','problem.full_name','points'], |
|
209 | date_filter: 'submitted_at', |
|
212 | date_filter: 'submitted_at', |
|
210 | date_param_since: 'since_datetime', |
|
213 | date_param_since: 'since_datetime', |
|
211 | date_param_until: 'until_datetime', |
|
214 | date_param_until: 'until_datetime', |
|
212 | hard_limit: 100_000 |
|
215 | hard_limit: 100_000 |
|
213 | ) |
|
216 | ) |
|
214 | end |
|
217 | end |
|
215 |
|
218 | ||
|
216 | def login |
|
219 | def login |
|
217 | end |
|
220 | end |
|
218 |
|
221 | ||
|
219 | def problem_hof |
|
222 | def problem_hof |
|
220 | # gen problem list |
|
223 | # gen problem list |
|
221 | @user = User.find(session[:user_id]) |
|
224 | @user = User.find(session[:user_id]) |
|
222 | @problems = @user.available_problems |
|
225 | @problems = @user.available_problems |
|
223 |
|
226 | ||
|
224 | # get selected problems or the default |
|
227 | # get selected problems or the default |
|
225 | if params[:id] |
|
228 | if params[:id] |
|
226 | begin |
|
229 | begin |
|
227 | @problem = Problem.available.find(params[:id]) |
|
230 | @problem = Problem.available.find(params[:id]) |
|
228 | rescue |
|
231 | rescue |
|
229 | redirect_to action: :problem_hof |
|
232 | redirect_to action: :problem_hof |
|
230 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
233 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
231 | return |
|
234 | return |
|
232 | end |
|
235 | end |
|
233 | end |
|
236 | end |
|
234 |
|
237 | ||
|
235 | return unless @problem |
|
238 | return unless @problem |
|
236 |
|
239 | ||
|
237 | #model submisssion |
|
240 | #model submisssion |
|
238 | @model_subs = Submission.where(problem: @problem,tag: Submission.tags[:model]) |
|
241 | @model_subs = Submission.where(problem: @problem,tag: Submission.tags[:model]) |
|
239 |
|
242 | ||
|
240 |
|
243 | ||
|
241 | #calculate best submission |
|
244 | #calculate best submission |
|
242 | @by_lang = {} #aggregrate by language |
|
245 | @by_lang = {} #aggregrate by language |
|
243 |
|
246 | ||
|
244 | range =65 |
|
247 | range =65 |
|
245 | #@histogram = { data: Array.new(range,0), summary: {} } |
|
248 | #@histogram = { data: Array.new(range,0), summary: {} } |
|
246 | @summary = {count: 0, solve: 0, attempt: 0} |
|
249 | @summary = {count: 0, solve: 0, attempt: 0} |
|
247 | user = Hash.new(0) |
|
250 | user = Hash.new(0) |
|
248 | Submission.where(problem_id: @problem.id).find_each do |sub| |
|
251 | Submission.where(problem_id: @problem.id).find_each do |sub| |
|
249 | #histogram |
|
252 | #histogram |
|
250 | d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 |
|
253 | d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 |
|
251 | #@histogram[:data][d.to_i] += 1 if d < range |
|
254 | #@histogram[:data][d.to_i] += 1 if d < range |
|
252 |
|
255 | ||
|
253 | next unless sub.points |
|
256 | next unless sub.points |
|
254 | @summary[:count] += 1 |
|
257 | @summary[:count] += 1 |
|
255 | user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max |
|
258 | user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max |
|
256 |
|
259 | ||
|
257 | lang = Language.find_by_id(sub.language_id) |
|
260 | lang = Language.find_by_id(sub.language_id) |
|
258 | next unless lang |
|
261 | next unless lang |
|
259 | next unless sub.points >= @problem.full_score |
|
262 | next unless sub.points >= @problem.full_score |
|
260 |
|
263 | ||
|
261 | #initialize |
|
264 | #initialize |
|
262 | unless @by_lang.has_key?(lang.pretty_name) |
|
265 | unless @by_lang.has_key?(lang.pretty_name) |
|
263 | @by_lang[lang.pretty_name] = { |
|
266 | @by_lang[lang.pretty_name] = { |
|
264 | runtime: { avail: false, value: 2**30-1 }, |
|
267 | runtime: { avail: false, value: 2**30-1 }, |
|
265 | memory: { avail: false, value: 2**30-1 }, |
|
268 | memory: { avail: false, value: 2**30-1 }, |
|
266 | length: { avail: false, value: 2**30-1 }, |
|
269 | length: { avail: false, value: 2**30-1 }, |
|
267 | first: { avail: false, value: DateTime.new(3000,1,1) } |
|
270 | first: { avail: false, value: DateTime.new(3000,1,1) } |
|
268 | } |
|
271 | } |
|
269 | end |
|
272 | end |
|
270 |
|
273 | ||
|
271 | if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value] |
|
274 | if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value] |
|
272 | @by_lang[lang.pretty_name][:runtime] = { avail: true, user_id: sub.user_id, value: sub.max_runtime, sub_id: sub.id } |
|
275 | @by_lang[lang.pretty_name][:runtime] = { avail: true, user_id: sub.user_id, value: sub.max_runtime, sub_id: sub.id } |
|
273 | end |
|
276 | end |
|
274 |
|
277 | ||
|
275 | if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value] |
|
278 | if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value] |
|
276 | @by_lang[lang.pretty_name][:memory] = { avail: true, user_id: sub.user_id, value: sub.peak_memory, sub_id: sub.id } |
|
279 | @by_lang[lang.pretty_name][:memory] = { avail: true, user_id: sub.user_id, value: sub.peak_memory, sub_id: sub.id } |
|
277 | end |
|
280 | end |
|
278 |
|
281 | ||
|
279 | if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and sub.user and |
|
282 | if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and sub.user and |
|
280 | !sub.user.admin? |
|
283 | !sub.user.admin? |
|
281 | @by_lang[lang.pretty_name][:first] = { avail: true, user_id: sub.user_id, value: sub.submitted_at, sub_id: sub.id } |
|
284 | @by_lang[lang.pretty_name][:first] = { avail: true, user_id: sub.user_id, value: sub.submitted_at, sub_id: sub.id } |
|
282 | end |
|
285 | end |
|
283 |
|
286 | ||
|
284 | if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length |
|
287 | if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length |
|
285 | @by_lang[lang.pretty_name][:length] = { avail: true, user_id: sub.user_id, value: sub.effective_code_length, sub_id: sub.id } |
|
288 | @by_lang[lang.pretty_name][:length] = { avail: true, user_id: sub.user_id, value: sub.effective_code_length, sub_id: sub.id } |
|
286 | end |
|
289 | end |
|
287 | end |
|
290 | end |
|
288 |
|
291 | ||
|
289 | #process user_id |
|
292 | #process user_id |
|
290 | @by_lang.each do |lang,prop| |
|
293 | @by_lang.each do |lang,prop| |
|
291 | prop.each do |k,v| |
|
294 | prop.each do |k,v| |
|
292 | v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)" |
|
295 | v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)" |
|
293 | end |
|
296 | end |
|
294 | end |
|
297 | end |
|
295 |
|
298 | ||
|
296 | #sum into best |
|
299 | #sum into best |
|
297 | if @by_lang and @by_lang.first |
|
300 | if @by_lang and @by_lang.first |
|
298 | @best = @by_lang.first[1].clone |
|
301 | @best = @by_lang.first[1].clone |
|
299 | @by_lang.each do |lang,prop| |
|
302 | @by_lang.each do |lang,prop| |
|
300 | if @best[:runtime][:value] >= prop[:runtime][:value] |
|
303 | if @best[:runtime][:value] >= prop[:runtime][:value] |
|
301 | @best[:runtime] = prop[:runtime] |
|
304 | @best[:runtime] = prop[:runtime] |
|
302 | @best[:runtime][:lang] = lang |
|
305 | @best[:runtime][:lang] = lang |
|
303 | end |
|
306 | end |
|
304 | if @best[:memory][:value] >= prop[:memory][:value] |
|
307 | if @best[:memory][:value] >= prop[:memory][:value] |
|
305 | @best[:memory] = prop[:memory] |
|
308 | @best[:memory] = prop[:memory] |
|
306 | @best[:memory][:lang] = lang |
|
309 | @best[:memory][:lang] = lang |
|
307 | end |
|
310 | end |
|
308 | if @best[:length][:value] >= prop[:length][:value] |
|
311 | if @best[:length][:value] >= prop[:length][:value] |
|
309 | @best[:length] = prop[:length] |
|
312 | @best[:length] = prop[:length] |
|
310 | @best[:length][:lang] = lang |
|
313 | @best[:length][:lang] = lang |
|
311 | end |
|
314 | end |
|
312 | if @best[:first][:value] >= prop[:first][:value] |
|
315 | if @best[:first][:value] >= prop[:first][:value] |
|
313 | @best[:first] = prop[:first] |
|
316 | @best[:first] = prop[:first] |
|
314 | @best[:first][:lang] = lang |
|
317 | @best[:first][:lang] = lang |
|
315 | end |
|
318 | end |
|
316 | end |
|
319 | end |
|
317 | end |
|
320 | end |
|
318 |
|
321 | ||
|
319 | #@histogram[:summary][:max] = [@histogram[:data].max,1].max |
|
322 | #@histogram[:summary][:max] = [@histogram[:data].max,1].max |
|
320 | @summary[:attempt] = user.count |
|
323 | @summary[:attempt] = user.count |
|
321 | user.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
324 | user.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
322 |
|
325 | ||
|
323 |
|
326 | ||
|
324 | #for new graph |
|
327 | #for new graph |
|
325 | @chart_dataset = @problem.get_jschart_history.to_json.html_safe |
|
328 | @chart_dataset = @problem.get_jschart_history.to_json.html_safe |
|
326 | end |
|
329 | end |
|
327 |
|
330 | ||
|
328 | def stuck #report struggling user,problem |
|
331 | def stuck #report struggling user,problem |
|
329 | # init |
|
332 | # init |
|
330 | user,problem = nil |
|
333 | user,problem = nil |
|
331 | solve = true |
|
334 | solve = true |
|
332 | tries = 0 |
|
335 | tries = 0 |
|
333 | @struggle = Array.new |
|
336 | @struggle = Array.new |
|
334 | record = {} |
|
337 | record = {} |
|
335 | Submission.includes(:problem,:user).order(:problem_id,:user_id).find_each do |sub| |
|
338 | Submission.includes(:problem,:user).order(:problem_id,:user_id).find_each do |sub| |
|
336 | next unless sub.problem and sub.user |
|
339 | next unless sub.problem and sub.user |
|
337 | if user != sub.user_id or problem != sub.problem_id |
|
340 | if user != sub.user_id or problem != sub.problem_id |
|
338 | @struggle << { user: record[:user], problem: record[:problem], tries: tries } unless solve |
|
341 | @struggle << { user: record[:user], problem: record[:problem], tries: tries } unless solve |
|
339 | record = {user: sub.user, problem: sub.problem} |
|
342 | record = {user: sub.user, problem: sub.problem} |
|
340 | user,problem = sub.user_id, sub.problem_id |
|
343 | user,problem = sub.user_id, sub.problem_id |
|
341 | solve = false |
|
344 | solve = false |
|
342 | tries = 0 |
|
345 | tries = 0 |
|
343 | end |
|
346 | end |
|
344 | if sub.points >= sub.problem.full_score |
|
347 | if sub.points >= sub.problem.full_score |
|
345 | solve = true |
|
348 | solve = true |
|
346 | else |
|
349 | else |
|
347 | tries += 1 |
|
350 | tries += 1 |
|
348 | end |
|
351 | end |
|
349 | end |
|
352 | end |
|
350 | @struggle.sort!{|a,b| b[:tries] <=> a[:tries] } |
|
353 | @struggle.sort!{|a,b| b[:tries] <=> a[:tries] } |
|
351 | @struggle = @struggle[0..50] |
|
354 | @struggle = @struggle[0..50] |
|
352 | end |
|
355 | end |
|
353 |
|
356 | ||
|
354 |
|
357 | ||
|
355 | def multiple_login |
|
358 | def multiple_login |
|
356 | #user with multiple IP |
|
359 | #user with multiple IP |
|
357 | raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:login) |
|
360 | raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:login) |
You need to be logged in to leave comments.
Login now