Description:
[web] better user_stat git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@138 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r63:787ae01347a6 - - 2 files changed: 3 inserted, 2 deleted

@@ -31,60 +31,61
31 else
31 else
32 render :action => 'new'
32 render :action => 'new'
33 end
33 end
34 end
34 end
35
35
36 def create_from_list
36 def create_from_list
37 lines = params[:user_list]
37 lines = params[:user_list]
38 lines.split("\n").each do |line|
38 lines.split("\n").each do |line|
39 items = line.split
39 items = line.split
40 if items.length==5
40 if items.length==5
41 user = User.new
41 user = User.new
42 user.login = items[0]
42 user.login = items[0]
43 user.full_name = "#{items[1]} #{items[2]}"
43 user.full_name = "#{items[1]} #{items[2]}"
44 user.alias = items[3]
44 user.alias = items[3]
45 user.password = items[4]
45 user.password = items[4]
46 user.password_confirmation = items[4]
46 user.password_confirmation = items[4]
47 user.save
47 user.save
48 end
48 end
49 end
49 end
50 redirect_to :action => 'list'
50 redirect_to :action => 'list'
51 end
51 end
52
52
53 def edit
53 def edit
54 @user = User.find(params[:id])
54 @user = User.find(params[:id])
55 end
55 end
56
56
57 def update
57 def update
58 @user = User.find(params[:id])
58 @user = User.find(params[:id])
59 if @user.update_attributes(params[:user])
59 if @user.update_attributes(params[:user])
60 flash[:notice] = 'User was successfully updated.'
60 flash[:notice] = 'User was successfully updated.'
61 redirect_to :action => 'show', :id => @user
61 redirect_to :action => 'show', :id => @user
62 else
62 else
63 render :action => 'edit'
63 render :action => 'edit'
64 end
64 end
65 end
65 end
66
66
67 def destroy
67 def destroy
68 User.find(params[:id]).destroy
68 User.find(params[:id]).destroy
69 redirect_to :action => 'list'
69 redirect_to :action => 'list'
70 end
70 end
71
71
72 def user_stat
72 def user_stat
73 @problems = Problem.find_available_problems
73 @problems = Problem.find_available_problems
74 @users = User.find(:all)
74 @users = User.find(:all)
75 @scorearray = Array.new
75 @scorearray = Array.new
76 @users.each do |u|
76 @users.each do |u|
77 ustat = Array.new
77 ustat = Array.new
78 ustat[0] = u.login
78 ustat[0] = u.login
79 + ustat[1] = u.full_name
79 @problems.each do |p|
80 @problems.each do |p|
80 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
81 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
81 if (sub!=nil) and (sub.points!=nil)
82 if (sub!=nil) and (sub.points!=nil)
82 ustat << [sub.points, (sub.points>=p.full_score)]
83 ustat << [sub.points, (sub.points>=p.full_score)]
83 else
84 else
84 ustat << [0,false]
85 ustat << [0,false]
85 end
86 end
86 end
87 end
87 @scorearray << ustat
88 @scorearray << ustat
88 end
89 end
89 end
90 end
90 end
91 end
@@ -1,30 +1,30
1 <h1>User grading results</h1>
1 <h1>User grading results</h1>
2
2
3 <table class="info">
3 <table class="info">
4 - <tr class="info-head"><th>User</th>
4 + <tr class="info-head"><th>User</th><th>Name</th>
5 <% @problems.each do |p| %>
5 <% @problems.each do |p| %>
6 <th><%= p.name %></th>
6 <th><%= p.name %></th>
7 <% end %>
7 <% end %>
8 <th>Total</th>
8 <th>Total</th>
9 <th>Passed</th>
9 <th>Passed</th>
10 </tr>
10 </tr>
11 <% counter = 0 %>
11 <% counter = 0 %>
12 <% @scorearray.each do |sc| %>
12 <% @scorearray.each do |sc| %>
13 <tr class="<%= (counter %2 ==0) ? "info-even" : "info-odd" %>">
13 <tr class="<%= (counter %2 ==0) ? "info-even" : "info-odd" %>">
14 <% total = 0 %>
14 <% total = 0 %>
15 <% num_passed = 0 %>
15 <% num_passed = 0 %>
16 <% sc.each_index do |i| %>
16 <% sc.each_index do |i| %>
17 - <% if i==0 %>
17 + <% if i<=1 %>
18 <td><%= sc[i] %></td>
18 <td><%= sc[i] %></td>
19 <% else %>
19 <% else %>
20 <td><%= sc[i][0] %></td>
20 <td><%= sc[i][0] %></td>
21 <% total += sc[i][0] %>
21 <% total += sc[i][0] %>
22 <% num_passed += 1 if sc[i][1] %>
22 <% num_passed += 1 if sc[i][1] %>
23 <% end %>
23 <% end %>
24 <% end %>
24 <% end %>
25 <td><%= total %></td>
25 <td><%= total %></td>
26 <td><%= num_passed %></td>
26 <td><%= num_passed %></td>
27 </tr>
27 </tr>
28 <% counter += 1 %>
28 <% counter += 1 %>
29 <% end %>
29 <% end %>
30 </table>
30 </table>
You need to be logged in to leave comments. Login now