Description:
fix download score in user_stat not working
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r499:1da8597120e1 - - 1 file changed: 6 inserted, 0 deleted
@@ -57,192 +57,198 | |||
|
57 | 57 | if @user.save |
|
58 | 58 | flash[:notice] = 'User was successfully created.' |
|
59 | 59 | redirect_to :action => 'list' |
|
60 | 60 | else |
|
61 | 61 | render :action => 'new' |
|
62 | 62 | end |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | def create_from_list |
|
66 | 66 | lines = params[:user_list] |
|
67 | 67 | |
|
68 | 68 | note = [] |
|
69 | 69 | |
|
70 | 70 | lines.split("\n").each do |line| |
|
71 | 71 | items = line.chomp.split(',') |
|
72 | 72 | if items.length>=2 |
|
73 | 73 | login = items[0] |
|
74 | 74 | full_name = items[1] |
|
75 | 75 | |
|
76 | 76 | added_random_password = false |
|
77 | 77 | if items.length>=3 |
|
78 | 78 | password = items[2].chomp(" ") |
|
79 | 79 | user_alias = (items.length>=4) ? items[3] : login |
|
80 | 80 | else |
|
81 | 81 | password = random_password |
|
82 | 82 | user_alias = (items.length>=4) ? items[3] : login |
|
83 | 83 | added_random_password = true |
|
84 | 84 | end |
|
85 | 85 | |
|
86 | 86 | user = User.find_by_login(login) |
|
87 | 87 | if (user) |
|
88 | 88 | user.full_name = full_name |
|
89 | 89 | user.password = password |
|
90 | 90 | else |
|
91 | 91 | user = User.new({:login => login, |
|
92 | 92 | :full_name => full_name, |
|
93 | 93 | :password => password, |
|
94 | 94 | :password_confirmation => password, |
|
95 | 95 | :alias => user_alias}) |
|
96 | 96 | end |
|
97 | 97 | user.activated = true |
|
98 | 98 | user.save |
|
99 | 99 | |
|
100 | 100 | if added_random_password |
|
101 | 101 | note << "'#{login}' (+)" |
|
102 | 102 | else |
|
103 | 103 | note << login |
|
104 | 104 | end |
|
105 | 105 | end |
|
106 | 106 | end |
|
107 | 107 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
108 | 108 | ' were successfully created. ' + |
|
109 | 109 | '( (+) - created with random passwords.)' |
|
110 | 110 | redirect_to :action => 'list' |
|
111 | 111 | end |
|
112 | 112 | |
|
113 | 113 | def edit |
|
114 | 114 | @user = User.find(params[:id]) |
|
115 | 115 | end |
|
116 | 116 | |
|
117 | 117 | def update |
|
118 | 118 | @user = User.find(params[:id]) |
|
119 | 119 | if @user.update_attributes(params[:user]) |
|
120 | 120 | flash[:notice] = 'User was successfully updated.' |
|
121 | 121 | redirect_to :action => 'show', :id => @user |
|
122 | 122 | else |
|
123 | 123 | render :action => 'edit' |
|
124 | 124 | end |
|
125 | 125 | end |
|
126 | 126 | |
|
127 | 127 | def destroy |
|
128 | 128 | User.find(params[:id]).destroy |
|
129 | 129 | redirect_to :action => 'list' |
|
130 | 130 | end |
|
131 | 131 | |
|
132 | 132 | def user_stat |
|
133 | 133 | if params[:commit] == 'download csv' |
|
134 | 134 | @problems = Problem.all |
|
135 | 135 | else |
|
136 | 136 | @problems = Problem.find_available_problems |
|
137 | 137 | end |
|
138 | 138 | @users = User.find(:all, :include => [:contests, :contest_stat]) |
|
139 | 139 | @scorearray = Array.new |
|
140 | 140 | @users.each do |u| |
|
141 | 141 | ustat = Array.new |
|
142 | 142 | ustat[0] = u |
|
143 | 143 | @problems.each do |p| |
|
144 | 144 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
145 | 145 | if (sub!=nil) and (sub.points!=nil) |
|
146 | 146 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
147 | 147 | else |
|
148 | 148 | ustat << [0,false] |
|
149 | 149 | end |
|
150 | 150 | end |
|
151 | 151 | @scorearray << ustat |
|
152 | 152 | end |
|
153 | + if params[:commit] == 'download csv' then | |
|
154 | + csv = gen_csv_from_scorearray(@scorearray,@problems) | |
|
155 | + send_data csv, filename: 'last_score.csv' | |
|
156 | + else | |
|
157 | + render template: 'user_admin/user_stat' | |
|
158 | + end | |
|
153 | 159 | end |
|
154 | 160 | |
|
155 | 161 | def user_stat_max |
|
156 | 162 | if params[:commit] == 'download csv' |
|
157 | 163 | @problems = Problem.all |
|
158 | 164 | else |
|
159 | 165 | @problems = Problem.find_available_problems |
|
160 | 166 | end |
|
161 | 167 | @users = User.find(:all, :include => [:contests, :contest_stat]) |
|
162 | 168 | @scorearray = Array.new |
|
163 | 169 | #set up range from param |
|
164 | 170 | since_id = params.fetch(:since_id, 0).to_i |
|
165 | 171 | until_id = params.fetch(:until_id, 0).to_i |
|
166 | 172 | @users.each do |u| |
|
167 | 173 | ustat = Array.new |
|
168 | 174 | ustat[0] = u |
|
169 | 175 | @problems.each do |p| |
|
170 | 176 | max_points = 0 |
|
171 | 177 | Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| |
|
172 | 178 | max_points = sub.points if sub and sub.points and (sub.points > max_points) |
|
173 | 179 | end |
|
174 | 180 | ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)] |
|
175 | 181 | end |
|
176 | 182 | @scorearray << ustat |
|
177 | 183 | end |
|
178 | 184 | |
|
179 | 185 | if params[:commit] == 'download csv' then |
|
180 | 186 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
181 | 187 | send_data csv, filename: 'max_score.csv' |
|
182 | 188 | else |
|
183 | 189 | render template: 'user_admin/user_stat' |
|
184 | 190 | end |
|
185 | 191 | end |
|
186 | 192 | |
|
187 | 193 | def import |
|
188 | 194 | if params[:file]=='' |
|
189 | 195 | flash[:notice] = 'Error importing no file' |
|
190 | 196 | redirect_to :action => 'list' and return |
|
191 | 197 | end |
|
192 | 198 | import_from_file(params[:file]) |
|
193 | 199 | end |
|
194 | 200 | |
|
195 | 201 | def random_all_passwords |
|
196 | 202 | users = User.find(:all) |
|
197 | 203 | @prefix = params[:prefix] || '' |
|
198 | 204 | @non_admin_users = User.find_non_admin_with_prefix(@prefix) |
|
199 | 205 | @changed = false |
|
200 | 206 | if request.request_method == 'POST' |
|
201 | 207 | @non_admin_users.each do |user| |
|
202 | 208 | password = random_password |
|
203 | 209 | user.password = password |
|
204 | 210 | user.password_confirmation = password |
|
205 | 211 | user.save |
|
206 | 212 | end |
|
207 | 213 | @changed = true |
|
208 | 214 | end |
|
209 | 215 | end |
|
210 | 216 | |
|
211 | 217 | # contest management |
|
212 | 218 | |
|
213 | 219 | def contests |
|
214 | 220 | @contest, @users = find_contest_and_user_from_contest_id(params[:id]) |
|
215 | 221 | @contests = Contest.enabled |
|
216 | 222 | end |
|
217 | 223 | |
|
218 | 224 | def assign_from_list |
|
219 | 225 | contest_id = params[:users_contest_id] |
|
220 | 226 | org_contest, users = find_contest_and_user_from_contest_id(contest_id) |
|
221 | 227 | contest = Contest.find(params[:new_contest][:id]) |
|
222 | 228 | if !contest |
|
223 | 229 | flash[:notice] = 'Error: no contest' |
|
224 | 230 | redirect_to :action => 'contests', :id =>contest_id |
|
225 | 231 | end |
|
226 | 232 | |
|
227 | 233 | note = [] |
|
228 | 234 | users.each do |u| |
|
229 | 235 | u.contests = [contest] |
|
230 | 236 | note << u.login |
|
231 | 237 | end |
|
232 | 238 | flash[:notice] = 'User(s) ' + note.join(', ') + |
|
233 | 239 | " were successfully reassigned to #{contest.title}." |
|
234 | 240 | redirect_to :action => 'contests', :id =>contest.id |
|
235 | 241 | end |
|
236 | 242 | |
|
237 | 243 | def add_to_contest |
|
238 | 244 | user = User.find(params[:id]) |
|
239 | 245 | contest = Contest.find(params[:contest_id]) |
|
240 | 246 | if user and contest |
|
241 | 247 | user.contests << contest |
|
242 | 248 | end |
|
243 | 249 | redirect_to :action => 'list' |
|
244 | 250 | end |
|
245 | 251 | |
|
246 | 252 | def remove_from_contest |
|
247 | 253 | user = User.find(params[:id]) |
|
248 | 254 | contest = Contest.find(params[:contest_id]) |
You need to be logged in to leave comments.
Login now