Description:
add problem stat
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r400:91e21331e6bf - - 3 files changed: 250 inserted, 0 deleted
@@ -0,0 +1,178 | |||
|
1 | + class ReportController < ApplicationController | |
|
2 | + | |
|
3 | + before_filter :admin_authorization, only: [:login_stat,:submission_stat] | |
|
4 | + | |
|
5 | + def login_stat | |
|
6 | + @logins = Array.new | |
|
7 | + | |
|
8 | + date_and_time = '%Y-%m-%d %H:%M' | |
|
9 | + begin | |
|
10 | + @since_time = DateTime.strptime(params[:since_datetime],date_and_time) | |
|
11 | + rescue | |
|
12 | + @since_time = DateTime.new(1000,1,1) | |
|
13 | + end | |
|
14 | + begin | |
|
15 | + @until_time = DateTime.strptime(params[:until_datetime],date_and_time) | |
|
16 | + rescue | |
|
17 | + @until_time = DateTime.new(3000,1,1) | |
|
18 | + end | |
|
19 | + | |
|
20 | + User.all.each do |user| | |
|
21 | + @logins << { login: user.login, | |
|
22 | + full_name: user.full_name, | |
|
23 | + count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", | |
|
24 | + user.id,@since_time,@until_time) | |
|
25 | + .count(:id), | |
|
26 | + min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", | |
|
27 | + user.id,@since_time,@until_time) | |
|
28 | + .minimum(:created_at), | |
|
29 | + max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", | |
|
30 | + user.id,@since_time,@until_time) | |
|
31 | + .maximum(:created_at) | |
|
32 | + } | |
|
33 | + end | |
|
34 | + end | |
|
35 | + | |
|
36 | + def submission_stat | |
|
37 | + | |
|
38 | + date_and_time = '%Y-%m-%d %H:%M' | |
|
39 | + begin | |
|
40 | + @since_time = DateTime.strptime(params[:since_datetime],date_and_time) | |
|
41 | + rescue | |
|
42 | + @since_time = DateTime.new(1000,1,1) | |
|
43 | + end | |
|
44 | + begin | |
|
45 | + @until_time = DateTime.strptime(params[:until_datetime],date_and_time) | |
|
46 | + rescue | |
|
47 | + @until_time = DateTime.new(3000,1,1) | |
|
48 | + end | |
|
49 | + | |
|
50 | + @submissions = {} | |
|
51 | + | |
|
52 | + User.find_each do |user| | |
|
53 | + @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } } | |
|
54 | + end | |
|
55 | + | |
|
56 | + Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s| | |
|
57 | + if @submissions[s.user_id] | |
|
58 | + if not @submissions[s.user_id][:sub].has_key?(s.problem_id) | |
|
59 | + a = nil | |
|
60 | + begin | |
|
61 | + a = Problem.find(s.problem_id) | |
|
62 | + rescue | |
|
63 | + a = nil | |
|
64 | + end | |
|
65 | + @submissions[s.user_id][:sub][s.problem_id] = | |
|
66 | + { prob_name: (a ? a.full_name : '(NULL)'), | |
|
67 | + sub_ids: [s.id] } | |
|
68 | + else | |
|
69 | + @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id | |
|
70 | + end | |
|
71 | + @submissions[s.user_id][:count] += 1 | |
|
72 | + end | |
|
73 | + end | |
|
74 | + end | |
|
75 | + | |
|
76 | + def problem_hof | |
|
77 | + # gen problem list | |
|
78 | + @user = User.find(session[:user_id]) | |
|
79 | + @problems = @user.available_problems | |
|
80 | + | |
|
81 | + # get selected problems or the default | |
|
82 | + if params[:id] | |
|
83 | + begin | |
|
84 | + @problem = Problem.available.find(params[:id]) | |
|
85 | + rescue | |
|
86 | + redirect_to action: :problem_hof | |
|
87 | + flash[:notice] = 'Error: submissions for that problem are not viewable.' | |
|
88 | + return | |
|
89 | + end | |
|
90 | + end | |
|
91 | + | |
|
92 | + if @problem | |
|
93 | + #aggregrate by language | |
|
94 | + @by_lang = {} | |
|
95 | + Submission.where(problem_id: @problem.id).find_each do |sub| | |
|
96 | + lang = Language.find_by_id(sub.language_id) | |
|
97 | + next unless lang | |
|
98 | + next unless sub.points >= @problem.full_score | |
|
99 | + | |
|
100 | + #initialize | |
|
101 | + unless @by_lang.has_key?(lang.pretty_name) | |
|
102 | + @by_lang[lang.pretty_name] = { | |
|
103 | + runtime: { avail: false, value: 2**30-1 }, | |
|
104 | + memory: { avail: false, value: 2**30-1 }, | |
|
105 | + length: { avail: false, value: 2**30-1 }, | |
|
106 | + first: { avail: false, value: DateTime.new(3000,1,1) } | |
|
107 | + } | |
|
108 | + end | |
|
109 | + | |
|
110 | + if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value] | |
|
111 | + @by_lang[lang.pretty_name][:runtime] = { | |
|
112 | + avail: true, | |
|
113 | + user_id: sub.user_id, | |
|
114 | + value: sub.max_runtime, | |
|
115 | + sub_id: sub.id | |
|
116 | + } | |
|
117 | + end | |
|
118 | + | |
|
119 | + if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value] | |
|
120 | + @by_lang[lang.pretty_name][:memory] = { | |
|
121 | + avail: true, | |
|
122 | + user_id: sub.user_id, | |
|
123 | + value: sub.peak_memory, | |
|
124 | + sub_id: sub.id | |
|
125 | + } | |
|
126 | + end | |
|
127 | + | |
|
128 | + if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] | |
|
129 | + @by_lang[lang.pretty_name][:first] = { | |
|
130 | + avail: true, | |
|
131 | + user_id: sub.user_id, | |
|
132 | + value: sub.submitted_at, | |
|
133 | + sub_id: sub.id | |
|
134 | + } | |
|
135 | + end | |
|
136 | + | |
|
137 | + if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length | |
|
138 | + @by_lang[lang.pretty_name][:length] = { | |
|
139 | + avail: true, | |
|
140 | + user_id: sub.user_id, | |
|
141 | + value: sub.effective_code_length, | |
|
142 | + sub_id: sub.id | |
|
143 | + } | |
|
144 | + end | |
|
145 | + end | |
|
146 | + | |
|
147 | + #process user_id | |
|
148 | + @by_lang.each do |lang,prop| | |
|
149 | + prop.each do |k,v| | |
|
150 | + v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).login : "(NULL)" | |
|
151 | + end | |
|
152 | + end | |
|
153 | + | |
|
154 | + #sum into best | |
|
155 | + if @by_lang and @by_lang.first | |
|
156 | + @best = @by_lang.first[1] | |
|
157 | + @by_lang.each do |lang,prop| | |
|
158 | + if @best[:runtime][:value] > prop[:runtime][:value] | |
|
159 | + @best[:runtime] = prop[:runtime] | |
|
160 | + @best[:runtime][:lang] = lang | |
|
161 | + end | |
|
162 | + if @best[:memory][:value] > prop[:memory][:value] | |
|
163 | + @best[:memory] = prop[:memory] | |
|
164 | + @best[:memory][:lang] = lang | |
|
165 | + end | |
|
166 | + if @best[:length][:value] > prop[:length][:value] | |
|
167 | + @best[:length] = prop[:length] | |
|
168 | + @best[:length][:lang] = lang | |
|
169 | + end | |
|
170 | + if @best[:first][:value] > prop[:first][:value] | |
|
171 | + @best[:first] = prop[:first] | |
|
172 | + @best[:first][:lang] = lang | |
|
173 | + end | |
|
174 | + end | |
|
175 | + end | |
|
176 | + end | |
|
177 | + end | |
|
178 | + end |
@@ -0,0 +1,7 | |||
|
1 | + | |
|
2 | + .task-menu | |
|
3 | + Reports | |
|
4 | + %br/ | |
|
5 | + = link_to '[Hall of Fame]', :action => 'problem_hof' | |
|
6 | + = link_to '[Submission]', :action => 'submission_stat' | |
|
7 | + = link_to '[Login]', :action => 'login_stat' |
@@ -0,0 +1,65 | |||
|
1 | + %h1 Tasks Hall of Fame | |
|
2 | + | |
|
3 | + .task-menu | |
|
4 | + Tasks | |
|
5 | + %br/ | |
|
6 | + - @problems.each do |prob| | |
|
7 | + = link_to( "[#{prob.name}]", {id: prob.id}) | |
|
8 | + | |
|
9 | + | |
|
10 | + | |
|
11 | + | |
|
12 | + %h2 Overall | |
|
13 | + | |
|
14 | + - if @best | |
|
15 | + %b Best Runtime: | |
|
16 | + = " by #{@best[:runtime][:user]} with #{@best[:runtime][:value] * 1000} milliseconds at submission " \ | |
|
17 | + = link_to("#" + @best[:runtime][:sub_id].to_s, controller: 'graders', action: 'submission', id:@best[:runtime][:sub_id]) | |
|
18 | + %br/ | |
|
19 | + %b Best Memory Usage: | |
|
20 | + = " by #{@best[:memory][:user]} with #{@best[:memory][:value]} kbytes at submission " | |
|
21 | + = link_to("#" + @best[:memory][:sub_id].to_s, controller: 'graders' , action: 'submission', id:@best[:memory][:sub_id]) | |
|
22 | + %br/ | |
|
23 | + %b Shortest Code: | |
|
24 | + = " by #{@best[:length][:user]} with #{@best[:length][:value]} at submission " | |
|
25 | + = link_to("#" + @best[:length][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:length][:sub_id]) | |
|
26 | + %br/ | |
|
27 | + %b First solver: | |
|
28 | + = " by #{@best[:first][:user]} is the first solver on #{@best[:first][:value]} at submission " | |
|
29 | + = link_to("#" + @best[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:first][:sub_id]) | |
|
30 | + %br/ | |
|
31 | + | |
|
32 | + | |
|
33 | + %p | |
|
34 | + This counts only for submission with 100% score <br/> | |
|
35 | + Right now, java is excluded from memory usage competition. (Because it always uses 2GB memory...) | |
|
36 | + | |
|
37 | + %h2 By language | |
|
38 | + | |
|
39 | + %table.info | |
|
40 | + %thead | |
|
41 | + %tr.info-head | |
|
42 | + %th Language | |
|
43 | + %th Best runtime (ms) | |
|
44 | + %th Best memory (kbytes) | |
|
45 | + %th Shortest Code (bytes) | |
|
46 | + %th First solver | |
|
47 | + %tbody | |
|
48 | + - @by_lang.each do |lang,value| | |
|
49 | + %tr{class: cycle('info-even','info-odd')} | |
|
50 | + %td= lang | |
|
51 | + %td | |
|
52 | + = "#{value[:runtime][:user]} (#{(value[:runtime][:value] * 1000).to_i} @" | |
|
53 | + = "#{link_to("#" + value[:runtime][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:runtime][:sub_id])} )".html_safe | |
|
54 | + %td | |
|
55 | + = "#{value[:memory][:user]} (#{value[:memory][:value]} @" | |
|
56 | + = "#{link_to("#" + value[:memory][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:memory][:sub_id])} )".html_safe | |
|
57 | + %td | |
|
58 | + = "#{value[:length][:user]} (#{value[:length][:value]} @" | |
|
59 | + = "#{link_to("#" + value[:length][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:length][:sub_id])} )".html_safe | |
|
60 | + %td | |
|
61 | + = "#{value[:first][:user]} (#{value[:first][:value]} @" | |
|
62 | + = "#{link_to("#" + value[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:first][:sub_id])} )".html_safe | |
|
63 | + | |
|
64 | + - else | |
|
65 | + %h3 No submissions |
You need to be logged in to leave comments.
Login now