Description:
add feature check maximum score in submission ranges available in the [result] admin menu. A user can enter a range of submissions id and the maximum score per each user,problem among the submission ranges will be reported
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r397:94216ffe57fe - - 3 files changed: 39 inserted, 6 deleted

@@ -108,54 +108,75
108 108
109 109 def update
110 110 @user = User.find(params[:id])
111 111 if @user.update_attributes(params[:user])
112 112 flash[:notice] = 'User was successfully updated.'
113 113 redirect_to :action => 'show', :id => @user
114 114 else
115 115 render :action => 'edit'
116 116 end
117 117 end
118 118
119 119 def destroy
120 120 User.find(params[:id]).destroy
121 121 redirect_to :action => 'list'
122 122 end
123 123
124 124 def user_stat
125 125 @problems = Problem.find_available_problems
126 126 @users = User.find(:all, :include => [:contests, :contest_stat])
127 127 @scorearray = Array.new
128 128 @users.each do |u|
129 129 ustat = Array.new
130 130 ustat[0] = u
131 131 @problems.each do |p|
132 - sub = Submission.find_last_by_user_and_problem(u.id,p.id)
133 - if (sub!=nil) and (sub.points!=nil)
134 - ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
135 - else
136 - ustat << [0,false]
137 - end
132 + sub = Submission.find_last_by_user_and_problem(u.id,p.id)
133 + if (sub!=nil) and (sub.points!=nil)
134 + ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
135 + else
136 + ustat << [0,false]
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 159 end
139 160 @scorearray << ustat
140 161 end
141 162 end
142 163
143 164 def import
144 165 if params[:file]==''
145 166 flash[:notice] = 'Error importing no file'
146 167 redirect_to :action => 'list' and return
147 168 end
148 169 import_from_file(params[:file])
149 170 end
150 171
151 172 def random_all_passwords
152 173 users = User.find(:all)
153 174 @prefix = params[:prefix] || ''
154 175 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
155 176 @changed = false
156 177 if request.request_method == 'POST'
157 178 @non_admin_users.each do |user|
158 179 password = random_password
159 180 user.password = password
160 181 user.password_confirmation = password
161 182 user.save
@@ -13,48 +13,55
13 13 validate :must_have_valid_problem
14 14 validate :must_specify_language
15 15
16 16 before_save :assign_latest_number_if_new_recond
17 17
18 18 def self.find_last_by_user_and_problem(user_id, problem_id)
19 19 last_sub = find(:first,
20 20 :conditions => {:user_id => user_id,
21 21 :problem_id => problem_id},
22 22 :order => 'number DESC')
23 23 return last_sub
24 24 end
25 25
26 26 def self.find_all_last_by_problem(problem_id)
27 27 # need to put in SQL command, maybe there's a better way
28 28 Submission.find_by_sql("SELECT * FROM submissions " +
29 29 "WHERE id = " +
30 30 "(SELECT MAX(id) FROM submissions AS subs " +
31 31 "WHERE subs.user_id = submissions.user_id AND " +
32 32 "problem_id = " + problem_id.to_s + " " +
33 33 "GROUP BY user_id) " +
34 34 "ORDER BY user_id")
35 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 44 def self.find_last_for_all_available_problems(user_id)
38 45 submissions = Array.new
39 46 problems = Problem.find_available_problems
40 47 problems.each do |problem|
41 48 sub = Submission.find_last_by_user_and_problem(user_id, problem.id)
42 49 submissions << sub if sub!=nil
43 50 end
44 51 submissions
45 52 end
46 53
47 54 def self.find_by_user_problem_number(user_id, problem_id, number)
48 55 Submission.find(:first,
49 56 :conditions => {
50 57 :user_id => user_id,
51 58 :problem_id => problem_id,
52 59 :number => number
53 60 })
54 61 end
55 62
56 63 def self.find_all_by_user_problem(user_id, problem_id)
57 64 Submission.find(:all,
58 65 :conditions => {
59 66 :user_id => user_id,
60 67 :problem_id => problem_id,
@@ -1,25 +1,30
1 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 8 <table class="info">
4 9 <tr class="info-head">
5 10 <th>User</th>
6 11 <th>Name</th>
7 12 <th>Activated?</th>
8 13 <th>Logged in</th>
9 14 <th>Contest(s)</th>
10 15 <% @problems.each do |p| %>
11 16 <th><%= p.name %></th>
12 17 <% end %>
13 18 <th>Total</th>
14 19 <th>Passed</th>
15 20 </tr>
16 21 <% counter = 0 %>
17 22 <% @scorearray.each do |sc| %>
18 23 <tr class="<%= (counter %2 ==0) ? "info-even" : "info-odd" %>">
19 24 <% total = 0 %>
20 25 <% num_passed = 0 %>
21 26 <% sc.each_index do |i| %>
22 27 <% if i==0 %>
23 28 <td><%= sc[i].login %></td>
24 29 <td><%= sc[i].full_name %></td>
25 30 <td><%= sc[i].activated %></td>
You need to be logged in to leave comments. Login now