Description:
add download score as csv
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r449:c1892413ee46 - - 2 files changed: 58 inserted, 1 deleted
@@ -1,14 +1,17 | |||
|
1 | + require 'csv' | |
|
2 | + | |
|
1 | 3 | class UserAdminController < ApplicationController |
|
2 | 4 | |
|
5 | + | |
|
3 | 6 | include MailHelperMethods |
|
4 | 7 | |
|
5 | 8 | before_filter :admin_authorization |
|
6 | 9 | |
|
7 | 10 | # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) |
|
8 | 11 | verify :method => :post, :only => [ :destroy, |
|
9 | 12 | :create, :create_from_list, |
|
10 | 13 | :update, |
|
11 | 14 | :manage_contest, |
|
12 | 15 | :bulk_mail |
|
13 | 16 | ], |
|
14 | 17 | :redirect_to => { :action => :list } |
@@ -113,64 +116,84 | |||
|
113 | 116 | redirect_to :action => 'show', :id => @user |
|
114 | 117 | else |
|
115 | 118 | render :action => 'edit' |
|
116 | 119 | end |
|
117 | 120 | end |
|
118 | 121 | |
|
119 | 122 | def destroy |
|
120 | 123 | User.find(params[:id]).destroy |
|
121 | 124 | redirect_to :action => 'list' |
|
122 | 125 | end |
|
123 | 126 | |
|
124 | 127 | def user_stat |
|
128 | + if params[:commit] == 'download csv' | |
|
129 | + @problems = Problem.all | |
|
130 | + else | |
|
125 | 131 | @problems = Problem.find_available_problems |
|
132 | + end | |
|
126 | 133 | @users = User.find(:all, :include => [:contests, :contest_stat]) |
|
127 | 134 | @scorearray = Array.new |
|
128 | 135 | @users.each do |u| |
|
129 | 136 | ustat = Array.new |
|
130 | 137 | ustat[0] = u |
|
131 | 138 | @problems.each do |p| |
|
132 | 139 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
133 | 140 | if (sub!=nil) and (sub.points!=nil) |
|
134 | 141 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
135 | 142 | else |
|
136 | 143 | ustat << [0,false] |
|
137 | 144 | end |
|
138 | 145 | end |
|
139 | 146 | @scorearray << ustat |
|
140 | 147 | end |
|
148 | + | |
|
149 | + if params[:commit] == 'download csv' then | |
|
150 | + csv = gen_csv_from_scorearray(@scorearray,@problems) | |
|
151 | + send_data csv, filename: 'last_score.csv' | |
|
152 | + else | |
|
153 | + render template: 'user_admin/user_stat' | |
|
154 | + end | |
|
141 | 155 | end |
|
142 | 156 | |
|
143 | 157 | def user_stat_max |
|
158 | + if params[:commit] == 'download csv' | |
|
159 | + @problems = Problem.all | |
|
160 | + else | |
|
144 | 161 | @problems = Problem.find_available_problems |
|
162 | + end | |
|
145 | 163 | @users = User.find(:all, :include => [:contests, :contest_stat]) |
|
146 | 164 | @scorearray = Array.new |
|
147 | 165 | #set up range from param |
|
148 | 166 | since_id = params.fetch(:since_id, 0).to_i |
|
149 | 167 | until_id = params.fetch(:until_id, 0).to_i |
|
150 | 168 | @users.each do |u| |
|
151 | 169 | ustat = Array.new |
|
152 | 170 | ustat[0] = u |
|
153 | 171 | @problems.each do |p| |
|
154 | 172 | max_points = 0 |
|
155 | 173 | Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub| |
|
156 | 174 | max_points = sub.points if sub and sub.points and (sub.points > max_points) |
|
157 | 175 | end |
|
158 | 176 | ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)] |
|
159 | 177 | end |
|
160 | 178 | @scorearray << ustat |
|
161 | 179 | end |
|
162 | 180 | |
|
181 | + if params[:commit] == 'download csv' then | |
|
182 | + csv = gen_csv_from_scorearray(@scorearray,@problems) | |
|
183 | + send_data csv, filename: 'max_score.csv' | |
|
184 | + else | |
|
163 | 185 | render template: 'user_admin/user_stat' |
|
164 | 186 | end |
|
187 | + end | |
|
165 | 188 | |
|
166 | 189 | def import |
|
167 | 190 | if params[:file]=='' |
|
168 | 191 | flash[:notice] = 'Error importing no file' |
|
169 | 192 | redirect_to :action => 'list' and return |
|
170 | 193 | end |
|
171 | 194 | import_from_file(params[:file]) |
|
172 | 195 | end |
|
173 | 196 | |
|
174 | 197 | def random_all_passwords |
|
175 | 198 | users = User.find(:all) |
|
176 | 199 | @prefix = params[:prefix] || '' |
@@ -466,13 +489,44 | |||
|
466 | 489 | if id!='none' |
|
467 | 490 | @contest = Contest.find(id) |
|
468 | 491 | else |
|
469 | 492 | @contest = nil |
|
470 | 493 | end |
|
471 | 494 | if @contest |
|
472 | 495 | @users = @contest.users |
|
473 | 496 | else |
|
474 | 497 | @users = User.find_users_with_no_contest |
|
475 | 498 | end |
|
476 | 499 | return [@contest, @users] |
|
477 | 500 | end |
|
501 | + | |
|
502 | + def gen_csv_from_scorearray(scorearray,problem) | |
|
503 | + CSV.generate do |csv| | |
|
504 | + #add header | |
|
505 | + header = ['User','Name', 'Activated?', 'Logged in', 'Contest'] | |
|
506 | + problem.each { |p| header << p.name } | |
|
507 | + header += ['Total','Passed'] | |
|
508 | + csv << header | |
|
509 | + #add data | |
|
510 | + scorearray.each do |sc| | |
|
511 | + total = num_passed = 0 | |
|
512 | + row = Array.new | |
|
513 | + sc.each_index do |i| | |
|
514 | + if i == 0 | |
|
515 | + row << sc[i].login | |
|
516 | + row << sc[i].full_name | |
|
517 | + row << sc[i].activated | |
|
518 | + row << (sc[i].try(:contest_stat).try(:started_at)!=nil ? 'yes' : 'no') | |
|
519 | + row << sc[i].contests.collect {|c| c.name}.join(', ') | |
|
520 | + else | |
|
521 | + row << sc[i][0] | |
|
522 | + total += sc[i][0] | |
|
523 | + num_passed += 1 if sc[i][1] | |
|
478 | 524 | end |
|
525 | + end | |
|
526 | + row << total | |
|
527 | + row << num_passed | |
|
528 | + csv << row | |
|
529 | + end | |
|
530 | + end | |
|
531 | + end | |
|
532 | + end |
@@ -10,27 +10,30 | |||
|
10 | 10 | }); |
|
11 | 11 | |
|
12 | 12 | %h1 User grading results |
|
13 | 13 | %h2= params[:action] == 'user_stat' ? "Show scores from latest submission" : "Show max scores in submission range" |
|
14 | 14 | |
|
15 | 15 | |
|
16 | 16 | - if @problem and @problem.errors |
|
17 | 17 | =error_messages_for 'problem' |
|
18 | 18 | |
|
19 | 19 | = render partial: 'submission_range' |
|
20 | 20 | |
|
21 | 21 |
- if params[:action] == 'user_stat' |
|
22 |
- |
|
|
22 | + %h3 Latest score | |
|
23 | + = link_to '[download csv with all problems]', controller: :user_admin, action: :user_stat, commit: 'download csv' | |
|
23 | 24 | - else |
|
25 | + %h3 Max score | |
|
24 | 26 | = link_to '[Show only latest submissions]', controller: :user_admin, action: :user_stat |
|
27 | + = link_to '[download csv with all problems]', controller: :user_admin, action: :user_stat_max, commit: 'download csv' | |
|
25 | 28 | |
|
26 | 29 | %table.tablesorter-cafe#my_table |
|
27 | 30 | %thead |
|
28 | 31 | %tr |
|
29 | 32 | %th User |
|
30 | 33 | %th Name |
|
31 | 34 | %th Activated? |
|
32 | 35 | %th Logged in |
|
33 | 36 | %th Contest(s) |
|
34 | 37 | - @problems.each do |p| |
|
35 | 38 | %th= p.name |
|
36 | 39 | %th Total |
You need to be logged in to leave comments.
Login now