Description:
make report max_score remember user options
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r647:bb242b3ef68d - - 3 files changed: 8 inserted, 6 deleted
@@ -1,151 +1,153 | |||
|
1 | 1 | require 'csv' |
|
2 | 2 | |
|
3 | 3 | class ReportController < ApplicationController |
|
4 | 4 | |
|
5 | 5 | before_filter :authenticate |
|
6 | 6 | |
|
7 | 7 | before_filter :admin_authorization, only: [:login_stat,:submission_stat, :stuck, :cheat_report, :cheat_scruntinize, :show_max_score] |
|
8 | 8 | |
|
9 | 9 | before_filter(only: [:problem_hof]) { |c| |
|
10 | 10 | return false unless authenticate |
|
11 | 11 | |
|
12 | 12 | admin_authorization unless GraderConfiguration["right.user_view_submission"] |
|
13 | 13 | } |
|
14 | 14 | |
|
15 | 15 | def max_score |
|
16 | 16 | end |
|
17 | 17 | |
|
18 | 18 | def current_score |
|
19 | 19 | @problems = Problem.available_problems |
|
20 | 20 | @users = User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
21 | 21 | @scorearray = calculate_max_score(@problems, @users,0,0,true) |
|
22 | 22 | |
|
23 | 23 | #rencer accordingly |
|
24 | 24 | if params[:button] == 'download' then |
|
25 | 25 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
26 | 26 | send_data csv, filename: 'max_score.csv' |
|
27 | 27 | else |
|
28 | 28 | #render template: 'user_admin/user_stat' |
|
29 | 29 | render 'current_score' |
|
30 | 30 | end |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | def show_max_score |
|
34 | 34 | #process parameters |
|
35 | 35 | #problems |
|
36 | 36 | @problems = [] |
|
37 | + if params[:problem_id] | |
|
37 | 38 | params[:problem_id].each do |id| |
|
38 | 39 | next unless id.strip != "" |
|
39 | 40 | pid = Problem.find_by_id(id.to_i) |
|
40 | 41 | @problems << pid if pid |
|
41 | 42 | end |
|
43 | + end | |
|
42 | 44 | |
|
43 | 45 | #users |
|
44 | 46 | @users = if params[:user] == "all" then |
|
45 | 47 | User.includes(:contests).includes(:contest_stat) |
|
46 | 48 | else |
|
47 | 49 | User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
48 | 50 | end |
|
49 | 51 | |
|
50 | 52 | #set up range from param |
|
51 | - since_id = params.fetch(:from_id, 0).to_i | |
|
52 | - until_id = params.fetch(:to_id, 0).to_i | |
|
53 | + @since_id = params.fetch(:from_id, 0).to_i | |
|
54 | + @until_id = params.fetch(:to_id, 0).to_i | |
|
53 | 55 | |
|
54 | 56 | #calculate the routine |
|
55 | - @scorearray = calculate_max_score(@problems, @users,since_id,until_id) | |
|
57 | + @scorearray = calculate_max_score(@problems, @users, @since_id, @until_id) | |
|
56 | 58 | |
|
57 | 59 | #rencer accordingly |
|
58 | 60 | if params[:button] == 'download' then |
|
59 | 61 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
60 | 62 | send_data csv, filename: 'max_score.csv' |
|
61 | 63 | else |
|
62 | 64 | #render template: 'user_admin/user_stat' |
|
63 | 65 | render 'max_score' |
|
64 | 66 | end |
|
65 | 67 | |
|
66 | 68 | end |
|
67 | 69 | |
|
68 | 70 | def score |
|
69 | 71 | if params[:commit] == 'download csv' |
|
70 | 72 | @problems = Problem.all |
|
71 | 73 | else |
|
72 | 74 | @problems = Problem.available_problems |
|
73 | 75 | end |
|
74 | 76 | @users = User.includes(:contests, :contest_stat).where(enabled: true) |
|
75 | 77 | @scorearray = Array.new |
|
76 | 78 | @users.each do |u| |
|
77 | 79 | ustat = Array.new |
|
78 | 80 | ustat[0] = u |
|
79 | 81 | @problems.each do |p| |
|
80 | 82 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
81 | 83 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
82 | 84 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
83 | 85 | else |
|
84 | 86 | ustat << [0,false] |
|
85 | 87 | end |
|
86 | 88 | end |
|
87 | 89 | @scorearray << ustat |
|
88 | 90 | end |
|
89 | 91 | if params[:commit] == 'download csv' then |
|
90 | 92 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
91 | 93 | send_data csv, filename: 'last_score.csv' |
|
92 | 94 | else |
|
93 | 95 | render template: 'user_admin/user_stat' |
|
94 | 96 | end |
|
95 | 97 | |
|
96 | 98 | end |
|
97 | 99 | |
|
98 | 100 | def login_stat |
|
99 | 101 | @logins = Array.new |
|
100 | 102 | |
|
101 | 103 | date_and_time = '%Y-%m-%d %H:%M' |
|
102 | 104 | begin |
|
103 | 105 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
104 | 106 | @since_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
105 | 107 | rescue |
|
106 | 108 | @since_time = DateTime.new(1000,1,1) |
|
107 | 109 | end |
|
108 | 110 | begin |
|
109 | 111 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
110 | 112 | @until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) |
|
111 | 113 | rescue |
|
112 | 114 | @until_time = DateTime.new(3000,1,1) |
|
113 | 115 | end |
|
114 | 116 | |
|
115 | 117 | User.all.each do |user| |
|
116 | 118 | @logins << { id: user.id, |
|
117 | 119 | login: user.login, |
|
118 | 120 | full_name: user.full_name, |
|
119 | 121 | count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
120 | 122 | user.id,@since_time,@until_time) |
|
121 | 123 | .count(:id), |
|
122 | 124 | min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
123 | 125 | user.id,@since_time,@until_time) |
|
124 | 126 | .minimum(:created_at), |
|
125 | 127 | max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
126 | 128 | user.id,@since_time,@until_time) |
|
127 | 129 | .maximum(:created_at), |
|
128 | 130 | ip: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
129 | 131 | user.id,@since_time,@until_time) |
|
130 | 132 | .select(:ip_address).uniq |
|
131 | 133 | |
|
132 | 134 | } |
|
133 | 135 | end |
|
134 | 136 | end |
|
135 | 137 | |
|
136 | 138 | def submission_stat |
|
137 | 139 | |
|
138 | 140 | date_and_time = '%Y-%m-%d %H:%M' |
|
139 | 141 | begin |
|
140 | 142 | @since_time = DateTime.strptime(params[:since_datetime],date_and_time) |
|
141 | 143 | rescue |
|
142 | 144 | @since_time = DateTime.new(1000,1,1) |
|
143 | 145 | end |
|
144 | 146 | begin |
|
145 | 147 | @until_time = DateTime.strptime(params[:until_datetime],date_and_time) |
|
146 | 148 | rescue |
|
147 | 149 | @until_time = DateTime.new(3000,1,1) |
|
148 | 150 | end |
|
149 | 151 | |
|
150 | 152 | @submissions = {} |
|
151 | 153 |
@@ -1,49 +1,49 | |||
|
1 | 1 | %h1 Maximum score |
|
2 | 2 | |
|
3 | 3 | = form_tag report_show_max_score_path |
|
4 | 4 | .row |
|
5 | 5 | .col-md-4 |
|
6 | 6 | .panel.panel-primary |
|
7 | 7 | .panel-heading |
|
8 | 8 | Problems |
|
9 | 9 | .panel-body |
|
10 | 10 | %p |
|
11 | 11 | Select problem(s) that we wish to know the score. |
|
12 | 12 | = label_tag :problem_id, "Problems" |
|
13 | 13 | = select_tag 'problem_id[]', |
|
14 | 14 | options_for_select(Problem.all.collect {|p| ["[#{p.name}] #{p.full_name}", p.id]},params[:problem_id]), |
|
15 | 15 | { class: 'select2 form-control', multiple: "true" } |
|
16 | 16 | .col-md-4 |
|
17 | 17 | .panel.panel-primary |
|
18 | 18 | .panel-heading |
|
19 | 19 | Submission range |
|
20 | 20 | .panel-body |
|
21 | 21 | %p |
|
22 | 22 | Input minimum and maximum range of submission ID that should be included. A blank value for min and max means -1 and infinity, respectively. |
|
23 | 23 | .form-group |
|
24 | 24 | = label_tag :from, "Min" |
|
25 |
- = text_field_tag 'from_id', |
|
|
25 | + = text_field_tag 'from_id', @since_id, class: "form-control" | |
|
26 | 26 | .form-group |
|
27 | 27 | = label_tag :from, "Max" |
|
28 | - = text_field_tag 'to_id', nil, class: "form-control" | |
|
28 | + = text_field_tag 'to_id', @until_id, class: "form-control" | |
|
29 | 29 | .col-md-4 |
|
30 | 30 | .panel.panel-primary |
|
31 | 31 | .panel-heading |
|
32 | 32 | Users |
|
33 | 33 | .panel-body |
|
34 | 34 | .radio |
|
35 | 35 | %label |
|
36 | 36 | = radio_button_tag 'users', 'all', true |
|
37 | 37 | All users |
|
38 | 38 | .radio |
|
39 | 39 | %label |
|
40 | 40 | = radio_button_tag 'users', 'enabled' |
|
41 | 41 | Only enabled users |
|
42 | 42 | .row |
|
43 | 43 | .col-md-12 |
|
44 | 44 | = button_tag 'Show', class: "btn btn-primary btn-large", value: "show" |
|
45 | 45 | = button_tag 'Download CSV', class: "btn btn-primary btn-large", value: "download" |
|
46 | 46 | |
|
47 | 47 | - if @scorearray |
|
48 | 48 | %h2 Result |
|
49 | 49 | =render "score_table" |
@@ -1,2 +1,2 | |||
|
1 | 1 | :plain |
|
2 | - $("body").prepend("<div class=\"alert alert-info\"> Submission #{@submission.id}'s task status has been chaned to \"#{@task.status_str}\" </div>") | |
|
2 | + $("body").prepend("<div class=\"alert alert-info\"> Submission #{@submission.id}'s task status has been changed to \"#{@task.status_str}\". It will be re-judged soon. </div>") |
You need to be logged in to leave comments.
Login now