Description:
merge
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r514:41d1cd2793ff - - 11 files changed: 301 inserted, 132 deleted
@@ -0,0 +1,44 | |||
|
1 | + - param = {} unless param | |
|
2 | + - graph_height = param[:graph_height] || 100 | |
|
3 | + - bar_width = param[:bar_width] || 14 | |
|
4 | + - graph_width = (bar_width * histogram[:data].count) + 20 | |
|
5 | + :css | |
|
6 | + .hist_bar { | |
|
7 | + width: #{bar_width-1}px; | |
|
8 | + position: absolute; | |
|
9 | + background-color: lightblue; | |
|
10 | + } | |
|
11 | + .hist_fill { | |
|
12 | + width: #{bar_width-1}px; | |
|
13 | + position: absolute; | |
|
14 | + background-color: #eee; | |
|
15 | + } | |
|
16 | + .hist_text { | |
|
17 | + position: absolute; | |
|
18 | + font-size:5px; | |
|
19 | + } | |
|
20 | + | |
|
21 | + %div{style: "position: relative; width: #{graph_width}px; height: 125px; background-color:#fff;" } | |
|
22 | + //draw background | |
|
23 | + - histogram[:data].each_index do |i| | |
|
24 | + - height = histogram[:data][i] * graph_height / histogram[:summary][:max] | |
|
25 | + - top = graph_height - height | |
|
26 | + - left = graph_width - (i+1)*bar_width | |
|
27 | + %div.hist_fill{style: "top: 0px; height: #{graph_height - height}px; left: #{left}px;" } | |
|
28 | + // draw horizontal line | |
|
29 | + - line = 3 | |
|
30 | + - line.times do |i| | |
|
31 | + - top = graph_height - graph_height * (i+0.5)/ line | |
|
32 | + %div{style: "position:absolute;width: #{graph_width-21}px;height: 1px;left: 20px;top:#{top}px;background-color: #333;"} | |
|
33 | + %div.hist_text{style: "position:absolute;left: 0px;top:#{top-6}px"} | |
|
34 | + =((i+0.5) * histogram[:summary][:max] / line).to_i | |
|
35 | + // draw the actual bar and text | |
|
36 | + - @histogram[:data].each_index do |i| | |
|
37 | + - height = histogram[:data][i] * graph_height / histogram[:summary][:max] | |
|
38 | + - top = graph_height - height | |
|
39 | + - left = graph_width - (i+1)*bar_width | |
|
40 | + %div.hist_bar{style: "top: #{top}px; height: #{height}px; left: #{left}px; dae: #{histogram[:data][i]}" } | |
|
41 | + - if i % 7 == 1 | |
|
42 | + %div.hist_text{style: "top:#{graph_height + 5}px;left: #{left}px;"} #{(Time.zone.today - i.day).strftime('%-d')} | |
|
43 | + - if (Time.now.in_time_zone - i.day).day == 15 | |
|
44 | + %div.hist_text{style: "top:#{graph_height + 15}px;left: #{left}px;"} #{(Time.zone.today - i.day).strftime('%b')} |
@@ -57,204 +57,221 | |||
|
57 | 57 | @problem.full_score = 100 |
|
58 | 58 | @problem.available = false |
|
59 | 59 | @problem.test_allowed = true |
|
60 | 60 | @problem.output_only = false |
|
61 | 61 | @problem.date_added = Time.new |
|
62 | 62 | if @problem.save |
|
63 | 63 | flash[:notice] = 'Problem was successfully created.' |
|
64 | 64 | redirect_to :action => 'list' |
|
65 | 65 | else |
|
66 | 66 | flash[:notice] = 'Error saving problem' |
|
67 | 67 | redirect_to :action => 'list' |
|
68 | 68 | end |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | 71 | def edit |
|
72 | 72 | @problem = Problem.find(params[:id]) |
|
73 | 73 | @description = @problem.description |
|
74 | 74 | end |
|
75 | 75 | |
|
76 | 76 | def update |
|
77 | 77 | @problem = Problem.find(params[:id]) |
|
78 | 78 | @description = @problem.description |
|
79 | 79 | if @description == nil and params[:description][:body]!='' |
|
80 | 80 | @description = Description.new(params[:description]) |
|
81 | 81 | if !@description.save |
|
82 | 82 | flash[:notice] = 'Error saving description' |
|
83 | 83 | render :action => 'edit' and return |
|
84 | 84 | end |
|
85 | 85 | @problem.description = @description |
|
86 | 86 | elsif @description!=nil |
|
87 | 87 | if !@description.update_attributes(params[:description]) |
|
88 | 88 | flash[:notice] = 'Error saving description' |
|
89 | 89 | render :action => 'edit' and return |
|
90 | 90 | end |
|
91 | 91 | end |
|
92 | 92 | if params[:file] and params[:file].content_type != 'application/pdf' |
|
93 | 93 | flash[:notice] = 'Error: Uploaded file is not PDF' |
|
94 | 94 | render :action => 'edit' and return |
|
95 | 95 | end |
|
96 | 96 | if @problem.update_attributes(params[:problem]) |
|
97 | 97 | flash[:notice] = 'Problem was successfully updated.' |
|
98 | 98 | unless params[:file] == nil or params[:file] == '' |
|
99 | 99 | flash[:notice] = 'Problem was successfully updated and a new PDF file is uploaded.' |
|
100 | 100 | out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}" |
|
101 | 101 | if not FileTest.exists? out_dirname |
|
102 | 102 | Dir.mkdir out_dirname |
|
103 | 103 | end |
|
104 | 104 | |
|
105 | 105 | out_filename = "#{out_dirname}/#{@problem.name}.pdf" |
|
106 | 106 | if FileTest.exists? out_filename |
|
107 | 107 | File.delete out_filename |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | File.open(out_filename,"wb") do |file| |
|
111 | 111 | file.write(params[:file].read) |
|
112 | 112 | end |
|
113 | 113 | @problem.description_filename = "#{@problem.name}.pdf" |
|
114 | 114 | @problem.save |
|
115 | 115 | end |
|
116 | 116 | redirect_to :action => 'show', :id => @problem |
|
117 | 117 | else |
|
118 | 118 | render :action => 'edit' |
|
119 | 119 | end |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | def destroy |
|
123 | 123 | Problem.find(params[:id]).destroy |
|
124 | 124 | redirect_to :action => 'list' |
|
125 | 125 | end |
|
126 | 126 | |
|
127 | 127 | def toggle |
|
128 | 128 | @problem = Problem.find(params[:id]) |
|
129 | 129 | @problem.available = !(@problem.available) |
|
130 | 130 | @problem.save |
|
131 | 131 | end |
|
132 | 132 | |
|
133 | 133 | def turn_all_off |
|
134 | 134 | Problem.find(:all, |
|
135 | 135 | :conditions => "available = 1").each do |problem| |
|
136 | 136 | problem.available = false |
|
137 | 137 | problem.save |
|
138 | 138 | end |
|
139 | 139 | redirect_to :action => 'list' |
|
140 | 140 | end |
|
141 | 141 | |
|
142 | 142 | def turn_all_on |
|
143 | 143 | Problem.find(:all, |
|
144 | 144 | :conditions => "available = 0").each do |problem| |
|
145 | 145 | problem.available = true |
|
146 | 146 | problem.save |
|
147 | 147 | end |
|
148 | 148 | redirect_to :action => 'list' |
|
149 | 149 | end |
|
150 | 150 | |
|
151 | 151 | def stat |
|
152 | 152 | @problem = Problem.find(params[:id]) |
|
153 |
- |
|
|
153 | + unless @problem.available or session[:admin] | |
|
154 | 154 | redirect_to :controller => 'main', :action => 'list' |
|
155 | - else | |
|
156 | - @submissions = Submission.includes(:user).where(problem_id: params[:id]).order(:user_id,:id) | |
|
155 | + return | |
|
157 | 156 | end |
|
157 | + @submissions = Submission.includes(:user).where(problem_id: params[:id]).order(:user_id,:id) | |
|
158 | + | |
|
159 | + #stat summary | |
|
160 | + range =65 | |
|
161 | + @histogram = { data: Array.new(range,0), summary: {} } | |
|
162 | + user = Hash.new(0) | |
|
163 | + @submissions.find_each do |sub| | |
|
164 | + d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 | |
|
165 | + @histogram[:data][d.to_i] += 1 if d < range | |
|
166 | + user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max | |
|
167 | + end | |
|
168 | + @histogram[:summary][:max] = [@histogram[:data].max,1].max | |
|
169 | + | |
|
170 | + @summary = { attempt: user.count, solve: 0 } | |
|
171 | + user.each_value { |v| @summary[:solve] += 1 if v == 1 } | |
|
158 | 172 | end |
|
159 | 173 | |
|
160 | 174 | def manage |
|
161 | 175 | @problems = Problem.find(:all, :order => 'date_added DESC') |
|
162 | 176 | end |
|
163 | 177 | |
|
164 | 178 | def do_manage |
|
165 | 179 | if params.has_key? 'change_date_added' |
|
166 | 180 | change_date_added |
|
167 | 181 | elsif params.has_key? 'add_to_contest' |
|
168 | 182 | add_to_contest |
|
169 | 183 | elsif params.has_key? 'enable_problem' |
|
170 | 184 | set_available(true) |
|
171 | 185 | elsif params.has_key? 'disable_problem' |
|
172 | 186 | set_available(false) |
|
173 | 187 | end |
|
174 | 188 | redirect_to :action => 'manage' |
|
175 | 189 | end |
|
176 | 190 | |
|
177 | 191 | def import |
|
178 | 192 | @allow_test_pair_import = allow_test_pair_import? |
|
179 | 193 | end |
|
180 | 194 | |
|
181 | 195 | def do_import |
|
182 | 196 | old_problem = Problem.find_by_name(params[:name]) |
|
183 | 197 | if !allow_test_pair_import? and params.has_key? :import_to_db |
|
184 | 198 | params.delete :import_to_db |
|
185 | 199 | end |
|
186 | 200 | @problem, import_log = Problem.create_from_import_form_params(params, |
|
187 | 201 | old_problem) |
|
188 | 202 | |
|
189 | 203 | if !@problem.errors.empty? |
|
190 | 204 | render :action => 'import' and return |
|
191 | 205 | end |
|
192 | 206 | |
|
193 | 207 | if old_problem!=nil |
|
194 | 208 | flash[:notice] = "The test data has been replaced for problem #{@problem.name}" |
|
195 | 209 | end |
|
196 | 210 | @log = import_log |
|
197 | 211 | end |
|
198 | 212 | |
|
199 | 213 | def remove_contest |
|
200 | 214 | problem = Problem.find(params[:id]) |
|
201 | 215 | contest = Contest.find(params[:contest_id]) |
|
202 | 216 | if problem!=nil and contest!=nil |
|
203 | 217 | problem.contests.delete(contest) |
|
204 | 218 | end |
|
205 | 219 | redirect_to :action => 'manage' |
|
206 | 220 | end |
|
207 | 221 | |
|
208 | 222 | ################################## |
|
209 | 223 | protected |
|
210 | 224 | |
|
211 | 225 | def allow_test_pair_import? |
|
212 | 226 | if defined? ALLOW_TEST_PAIR_IMPORT |
|
213 | 227 | return ALLOW_TEST_PAIR_IMPORT |
|
214 | 228 | else |
|
215 | 229 | return false |
|
216 | 230 | end |
|
217 | 231 | end |
|
218 | 232 | |
|
219 | 233 | def change_date_added |
|
220 | 234 | problems = get_problems_from_params |
|
221 | 235 | year = params[:date_added][:year].to_i |
|
222 | 236 | month = params[:date_added][:month].to_i |
|
223 | 237 | day = params[:date_added][:day].to_i |
|
224 | 238 | date = Date.new(year,month,day) |
|
225 | 239 | problems.each do |p| |
|
226 | 240 | p.date_added = date |
|
227 | 241 | p.save |
|
228 | 242 | end |
|
229 | 243 | end |
|
230 | 244 | |
|
231 | 245 | def add_to_contest |
|
232 | 246 | problems = get_problems_from_params |
|
233 | 247 | contest = Contest.find(params[:contest][:id]) |
|
234 | 248 | if contest!=nil and contest.enabled |
|
235 | 249 | problems.each do |p| |
|
236 | 250 | p.contests << contest |
|
237 | 251 | end |
|
238 | 252 | end |
|
239 | 253 | end |
|
240 | 254 | |
|
241 | 255 | def set_available(avail) |
|
242 | 256 | problems = get_problems_from_params |
|
243 | 257 | problems.each do |p| |
|
244 | 258 | p.available = avail |
|
245 | 259 | p.save |
|
246 | 260 | end |
|
247 | 261 | end |
|
248 | 262 | |
|
249 | 263 | def get_problems_from_params |
|
250 | 264 | problems = [] |
|
251 | 265 | params.keys.each do |k| |
|
252 | 266 | if k.index('prob-')==0 |
|
253 | 267 | name, id, order = k.split('-') |
|
254 | 268 | problems << Problem.find(id) |
|
255 | 269 | end |
|
256 | 270 | end |
|
257 | 271 | problems |
|
258 | 272 | end |
|
259 | 273 | |
|
274 | + def get_problems_stat | |
|
275 | + end | |
|
276 | + | |
|
260 | 277 | end |
@@ -12,184 +12,180 | |||
|
12 | 12 | } |
|
13 | 13 | |
|
14 | 14 | def login_stat |
|
15 | 15 | @logins = Array.new |
|
16 | 16 | |
|
17 | 17 | date_and_time = '%Y-%m-%d %H:%M' |
|
18 | 18 | begin |
|
19 | 19 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
20 | 20 | @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) |
|
21 | 21 | rescue |
|
22 | 22 | @since_time = DateTime.new(1000,1,1) |
|
23 | 23 | end |
|
24 | 24 | begin |
|
25 | 25 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
26 | 26 | @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) |
|
27 | 27 | rescue |
|
28 | 28 | @until_time = DateTime.new(3000,1,1) |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | User.all.each do |user| |
|
32 | 32 | @logins << { id: user.id, |
|
33 | 33 | login: user.login, |
|
34 | 34 | full_name: user.full_name, |
|
35 | 35 | count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
36 | 36 | user.id,@since_time,@until_time) |
|
37 | 37 | .count(:id), |
|
38 | 38 | min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
39 | 39 | user.id,@since_time,@until_time) |
|
40 | 40 | .minimum(:created_at), |
|
41 | 41 | max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
42 | 42 | user.id,@since_time,@until_time) |
|
43 | 43 | .maximum(:created_at), |
|
44 | 44 | ip: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
45 | 45 | user.id,@since_time,@until_time) |
|
46 | 46 | .select(:ip_address).uniq |
|
47 | 47 | |
|
48 | 48 | } |
|
49 | 49 | end |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | def submission_stat |
|
53 | 53 | |
|
54 | 54 | date_and_time = '%Y-%m-%d %H:%M' |
|
55 | 55 | begin |
|
56 | 56 | @since_time = DateTime.strptime(params[:since_datetime],date_and_time) |
|
57 | 57 | rescue |
|
58 | 58 | @since_time = DateTime.new(1000,1,1) |
|
59 | 59 | end |
|
60 | 60 | begin |
|
61 | 61 | @until_time = DateTime.strptime(params[:until_datetime],date_and_time) |
|
62 | 62 | rescue |
|
63 | 63 | @until_time = DateTime.new(3000,1,1) |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | @submissions = {} |
|
67 | 67 | |
|
68 | 68 | User.find_each do |user| |
|
69 | 69 | @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } } |
|
70 | 70 | end |
|
71 | 71 | |
|
72 | 72 | Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s| |
|
73 | 73 | if @submissions[s.user_id] |
|
74 | 74 | if not @submissions[s.user_id][:sub].has_key?(s.problem_id) |
|
75 | 75 | a = nil |
|
76 | 76 | begin |
|
77 | 77 | a = Problem.find(s.problem_id) |
|
78 | 78 | rescue |
|
79 | 79 | a = nil |
|
80 | 80 | end |
|
81 | 81 | @submissions[s.user_id][:sub][s.problem_id] = |
|
82 | 82 | { prob_name: (a ? a.full_name : '(NULL)'), |
|
83 | 83 | sub_ids: [s.id] } |
|
84 | 84 | else |
|
85 | 85 | @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id |
|
86 | 86 | end |
|
87 | 87 | @submissions[s.user_id][:count] += 1 |
|
88 | 88 | end |
|
89 | 89 | end |
|
90 | 90 | end |
|
91 | 91 | |
|
92 | 92 | def problem_hof |
|
93 | 93 | # gen problem list |
|
94 | 94 | @user = User.find(session[:user_id]) |
|
95 | 95 | @problems = @user.available_problems |
|
96 | 96 | |
|
97 | 97 | # get selected problems or the default |
|
98 | 98 | if params[:id] |
|
99 | 99 | begin |
|
100 | 100 | @problem = Problem.available.find(params[:id]) |
|
101 | 101 | rescue |
|
102 | 102 | redirect_to action: :problem_hof |
|
103 | 103 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
104 | 104 | return |
|
105 | 105 | end |
|
106 | 106 | end |
|
107 | 107 | |
|
108 |
- |
|
|
109 | - #aggregrate by language | |
|
110 | - @by_lang = {} | |
|
111 | - Submission.where(problem_id: @problem.id).find_each do |sub| | |
|
112 | - lang = Language.find_by_id(sub.language_id) | |
|
113 | - next unless lang | |
|
114 | - next unless sub.points >= @problem.full_score | |
|
108 | + return unless @problem | |
|
109 | + | |
|
110 | + @by_lang = {} #aggregrate by language | |
|
115 | 111 | |
|
116 | - #initialize | |
|
117 | - unless @by_lang.has_key?(lang.pretty_name) | |
|
118 | - @by_lang[lang.pretty_name] = { | |
|
119 | - runtime: { avail: false, value: 2**30-1 }, | |
|
120 | - memory: { avail: false, value: 2**30-1 }, | |
|
121 | - length: { avail: false, value: 2**30-1 }, | |
|
122 | - first: { avail: false, value: DateTime.new(3000,1,1) } | |
|
123 | - } | |
|
124 | - end | |
|
112 | + range =65 | |
|
113 | + @histogram = { data: Array.new(range,0), summary: {} } | |
|
114 | + @summary = {count: 0, solve: 0, attempt: 0} | |
|
115 | + user = Hash.new(0) | |
|
116 | + Submission.where(problem_id: @problem.id).find_each do |sub| | |
|
117 | + #histogram | |
|
118 | + d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 | |
|
119 | + @histogram[:data][d.to_i] += 1 if d < range | |
|
125 | 120 | |
|
126 | - if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value] | |
|
127 | - @by_lang[lang.pretty_name][:runtime] = { | |
|
128 | - avail: true, | |
|
129 | - user_id: sub.user_id, | |
|
130 | - value: sub.max_runtime, | |
|
131 | - sub_id: sub.id | |
|
132 | - } | |
|
133 | - end | |
|
121 | + @summary[:count] += 1 | |
|
122 | + user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max | |
|
134 | 123 | |
|
135 | - if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value] | |
|
136 | - @by_lang[lang.pretty_name][:memory] = { | |
|
137 | - avail: true, | |
|
138 | - user_id: sub.user_id, | |
|
139 | - value: sub.peak_memory, | |
|
140 | - sub_id: sub.id | |
|
141 | - } | |
|
142 | - end | |
|
124 | + lang = Language.find_by_id(sub.language_id) | |
|
125 | + next unless lang | |
|
126 | + next unless sub.points >= @problem.full_score | |
|
143 | 127 | |
|
144 | - if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and | |
|
145 | - !sub.user.admin? | |
|
146 |
- |
|
|
147 | - avail: true, | |
|
148 | - user_id: sub.user_id, | |
|
149 | - value: sub.submitted_at, | |
|
150 | - sub_id: sub.id | |
|
151 |
- |
|
|
152 |
- |
|
|
128 | + #initialize | |
|
129 | + unless @by_lang.has_key?(lang.pretty_name) | |
|
130 | + @by_lang[lang.pretty_name] = { | |
|
131 | + runtime: { avail: false, value: 2**30-1 }, | |
|
132 | + memory: { avail: false, value: 2**30-1 }, | |
|
133 | + length: { avail: false, value: 2**30-1 }, | |
|
134 | + first: { avail: false, value: DateTime.new(3000,1,1) } | |
|
135 | + } | |
|
136 | + end | |
|
153 | 137 | |
|
154 | - if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length | |
|
155 | - @by_lang[lang.pretty_name][:length] = { | |
|
156 | - avail: true, | |
|
157 | - user_id: sub.user_id, | |
|
158 | - value: sub.effective_code_length, | |
|
159 | - sub_id: sub.id | |
|
160 | - } | |
|
161 | - end | |
|
162 | - end | |
|
163 | - | |
|
164 | - #process user_id | |
|
165 | - @by_lang.each do |lang,prop| | |
|
166 | - prop.each do |k,v| | |
|
167 | - v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)" | |
|
168 | - end | |
|
138 | + if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value] | |
|
139 | + @by_lang[lang.pretty_name][:runtime] = { avail: true, user_id: sub.user_id, value: sub.max_runtime, sub_id: sub.id } | |
|
169 | 140 | end |
|
170 | 141 | |
|
171 | - #sum into best | |
|
172 | - if @by_lang and @by_lang.first | |
|
173 | - @best = @by_lang.first[1].clone | |
|
174 | - @by_lang.each do |lang,prop| | |
|
175 | - if @best[:runtime][:value] >= prop[:runtime][:value] | |
|
176 | - @best[:runtime] = prop[:runtime] | |
|
177 | - @best[:runtime][:lang] = lang | |
|
178 |
- |
|
|
179 | - if @best[:memory][:value] >= prop[:memory][:value] | |
|
180 | - @best[:memory] = prop[:memory] | |
|
181 | - @best[:memory][:lang] = lang | |
|
182 |
- |
|
|
183 | - if @best[:length][:value] >= prop[:length][:value] | |
|
184 | - @best[:length] = prop[:length] | |
|
185 | - @best[:length][:lang] = lang | |
|
186 | - end | |
|
187 | - if @best[:first][:value] >= prop[:first][:value] | |
|
188 | - @best[:first] = prop[:first] | |
|
189 | - @best[:first][:lang] = lang | |
|
190 |
- |
|
|
142 | + if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value] | |
|
143 | + @by_lang[lang.pretty_name][:memory] = { avail: true, user_id: sub.user_id, value: sub.peak_memory, sub_id: sub.id } | |
|
144 | + end | |
|
145 | + | |
|
146 | + if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and | |
|
147 | + !sub.user.admin? | |
|
148 | + @by_lang[lang.pretty_name][:first] = { avail: true, user_id: sub.user_id, value: sub.submitted_at, sub_id: sub.id } | |
|
149 | + end | |
|
150 | + | |
|
151 | + if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length | |
|
152 | + @by_lang[lang.pretty_name][:length] = { avail: true, user_id: sub.user_id, value: sub.effective_code_length, sub_id: sub.id } | |
|
153 | + end | |
|
154 | + end | |
|
155 | + | |
|
156 | + #process user_id | |
|
157 | + @by_lang.each do |lang,prop| | |
|
158 | + prop.each do |k,v| | |
|
159 | + v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)" | |
|
160 | + end | |
|
161 | + end | |
|
162 | + | |
|
163 | + #sum into best | |
|
164 | + if @by_lang and @by_lang.first | |
|
165 | + @best = @by_lang.first[1].clone | |
|
166 | + @by_lang.each do |lang,prop| | |
|
167 | + if @best[:runtime][:value] >= prop[:runtime][:value] | |
|
168 | + @best[:runtime] = prop[:runtime] | |
|
169 | + @best[:runtime][:lang] = lang | |
|
170 | + end | |
|
171 | + if @best[:memory][:value] >= prop[:memory][:value] | |
|
172 | + @best[:memory] = prop[:memory] | |
|
173 | + @best[:memory][:lang] = lang | |
|
174 | + end | |
|
175 | + if @best[:length][:value] >= prop[:length][:value] | |
|
176 | + @best[:length] = prop[:length] | |
|
177 | + @best[:length][:lang] = lang | |
|
178 | + end | |
|
179 | + if @best[:first][:value] >= prop[:first][:value] | |
|
180 | + @best[:first] = prop[:first] | |
|
181 | + @best[:first][:lang] = lang | |
|
191 | 182 | end |
|
192 | 183 | end |
|
193 | 184 | end |
|
185 | + | |
|
186 | + @histogram[:summary][:max] = [@histogram[:data].max,1].max | |
|
187 | + @summary[:attempt] = user.count | |
|
188 | + user.each_value { |v| @summary[:solve] += 1 if v == 1 } | |
|
194 | 189 | end |
|
190 | + | |
|
195 | 191 | end |
@@ -18,159 +18,177 | |||
|
18 | 18 | |
|
19 | 19 | verify :method => :post, :only => [:chg_passwd], |
|
20 | 20 | :redirect_to => { :action => :index } |
|
21 | 21 | |
|
22 | 22 | #in_place_edit_for :user, :alias_for_editing |
|
23 | 23 | #in_place_edit_for :user, :email_for_editing |
|
24 | 24 | |
|
25 | 25 | def index |
|
26 | 26 | if !GraderConfiguration['system.user_setting_enabled'] |
|
27 | 27 | redirect_to :controller => 'main', :action => 'list' |
|
28 | 28 | else |
|
29 | 29 | @user = User.find(session[:user_id]) |
|
30 | 30 | end |
|
31 | 31 | end |
|
32 | 32 | |
|
33 | 33 | def chg_passwd |
|
34 | 34 | user = User.find(session[:user_id]) |
|
35 | 35 | user.password = params[:passwd] |
|
36 | 36 | user.password_confirmation = params[:passwd_verify] |
|
37 | 37 | if user.save |
|
38 | 38 | flash[:notice] = 'password changed' |
|
39 | 39 | else |
|
40 | 40 | flash[:notice] = 'Error: password changing failed' |
|
41 | 41 | end |
|
42 | 42 | redirect_to :action => 'index' |
|
43 | 43 | end |
|
44 | 44 | |
|
45 | 45 | def new |
|
46 | 46 | @user = User.new |
|
47 | 47 | render :action => 'new', :layout => 'empty' |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | def register |
|
51 | 51 | if(params[:cancel]) |
|
52 | 52 | redirect_to :controller => 'main', :action => 'login' |
|
53 | 53 | return |
|
54 | 54 | end |
|
55 | 55 | @user = User.new(params[:user]) |
|
56 | 56 | @user.password_confirmation = @user.password = User.random_password |
|
57 | 57 | @user.activated = false |
|
58 | 58 | if (@user.valid?) and (@user.save) |
|
59 | 59 | if send_confirmation_email(@user) |
|
60 | 60 | render :action => 'new_splash', :layout => 'empty' |
|
61 | 61 | else |
|
62 | 62 | @admin_email = GraderConfiguration['system.admin_email'] |
|
63 | 63 | render :action => 'email_error', :layout => 'empty' |
|
64 | 64 | end |
|
65 | 65 | else |
|
66 | 66 | @user.errors.add_to_base("Email cannot be blank") if @user.email=='' |
|
67 | 67 | render :action => 'new', :layout => 'empty' |
|
68 | 68 | end |
|
69 | 69 | end |
|
70 | 70 | |
|
71 | 71 | def confirm |
|
72 | 72 | login = params[:login] |
|
73 | 73 | key = params[:activation] |
|
74 | 74 | @user = User.find_by_login(login) |
|
75 | 75 | if (@user) and (@user.verify_activation_key(key)) |
|
76 | 76 | if @user.valid? # check uniquenss of email |
|
77 | 77 | @user.activated = true |
|
78 | 78 | @user.save |
|
79 | 79 | @result = :successful |
|
80 | 80 | else |
|
81 | 81 | @result = :email_used |
|
82 | 82 | end |
|
83 | 83 | else |
|
84 | 84 | @result = :failed |
|
85 | 85 | end |
|
86 | 86 | render :action => 'confirm', :layout => 'empty' |
|
87 | 87 | end |
|
88 | 88 | |
|
89 | 89 | def forget |
|
90 | 90 | render :action => 'forget', :layout => 'empty' |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | def retrieve_password |
|
94 | 94 | email = params[:email] |
|
95 | 95 | user = User.find_by_email(email) |
|
96 | 96 | if user |
|
97 | 97 | last_updated_time = user.updated_at || user.created_at || (Time.now.gmtime - 1.hour) |
|
98 | 98 | if last_updated_time > Time.now.gmtime - 5.minutes |
|
99 | 99 | flash[:notice] = 'The account has recently created or new password has recently been requested. Please wait for 5 minutes' |
|
100 | 100 | else |
|
101 | 101 | user.password = user.password_confirmation = User.random_password |
|
102 | 102 | user.save |
|
103 | 103 | send_new_password_email(user) |
|
104 | 104 | flash[:notice] = 'New password has been mailed to you.' |
|
105 | 105 | end |
|
106 | 106 | else |
|
107 | 107 | flash[:notice] = I18n.t 'registration.password_retrieval.no_email' |
|
108 | 108 | end |
|
109 | 109 | redirect_to :action => 'forget' |
|
110 | 110 | end |
|
111 | 111 | |
|
112 | 112 | def profile |
|
113 | 113 | @user = User.find(params[:id]) |
|
114 |
- @submission = Submission.where(user_id: params[:id]) |
|
|
114 | + @submission = Submission.includes(:problem).where(user_id: params[:id]) | |
|
115 | + | |
|
116 | + range = 120 | |
|
117 | + @histogram = { data: Array.new(range,0), summary: {} } | |
|
118 | + @summary = {count: 0, solve: 0, attempt: 0} | |
|
119 | + problem = Hash.new(0) | |
|
120 | + | |
|
121 | + @submission.find_each do |sub| | |
|
122 | + #histogram | |
|
123 | + d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 | |
|
124 | + @histogram[:data][d.to_i] += 1 if d < range | |
|
125 | + | |
|
126 | + @summary[:count] += 1 | |
|
127 | + problem[sub.problem] = [problem[sub.problem], (sub.points >= sub.problem.full_score) ? 1 : 0].max | |
|
128 | + end | |
|
129 | + | |
|
130 | + @histogram[:summary][:max] = [@histogram[:data].max,1].max | |
|
131 | + @summary[:attempt] = problem.count | |
|
132 | + problem.each_value { |v| @summary[:solve] += 1 if v == 1 } | |
|
115 | 133 | end |
|
116 | 134 | |
|
117 | 135 | protected |
|
118 | 136 | |
|
119 | 137 | def verify_online_registration |
|
120 | 138 | if !GraderConfiguration['system.online_registration'] |
|
121 | 139 | redirect_to :controller => 'main', :action => 'login' |
|
122 | 140 | end |
|
123 | 141 | end |
|
124 | 142 | |
|
125 | 143 | def send_confirmation_email(user) |
|
126 | 144 | contest_name = GraderConfiguration['contest.name'] |
|
127 | 145 | activation_url = url_for(:action => 'confirm', |
|
128 | 146 | :login => user.login, |
|
129 | 147 | :activation => user.activation_key) |
|
130 | 148 | home_url = url_for(:controller => 'main', :action => 'index') |
|
131 | 149 | mail_subject = "[#{contest_name}] Confirmation" |
|
132 | 150 | mail_body = t('registration.email_body', { |
|
133 | 151 | :full_name => user.full_name, |
|
134 | 152 | :contest_name => contest_name, |
|
135 | 153 | :login => user.login, |
|
136 | 154 | :password => user.password, |
|
137 | 155 | :activation_url => activation_url, |
|
138 | 156 | :admin_email => admin_email |
|
139 | 157 | }) |
|
140 | 158 | |
|
141 | 159 | logger.info mail_body |
|
142 | 160 | |
|
143 | 161 | send_mail(user.email, mail_subject, mail_body) |
|
144 | 162 | end |
|
145 | 163 | |
|
146 | 164 | def send_new_password_email(user) |
|
147 | 165 | contest_name = GraderConfiguration['contest.name'] |
|
148 | 166 | mail_subject = "[#{contest_name}] Password recovery" |
|
149 | 167 | mail_body = t('registration.password_retrieval.email_body', { |
|
150 | 168 | :full_name => user.full_name, |
|
151 | 169 | :contest_name => contest_name, |
|
152 | 170 | :login => user.login, |
|
153 | 171 | :password => user.password, |
|
154 | 172 | :admin_email => admin_email |
|
155 | 173 | }) |
|
156 | 174 | |
|
157 | 175 | logger.info mail_body |
|
158 | 176 | |
|
159 | 177 | send_mail(user.email, mail_subject, mail_body) |
|
160 | 178 | end |
|
161 | 179 | |
|
162 | 180 | # allow viewing of regular user profile only when options allow so |
|
163 | 181 | # only admins can view admins profile |
|
164 | 182 | def profile_authorization |
|
165 | 183 | #if view admins' profile, allow only admin |
|
166 | 184 | return false unless(params[:id]) |
|
167 | 185 | user = User.find(params[:id]) |
|
168 | 186 | return false unless user |
|
169 | 187 | return admin_authorization if user.admin? |
|
170 | 188 | return true if GraderConfiguration["right.user_view_submission"] |
|
171 | 189 | |
|
172 | 190 | #finally, we allow only admin |
|
173 | 191 | admin_authorization |
|
174 | 192 | end |
|
175 | 193 | |
|
176 | 194 | end |
@@ -1,121 +1,128 | |||
|
1 | 1 | class Problem < ActiveRecord::Base |
|
2 | 2 | |
|
3 | 3 | belongs_to :description |
|
4 | 4 | has_and_belongs_to_many :contests, :uniq => true |
|
5 | 5 | has_many :test_pairs, :dependent => :delete_all |
|
6 | 6 | |
|
7 | 7 | validates_presence_of :name |
|
8 | 8 | validates_format_of :name, :with => /^\w+$/ |
|
9 | 9 | validates_presence_of :full_name |
|
10 | 10 | |
|
11 | 11 | scope :available, :conditions => {:available => true} |
|
12 | 12 | |
|
13 | 13 | DEFAULT_TIME_LIMIT = 1 |
|
14 | 14 | DEFAULT_MEMORY_LIMIT = 32 |
|
15 | 15 | |
|
16 | 16 | def self.find_available_problems |
|
17 | 17 | Problem.available.all(:order => "date_added DESC, name ASC") |
|
18 | 18 | end |
|
19 | 19 | |
|
20 | 20 | def self.create_from_import_form_params(params, old_problem=nil) |
|
21 | 21 | org_problem = old_problem || Problem.new |
|
22 | 22 | import_params, problem = Problem.extract_params_and_check(params, |
|
23 | 23 | org_problem) |
|
24 | 24 | |
|
25 | 25 | if !problem.errors.empty? |
|
26 | 26 | return problem, 'Error importing' |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | problem.full_score = 100 |
|
30 | 30 | problem.date_added = Time.new |
|
31 | 31 | problem.test_allowed = true |
|
32 | 32 | problem.output_only = false |
|
33 | 33 | problem.available = false |
|
34 | 34 | |
|
35 | 35 | if not problem.save |
|
36 | 36 | return problem, 'Error importing' |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | import_to_db = params.has_key? :import_to_db |
|
40 | 40 | |
|
41 | 41 | importer = TestdataImporter.new(problem) |
|
42 | 42 | |
|
43 | 43 | if not importer.import_from_file(import_params[:file], |
|
44 | 44 | import_params[:time_limit], |
|
45 | 45 | import_params[:memory_limit], |
|
46 | 46 | import_params[:checker_name], |
|
47 | 47 | import_to_db) |
|
48 | 48 | problem.errors.add_to_base('Import error.') |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | 51 | return problem, importer.log_msg |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | def self.download_file_basedir |
|
55 | 55 | return "#{Rails.root}/data/tasks" |
|
56 | 56 | end |
|
57 | + | |
|
58 | + def get_submission_stat | |
|
59 | + result = Hash.new | |
|
60 | + #total number of submission | |
|
61 | + result[:total_sub] = Submission.where(problem_id: self.id).count | |
|
62 | + result[:attempted_user] = Submission.where(problem_id: self.id).group_by(:user_id) | |
|
63 | + end | |
|
57 | 64 | |
|
58 | 65 | protected |
|
59 | 66 | |
|
60 | 67 | def self.to_i_or_default(st, default) |
|
61 | 68 | if st!='' |
|
62 | 69 | result = st.to_i |
|
63 | 70 | end |
|
64 | 71 | result ||= default |
|
65 | 72 | end |
|
66 | 73 | |
|
67 | 74 | def self.to_f_or_default(st, default) |
|
68 | 75 | if st!='' |
|
69 | 76 | result = st.to_f |
|
70 | 77 | end |
|
71 | 78 | result ||= default |
|
72 | 79 | end |
|
73 | 80 | |
|
74 | 81 | def self.extract_params_and_check(params, problem) |
|
75 | 82 | time_limit = Problem.to_f_or_default(params[:time_limit], |
|
76 | 83 | DEFAULT_TIME_LIMIT) |
|
77 | 84 | memory_limit = Problem.to_i_or_default(params[:memory_limit], |
|
78 | 85 | DEFAULT_MEMORY_LIMIT) |
|
79 | 86 | |
|
80 | 87 | if time_limit<=0 or time_limit >60 |
|
81 | 88 | problem.errors.add_to_base('Time limit out of range.') |
|
82 | 89 | end |
|
83 | 90 | |
|
84 | 91 | if memory_limit==0 and params[:memory_limit]!='0' |
|
85 | 92 | problem.errors.add_to_base('Memory limit format errors.') |
|
86 | 93 | elsif memory_limit<=0 or memory_limit >512 |
|
87 | 94 | problem.errors.add_to_base('Memory limit out of range.') |
|
88 | 95 | end |
|
89 | 96 | |
|
90 | 97 | if params[:file]==nil or params[:file]=='' |
|
91 | 98 | problem.errors.add_to_base('No testdata file.') |
|
92 | 99 | end |
|
93 | 100 | |
|
94 | 101 | checker_name = 'text' |
|
95 | 102 | if ['text','float'].include? params[:checker] |
|
96 | 103 | checker_name = params[:checker] |
|
97 | 104 | end |
|
98 | 105 | |
|
99 | 106 | file = params[:file] |
|
100 | 107 | |
|
101 | 108 | if !problem.errors.empty? |
|
102 | 109 | return nil, problem |
|
103 | 110 | end |
|
104 | 111 | |
|
105 | 112 | problem.name = params[:name] |
|
106 | 113 | if params[:full_name]!='' |
|
107 | 114 | problem.full_name = params[:full_name] |
|
108 | 115 | else |
|
109 | 116 | problem.full_name = params[:name] |
|
110 | 117 | end |
|
111 | 118 | |
|
112 | 119 | return [{ |
|
113 | 120 | :time_limit => time_limit, |
|
114 | 121 | :memory_limit => memory_limit, |
|
115 | 122 | :file => file, |
|
116 | 123 | :checker_name => checker_name |
|
117 | 124 | }, |
|
118 | 125 | problem] |
|
119 | 126 | end |
|
120 | 127 | |
|
121 | 128 | end |
@@ -1,61 +1,67 | |||
|
1 | 1 | %style{type: "text/css"} |
|
2 | 2 | = @css_style |
|
3 | 3 | :css |
|
4 | 4 | .field { |
|
5 | 5 | font-weight: bold; |
|
6 | 6 | text-align: right; |
|
7 | 7 | padding: 3px; |
|
8 | 8 | } |
|
9 | 9 | |
|
10 | 10 | |
|
11 | 11 | %h1= "Submission: #{@submission.id}" |
|
12 | 12 | |
|
13 | 13 | |
|
14 | 14 | %h2 Stat |
|
15 | 15 | |
|
16 | 16 | %table.info |
|
17 | 17 | %thead |
|
18 | 18 | %tr.info-head |
|
19 | 19 | %th Field |
|
20 | 20 | %th Value |
|
21 | 21 | %tbody |
|
22 | 22 | %tr{class: cycle('info-even','info-odd')} |
|
23 | 23 | %td.field User: |
|
24 | - %td.value= "(#{@submission.user.login}) #{@submission.user.full_name}" | |
|
24 | + %td.value | |
|
25 | + - if @submission.user | |
|
26 | + = link_to "(#{@submission.user.login})", controller: "users", action: "profile", id: @submission.user | |
|
27 | + = @submission.user.full_name | |
|
28 | + - else | |
|
29 | + = "(n/a)" | |
|
25 | 30 | %tr{class: cycle('info-even','info-odd')} |
|
26 | 31 | %td.field Problem: |
|
27 | 32 | %td.value |
|
28 | 33 | - if @submission.problem!=nil |
|
29 |
- = "(#{@submission.problem.name}) |
|
|
34 | + = link_to "(#{@submission.problem.name})", controller: "problems", action: "stat", id: @submission.problem | |
|
35 | + = @submission.problem.full_name | |
|
30 | 36 | - else |
|
31 | 37 | = "(n/a)" |
|
32 | 38 | %tr{class: cycle('info-even','info-odd')} |
|
33 | 39 | %td.field Tries: |
|
34 | 40 | %td.value= @submission.number |
|
35 | 41 | %tr{class: cycle('info-even','info-odd')} |
|
36 | 42 | %td.field Submitted: |
|
37 | 43 | %td.value #{time_ago_in_words(@submission.submitted_at)} ago (at #{@submission.submitted_at.to_formatted_s(:long)}) |
|
38 | 44 | %tr{class: cycle('info-even','info-odd')} |
|
39 | 45 | %td.field Graded: |
|
40 | 46 | %td.value #{time_ago_in_words(@submission.graded_at)} ago (at #{@submission.graded_at.to_formatted_s(:long)}) |
|
41 | 47 | %tr{class: cycle('info-even','info-odd')} |
|
42 | 48 | %td.field Points: |
|
43 | 49 | %td.value #{@submission.points}/#{@submission.problem.full_score} |
|
44 | 50 | %tr{class: cycle('info-even','info-odd')} |
|
45 | 51 | %td.field Comment: |
|
46 | 52 | %td.value #{@submission.grader_comment} |
|
47 | 53 | %tr{class: cycle('info-even','info-odd')} |
|
48 | 54 | %td.field Runtime (s): |
|
49 | 55 | %td.value #{@submission.max_runtime} |
|
50 | 56 | %tr{class: cycle('info-even','info-odd')} |
|
51 | 57 | %td.field Memory (kb): |
|
52 | 58 | %td.value #{@submission.peak_memory} |
|
53 | 59 | - if session[:admin] |
|
54 | 60 | %tr{class: cycle('info-even','info-odd')} |
|
55 | 61 | %td.field IP: |
|
56 | 62 | %td.value #{@submission.ip_address} |
|
57 | 63 | |
|
58 | 64 | %h2 Source code |
|
59 | 65 | //%div.highlight{:style => "border: 1px solid black;"} |
|
60 | 66 | =@formatted_code.html_safe |
|
61 | 67 |
@@ -1,34 +1,51 | |||
|
1 | 1 | :css |
|
2 | 2 | .fix-width { |
|
3 | 3 | font-family: "Consolas, Monaco, Droid Sans Mono,Mono, Monospace,Courier" |
|
4 | 4 | } |
|
5 | 5 | |
|
6 | 6 | %h1 Problem stat: #{@problem.name} |
|
7 | 7 | %h2 Overview |
|
8 | 8 | |
|
9 | + | |
|
10 | + %table.info | |
|
11 | + %thead | |
|
12 | + %tr.info-head | |
|
13 | + %th Stat | |
|
14 | + %th Value | |
|
15 | + %tbody | |
|
16 | + %tr{class: cycle('info-even','info-odd')} | |
|
17 | + %td Submissions | |
|
18 | + %td= @submissions.count | |
|
19 | + %tr{class: cycle('info-even','info-odd')} | |
|
20 | + %td Solved/Attempted User | |
|
21 | + %td #{@summary[:solve]}/#{@summary[:attempt]} (#{(@summary[:solve]*100.0/@summary[:attempt]).round(1)}%) | |
|
22 | + | |
|
23 | + %h2 Submissions Count | |
|
24 | + = render partial: 'application/bar_graph', locals: { histogram: @histogram } | |
|
25 | + | |
|
9 | 26 | %h2 Submissions |
|
10 | 27 | - if @submissions and @submissions.count > 0 |
|
11 | 28 | %table.info#main_table |
|
12 | 29 | %thead |
|
13 | 30 | %tr.info-head |
|
14 | 31 | %th ID |
|
15 | 32 | %th Login |
|
16 | 33 | %th Name |
|
17 | 34 | %th Submitted_at |
|
18 | 35 | %th Points |
|
19 | 36 | %th comment |
|
20 | 37 | %tbody |
|
21 | 38 | - row_odd,curr = true,'' |
|
22 | 39 | - @submissions.each do |sub| |
|
23 | 40 | - next unless sub.user |
|
24 | 41 | - row_odd,curr = !row_odd, sub.user if curr != sub.user |
|
25 | 42 | %tr{class: row_odd ? "info-odd" : "info-even"} |
|
26 | 43 | %td= link_to sub.id, controller: 'graders', action: 'submission', id: sub.id |
|
27 | 44 | %td= link_to sub.user.login, controller: :users, action: :profile, id: sub.user.id |
|
28 | 45 | %td= sub.user.full_name |
|
29 | 46 | %td= time_ago_in_words(sub.submitted_at) + " ago" |
|
30 | 47 | %td= sub.points |
|
31 | 48 | %td.fix-width= sub.grader_comment |
|
32 | 49 | - else |
|
33 | 50 | No submission |
|
34 | 51 |
@@ -1,79 +1,128 | |||
|
1 | + - content_for :header do | |
|
2 | + = javascript_include_tag 'local_jquery' | |
|
3 | + | |
|
4 | + :javascript | |
|
5 | + $(document).ready( function() { | |
|
6 | + $("#mem_remark").hover( function() { | |
|
7 | + $("#mem_remark_box").show(); | |
|
8 | + }, function() { | |
|
9 | + $("#mem_remark_box").hide(); | |
|
10 | + }); | |
|
11 | + }); | |
|
12 | + alert("hahaha"); | |
|
1 | 13 | :css |
|
2 | 14 | .hof_user { color: orangered; font-style: italic; } |
|
3 | 15 | .hof_language { color: green; font-style: italic; } |
|
4 | 16 | .hof_value { color: deeppink;font-style: italic; } |
|
17 | + .info_param { font-weight: bold;text-align: right; } | |
|
18 | + .tooltip { | |
|
19 | + font-family: Verdana,sans-serif; | |
|
20 | + font-weight: normal; | |
|
21 | + text-align: left; | |
|
22 | + font-size: 1.0em; | |
|
23 | + color: black; | |
|
24 | + line-height: 1.1; | |
|
25 | + display: none; | |
|
26 | + min-width: 20em; | |
|
27 | + position: absolute; | |
|
28 | + left: 25px; | |
|
29 | + bottom: 5px; | |
|
30 | + border: 1px solid; | |
|
31 | + padding: 5px; | |
|
32 | + background-color: #FFF; | |
|
33 | + word-wrap: break-word; | |
|
34 | + z-index: 9999; | |
|
35 | + overflow: auto; | |
|
36 | + } | |
|
5 | 37 | |
|
6 |
- %h |
|
|
38 | + %h1 (#{Problem.find(params[:id]).name}) #{Problem.find(params[:id]).full_name} | |
|
39 | + | |
|
40 | + %h2 Problem Stat | |
|
41 | + %table.info | |
|
42 | + %thead | |
|
43 | + %tr.info-head | |
|
44 | + %th Stat | |
|
45 | + %th Value | |
|
46 | + %tbody | |
|
47 | + %tr{class: cycle('info-even','info-odd')} | |
|
48 | + %td.info_param Submissions | |
|
49 | + %td= @summary[:count] | |
|
50 | + %tr{class: cycle('info-even','info-odd')} | |
|
51 | + %td.info_param Solved/Attempted User | |
|
52 | + %td #{@summary[:solve]}/#{@summary[:attempt]} (#{(@summary[:solve]*100.0/@summary[:attempt]).round(1)}%) | |
|
53 | + - if @best | |
|
54 | + %tr{class: cycle('info-even','info-odd')} | |
|
55 | + %td.info_param Best Runtime | |
|
56 | + %td | |
|
57 | + by #{link_to @best[:runtime][:user], controller:'users', action:'profile', id:@best[:memory][:user_id]} | |
|
58 | + using <span class="hof_language">#{@best[:runtime][:lang]}</span> | |
|
59 | + with <span class="hof_value">#{@best[:runtime][:value] * 1000} milliseconds</span> | |
|
60 | + at submission | |
|
61 | + = link_to("#" + @best[:runtime][:sub_id].to_s, controller: 'graders', action: 'submission', id:@best[:runtime][:sub_id]) | |
|
62 | + | |
|
63 | + %tr{class: cycle('info-even','info-odd')} | |
|
64 | + %td.info_param | |
|
65 | + Best Memory Usage | |
|
66 | + %sup{ id: "mem_remark", style: "position:relative; color: blue;"} | |
|
67 | + [?] | |
|
68 | + %span.tooltip#mem_remark_box | |
|
69 | + This counts only for submission with 100% score. | |
|
70 | + Right now, java is excluded from memory usage competition. (Because it always uses 2GB memory...) | |
|
71 | + %td | |
|
72 | + by #{link_to @best[:memory][:user], controller:'users', action:'profile', id:@best[:memory][:user_id]} | |
|
73 | + using <span class="hof_language">#{@best[:memory][:lang]}</span> | |
|
74 | + with <span class="hof_value">#{number_with_delimiter(@best[:memory][:value])} kbytes </span> | |
|
75 | + at submission | |
|
76 | + = link_to("#" + @best[:memory][:sub_id].to_s, controller: 'graders' , action: 'submission', id:@best[:memory][:sub_id]) | |
|
77 | + | |
|
78 | + %tr{class: cycle('info-even','info-odd')} | |
|
79 | + %td.info_param Shortest Code | |
|
80 | + %td | |
|
81 | + by #{link_to @best[:length][:user], controller:'users', action:'profile', id:@best[:length][:user_id]} | |
|
82 | + using <span class="hof_language">#{@best[:length][:lang]}</span> | |
|
83 | + with <span class="hof_value">#{@best[:length][:value]} bytes</span> | |
|
84 | + at submission | |
|
85 | + = link_to("#" + @best[:length][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:length][:sub_id]) | |
|
86 | + | |
|
87 | + %tr{class: cycle('info-even','info-odd')} | |
|
88 | + %td.info_param First solver | |
|
89 | + %td | |
|
90 | + #{link_to @best[:first][:user], controller:'users', action:'profile', id:@best[:first][:user_id]} is the first solver | |
|
91 | + using <span class="hof_language">#{@best[:first][:lang]}</span> | |
|
92 | + on <span class="hof_value">#{@best[:first][:value]}</span> | |
|
93 | + at submission | |
|
94 | + = link_to("#" + @best[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:first][:sub_id]) | |
|
7 | 95 | |
|
8 | 96 | - if @best |
|
9 | - %b Best Runtime: | |
|
10 | - by #{link_to @best[:runtime][:user], controller:'users', action:'profile', id:@best[:memory][:user_id]} | |
|
11 | - using <span class="hof_language">#{@best[:runtime][:lang]}</span> | |
|
12 | - with <span class="hof_value">#{@best[:runtime][:value] * 1000} milliseconds</span> | |
|
13 | - at submission | |
|
14 | - = link_to("#" + @best[:runtime][:sub_id].to_s, controller: 'graders', action: 'submission', id:@best[:runtime][:sub_id]) | |
|
15 | - %br/ | |
|
16 | - | |
|
17 | - %b Best Memory Usage: | |
|
18 | - by #{link_to @best[:memory][:user], controller:'users', action:'profile', id:@best[:memory][:user_id]} | |
|
19 | - using <span class="hof_language">#{@best[:memory][:lang]}</span> | |
|
20 | - with <span class="hof_value">#{number_with_delimiter(@best[:memory][:value])} kbytes </span> | |
|
21 | - at submission | |
|
22 | - = link_to("#" + @best[:memory][:sub_id].to_s, controller: 'graders' , action: 'submission', id:@best[:memory][:sub_id]) | |
|
23 | - %br/ | |
|
24 | - | |
|
25 | - %b Shortest Code: | |
|
26 | - by #{link_to @best[:length][:user], controller:'users', action:'profile', id:@best[:length][:user_id]} | |
|
27 | - using <span class="hof_language">#{@best[:length][:lang]}</span> | |
|
28 | - with <span class="hof_value">#{@best[:length][:value]} bytes</span> | |
|
29 | - at submission | |
|
30 | - = link_to("#" + @best[:length][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:length][:sub_id]) | |
|
31 | - %br/ | |
|
32 | - | |
|
33 | - %b First solver: | |
|
34 | - #{link_to @best[:first][:user], controller:'users', action:'profile', id:@best[:first][:user_id]} is the first solver | |
|
35 | - using <span class="hof_language">#{@best[:first][:lang]}</span> | |
|
36 | - on <span class="hof_value">#{@best[:first][:value]}</span> | |
|
37 | - at submission | |
|
38 | - = link_to("#" + @best[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: @best[:first][:sub_id]) | |
|
39 | - %br/ | |
|
40 | - | |
|
41 | - | |
|
42 | - %p | |
|
43 | - This counts only for submission with 100% score <br/> | |
|
44 | - Right now, java is excluded from memory usage competition. (Because it always uses 2GB memory...) | |
|
45 | - | |
|
46 | 97 | %h2 By language |
|
47 | 98 | |
|
48 | 99 | %table.info |
|
49 | 100 | %thead |
|
50 | 101 | %tr.info-head |
|
51 | 102 | %th Language |
|
52 | 103 | %th Best runtime (ms) |
|
53 | 104 | %th Best memory (kbytes) |
|
54 | 105 | %th Shortest Code (bytes) |
|
55 | 106 | %th First solver |
|
56 | 107 | %tbody |
|
57 | 108 | - @by_lang.each do |lang,value| |
|
58 | 109 | %tr{class: cycle('info-even','info-odd')} |
|
59 | 110 | %td= lang |
|
60 | 111 | %td |
|
61 | 112 | = link_to value[:runtime][:user], controller: 'users', action: 'profile', id: value[:runtime][:user_id] |
|
62 | 113 | = "(#{(value[:runtime][:value] * 1000).to_i} @" |
|
63 | 114 | = "#{link_to("#" + value[:runtime][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:runtime][:sub_id])} )".html_safe |
|
64 | 115 | %td |
|
65 | 116 | = link_to value[:memory][:user], controller: 'users', action: 'profile', id: value[:memory][:user_id] |
|
66 | 117 | = "(#{number_with_delimiter(value[:memory][:value])} @" |
|
67 | 118 | = "#{link_to("#" + value[:memory][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:memory][:sub_id])} )".html_safe |
|
68 | 119 | %td |
|
69 | 120 | = link_to value[:length][:user], controller: 'users', action: 'profile', id: value[:length][:user_id] |
|
70 | 121 | = "(#{value[:length][:value]} @" |
|
71 | 122 | = "#{link_to("#" + value[:length][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:length][:sub_id])} )".html_safe |
|
72 | 123 | %td |
|
73 | 124 | - if value[:first][:user] != '(NULL)' #TODO: i know... this is wrong... |
|
74 | 125 | = link_to value[:first][:user], controller: 'users', action: 'profile', id: value[:first][:user_id] |
|
75 | 126 | = "(#{value[:first][:value]} @" |
|
76 | 127 | = "#{link_to("#" + value[:first][:sub_id].to_s, controller: 'graders' , action: 'submission', id: value[:first][:sub_id])} )".html_safe |
|
77 | 128 | |
|
78 | - - else | |
|
79 | - %h3 No submissions |
@@ -1,22 +1,23 | |||
|
1 | 1 | |
|
2 | 2 | /- if params[:id] |
|
3 | 3 | / %h1 Tasks Hall of Fame |
|
4 | 4 | / = link_to('[back to All-Time Hall of Fame]', action: 'problem_hof', id: nil ) |
|
5 | 5 | /- else |
|
6 | 6 | / %h1 All-Time Hall of Fame |
|
7 | 7 | |
|
8 | 8 | |
|
9 |
- %h1 |
|
|
9 | + %h1 Hall of Fame | |
|
10 | 10 | .task-menu |
|
11 | 11 | Tasks |
|
12 | 12 | %br/ |
|
13 | 13 | - @problems.each do |prob| |
|
14 | 14 | = link_to( "[#{prob.name}]", {id: prob.id}) |
|
15 | 15 | |
|
16 | 16 | - unless params[:id] |
|
17 | 17 | /=render partial: 'all_time_hof' |
|
18 | 18 | Please select a problem. |
|
19 | 19 | - else |
|
20 | 20 | =render partial: 'task_hof' |
|
21 | + %h2 Submission History | |
|
22 | + =render partial: 'application/bar_graph', locals: { histogram: @histogram } | |
|
21 | 23 | |
|
22 | - |
@@ -1,52 +1,66 | |||
|
1 | 1 | - content_for :header do |
|
2 | 2 | = javascript_include_tag 'local_jquery' |
|
3 | 3 | |
|
4 | - %script{:type=>"text/javascript"} | |
|
4 | + :javascript | |
|
5 | 5 | $(function () { |
|
6 | - $('#submission_table').tablesorter({widgets: ['zebra']}); | |
|
6 | + $('#submission_table').tablesorter({widgets: ['zebra']}); | |
|
7 | 7 | }); |
|
8 | 8 | |
|
9 | 9 | :css |
|
10 | 10 | .fix-width { |
|
11 | 11 | font-family: Droid Sans Mono,Consolas, monospace, mono, Courier New, Courier; |
|
12 | 12 | } |
|
13 | 13 | |
|
14 |
- %h1= @user.full_name |
|
|
14 | + %h1= @user.full_name | |
|
15 | 15 | |
|
16 | - %h2 Basic info | |
|
17 | 16 | <b>Login:</b> #{@user.login} <br/> |
|
18 | 17 | <b>Full name:</b> #{@user.full_name} <br /> |
|
19 | 18 | |
|
20 | 19 | |
|
21 | 20 | %h2 Problem Stat |
|
21 | + %table.info | |
|
22 | + %thead | |
|
23 | + %tr.info-head | |
|
24 | + %th Stat | |
|
25 | + %th Value | |
|
26 | + %tbody | |
|
27 | + %tr{class: cycle('info-even','info-odd')} | |
|
28 | + %td.info_param Submissions | |
|
29 | + %td= @summary[:count] | |
|
30 | + %tr{class: cycle('info-even','info-odd')} | |
|
31 | + %td.info_param Solved/Attempted Problem | |
|
32 | + %td #{@summary[:solve]}/#{@summary[:attempt]} (#{(@summary[:solve]*100.0/@summary[:attempt]).round(1)}%) | |
|
22 | 33 | |
|
23 | - %h2 Submissions | |
|
34 | + %h2 Submission History | |
|
35 | + | |
|
36 | + =render partial: 'application/bar_graph', locals: {histogram: @histogram, param: {bar_width: 7}} | |
|
37 | + | |
|
24 | 38 | |
|
25 | 39 | %table.tablesorter-cafe#submission_table |
|
26 | 40 | %thead |
|
27 | 41 | %tr |
|
28 | 42 | %th ID |
|
29 | 43 | %th Problem code |
|
30 | 44 | %th Problem full name |
|
31 | 45 | %th Language |
|
32 | 46 | %th Submitted at |
|
33 | 47 | %th Result |
|
34 | 48 | %th Score |
|
35 | 49 | - if session[:admin] |
|
36 | 50 | %th IP |
|
37 | 51 | %tbody |
|
38 | 52 | - @submission.each do |s| |
|
39 | 53 | - next unless s.problem |
|
40 | 54 | %tr |
|
41 | 55 | %td= link_to "#{s.id}", controller: "graders", action: "submission", id: s.id |
|
42 | - %td= s.problem.name | |
|
56 | + %td= link_to s.problem.name, controller: "problems", action: "stat", id: s.problem | |
|
43 | 57 | %td= s.problem.full_name |
|
44 | 58 | %td= s.language.pretty_name |
|
45 | 59 | %td #{s.submitted_at.strftime('%Y-%m-%d %H:%M')} (#{time_ago_in_words(s.submitted_at)} ago) |
|
46 | 60 | %td.fix-width= s.grader_comment |
|
47 | 61 | %td= (s.points*100)/s.problem.full_score |
|
48 | 62 | - if session[:admin] |
|
49 | 63 | %td= s.ip_address |
|
50 | 64 | |
|
51 | 65 | |
|
52 | 66 |
@@ -1,58 +1,58 | |||
|
1 | 1 | module GraderScript |
|
2 | 2 | |
|
3 | 3 | def self.grader_control_enabled? |
|
4 | 4 | if defined? GRADER_ROOT_DIR |
|
5 | 5 | GRADER_ROOT_DIR != '' |
|
6 | 6 | else |
|
7 | 7 | false |
|
8 | 8 | end |
|
9 | 9 | end |
|
10 | 10 | |
|
11 | 11 | def self.raw_dir |
|
12 | 12 | File.join GRADER_ROOT_DIR, "raw" |
|
13 | 13 | end |
|
14 | 14 | |
|
15 | 15 | def self.call_grader(params) |
|
16 | 16 | if GraderScript.grader_control_enabled? |
|
17 | 17 | cmd = File.join(GRADER_ROOT_DIR, "scripts/grader") + " " + params |
|
18 | 18 | system(cmd) |
|
19 | 19 | end |
|
20 | 20 | end |
|
21 | 21 | |
|
22 | 22 | def self.stop_grader(pid) |
|
23 | 23 | GraderScript.call_grader "stop #{pid}" |
|
24 | 24 | end |
|
25 | 25 | |
|
26 | 26 | def self.stop_graders(pids) |
|
27 | 27 | pid_str = (pids.map { |process| process.pid.to_s }).join ' ' |
|
28 | 28 | GraderScript.call_grader "stop #{pid_str}" |
|
29 | 29 | end |
|
30 | 30 | |
|
31 | 31 | def self.start_grader(env) |
|
32 | - GraderScript.call_grader "#{env} queue &" | |
|
33 | - GraderScript.call_grader "#{env} test_request &" | |
|
32 | + GraderScript.call_grader "#{env} queue --err-log &" | |
|
33 | + GraderScript.call_grader "#{env} test_request -err-log &" | |
|
34 | 34 | end |
|
35 | 35 | |
|
36 | 36 | def self.call_import_problem(problem_name, |
|
37 | 37 | problem_dir, |
|
38 | 38 | time_limit=1, |
|
39 | 39 | memory_limit=32, |
|
40 | 40 | checker_name='text') |
|
41 | 41 | if GraderScript.grader_control_enabled? |
|
42 | 42 | cur_dir = `pwd`.chomp |
|
43 | 43 | Dir.chdir(GRADER_ROOT_DIR) |
|
44 | 44 | |
|
45 | 45 | script_name = File.join(GRADER_ROOT_DIR, "scripts/import_problem") |
|
46 | 46 | cmd = "#{script_name} #{problem_name} #{problem_dir} #{checker_name}" + |
|
47 | 47 | " -t #{time_limit} -m #{memory_limit}" |
|
48 | 48 | |
|
49 | 49 | output = `#{cmd}` |
|
50 | 50 | |
|
51 | 51 | Dir.chdir(cur_dir) |
|
52 | 52 | |
|
53 | 53 | return "import CMD: #{cmd}\n" + output |
|
54 | 54 | end |
|
55 | 55 | return '' |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | end |
You need to be logged in to leave comments.
Login now