Description:
add check for nil problem
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r527:662f5e0a87b8 - - 1 file changed: 1 inserted, 1 deleted
@@ -97,97 +97,97 | |||||
|
97 | user.activated = true |
|
97 | user.activated = true |
|
98 | user.save |
|
98 | user.save |
|
99 |
|
99 | ||
|
100 | if added_random_password |
|
100 | if added_random_password |
|
101 | note << "'#{login}' (+)" |
|
101 | note << "'#{login}' (+)" |
|
102 | else |
|
102 | else |
|
103 | note << login |
|
103 | note << login |
|
104 | end |
|
104 | end |
|
105 | end |
|
105 | end |
|
106 | end |
|
106 | end |
|
107 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
107 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
108 | ' were successfully created. ' + |
|
108 | ' were successfully created. ' + |
|
109 | '( (+) - created with random passwords.)' |
|
109 | '( (+) - created with random passwords.)' |
|
110 | redirect_to :action => 'list' |
|
110 | redirect_to :action => 'list' |
|
111 | end |
|
111 | end |
|
112 |
|
112 | ||
|
113 | def edit |
|
113 | def edit |
|
114 | @user = User.find(params[:id]) |
|
114 | @user = User.find(params[:id]) |
|
115 | end |
|
115 | end |
|
116 |
|
116 | ||
|
117 | def update |
|
117 | def update |
|
118 | @user = User.find(params[:id]) |
|
118 | @user = User.find(params[:id]) |
|
119 | if @user.update_attributes(params[:user]) |
|
119 | if @user.update_attributes(params[:user]) |
|
120 | flash[:notice] = 'User was successfully updated.' |
|
120 | flash[:notice] = 'User was successfully updated.' |
|
121 | redirect_to :action => 'show', :id => @user |
|
121 | redirect_to :action => 'show', :id => @user |
|
122 | else |
|
122 | else |
|
123 | render :action => 'edit' |
|
123 | render :action => 'edit' |
|
124 | end |
|
124 | end |
|
125 | end |
|
125 | end |
|
126 |
|
126 | ||
|
127 | def destroy |
|
127 | def destroy |
|
128 | User.find(params[:id]).destroy |
|
128 | User.find(params[:id]).destroy |
|
129 | redirect_to :action => 'list' |
|
129 | redirect_to :action => 'list' |
|
130 | end |
|
130 | end |
|
131 |
|
131 | ||
|
132 | def user_stat |
|
132 | def user_stat |
|
133 | if params[:commit] == 'download csv' |
|
133 | if params[:commit] == 'download csv' |
|
134 | @problems = Problem.all |
|
134 | @problems = Problem.all |
|
135 | else |
|
135 | else |
|
136 | @problems = Problem.find_available_problems |
|
136 | @problems = Problem.find_available_problems |
|
137 | end |
|
137 | end |
|
138 | @users = User.find(:all, :include => [:contests, :contest_stat]) |
|
138 | @users = User.find(:all, :include => [:contests, :contest_stat]) |
|
139 | @scorearray = Array.new |
|
139 | @scorearray = Array.new |
|
140 | @users.each do |u| |
|
140 | @users.each do |u| |
|
141 | ustat = Array.new |
|
141 | ustat = Array.new |
|
142 | ustat[0] = u |
|
142 | ustat[0] = u |
|
143 | @problems.each do |p| |
|
143 | @problems.each do |p| |
|
144 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
144 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
145 | - if (sub!=nil) and (sub.points!=nil) |
|
145 | + if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
146 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
146 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
147 | else |
|
147 | else |
|
148 | ustat << [0,false] |
|
148 | ustat << [0,false] |
|
149 | end |
|
149 | end |
|
150 | end |
|
150 | end |
|
151 | @scorearray << ustat |
|
151 | @scorearray << ustat |
|
152 | end |
|
152 | end |
|
153 | if params[:commit] == 'download csv' then |
|
153 | if params[:commit] == 'download csv' then |
|
154 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
154 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
155 | send_data csv, filename: 'last_score.csv' |
|
155 | send_data csv, filename: 'last_score.csv' |
|
156 | else |
|
156 | else |
|
157 | render template: 'user_admin/user_stat' |
|
157 | render template: 'user_admin/user_stat' |
|
158 | end |
|
158 | end |
|
159 | end |
|
159 | end |
|
160 |
|
160 | ||
|
161 | def user_stat_max |
|
161 | def user_stat_max |
|
162 | if params[:commit] == 'download csv' |
|
162 | if params[:commit] == 'download csv' |
|
163 | @problems = Problem.all |
|
163 | @problems = Problem.all |
|
164 | else |
|
164 | else |
|
165 | @problems = Problem.find_available_problems |
|
165 | @problems = Problem.find_available_problems |
|
166 | end |
|
166 | end |
|
167 | @users = User.find(:all, :include => [:contests, :contest_stat]) |
|
167 | @users = User.find(:all, :include => [:contests, :contest_stat]) |
|
168 | @scorearray = Array.new |
|
168 | @scorearray = Array.new |
|
169 | #set up range from param |
|
169 | #set up range from param |
|
170 | since_id = params.fetch(:since_id, 0).to_i |
|
170 | since_id = params.fetch(:since_id, 0).to_i |
|
171 | until_id = params.fetch(:until_id, 0).to_i |
|
171 | until_id = params.fetch(:until_id, 0).to_i |
|
172 | @users.each do |u| |
|
172 | @users.each do |u| |
|
173 | ustat = Array.new |
|
173 | ustat = Array.new |
|
174 | ustat[0] = u |
|
174 | ustat[0] = u |
|
175 | @problems.each do |p| |
|
175 | @problems.each do |p| |
|
176 | max_points = 0 |
|
176 | max_points = 0 |
|
177 | Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| |
|
177 | Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| |
|
178 | max_points = sub.points if sub and sub.points and (sub.points > max_points) |
|
178 | max_points = sub.points if sub and sub.points and (sub.points > max_points) |
|
179 | end |
|
179 | end |
|
180 | ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)] |
|
180 | ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)] |
|
181 | end |
|
181 | end |
|
182 | @scorearray << ustat |
|
182 | @scorearray << ustat |
|
183 | end |
|
183 | end |
|
184 |
|
184 | ||
|
185 | if params[:commit] == 'download csv' then |
|
185 | if params[:commit] == 'download csv' then |
|
186 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
186 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
187 | send_data csv, filename: 'max_score.csv' |
|
187 | send_data csv, filename: 'max_score.csv' |
|
188 | else |
|
188 | else |
|
189 | render template: 'user_admin/user_stat' |
|
189 | render template: 'user_admin/user_stat' |
|
190 | end |
|
190 | end |
|
191 | end |
|
191 | end |
|
192 |
|
192 | ||
|
193 | def import |
|
193 | def import |
You need to be logged in to leave comments.
Login now