Description:
Fix bug #23, #22, #21, #17
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r730:7917a0f3fcef - - 4 files changed: 4 inserted, 2 deleted

@@ -1,310 +1,310
1 1 class ProblemsController < ApplicationController
2 2
3 3 before_action :authenticate, :authorization
4 4 before_action :testcase_authorization, only: [:show_testcase]
5 5
6 6 in_place_edit_for :problem, :name
7 7 in_place_edit_for :problem, :full_name
8 8 in_place_edit_for :problem, :full_score
9 9
10 10 def index
11 11 @problems = Problem.order(date_added: :desc)
12 12 end
13 13
14 14 # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
15 15 verify :method => :post, :only => [ :create, :quick_create,
16 16 :do_manage,
17 17 :do_import,
18 18 ],
19 19 :redirect_to => { :action => :index }
20 20
21 21 def show
22 22 @problem = Problem.find(params[:id])
23 23 end
24 24
25 25 def new
26 26 @problem = Problem.new
27 27 @description = nil
28 28 end
29 29
30 30 def create
31 31 @problem = Problem.new(problem_params)
32 32 @description = Description.new(params[:description])
33 33 if @description.body!=''
34 34 if !@description.save
35 35 render :action => new and return
36 36 end
37 37 else
38 38 @description = nil
39 39 end
40 40 @problem.description = @description
41 41 if @problem.save
42 42 flash[:notice] = 'Problem was successfully created.'
43 43 redirect_to action: :index
44 44 else
45 45 render :action => 'new'
46 46 end
47 47 end
48 48
49 49 def quick_create
50 50 @problem = Problem.new(problem_params)
51 51 @problem.full_name = @problem.name if @problem.full_name == ''
52 52 @problem.full_score = 100
53 53 @problem.available = false
54 54 @problem.test_allowed = true
55 55 @problem.output_only = false
56 56 @problem.date_added = Time.new
57 57 if @problem.save
58 58 flash[:notice] = 'Problem was successfully created.'
59 59 redirect_to action: :index
60 60 else
61 61 flash[:notice] = 'Error saving problem'
62 62 redirect_to action: :index
63 63 end
64 64 end
65 65
66 66 def edit
67 67 @problem = Problem.find(params[:id])
68 68 @description = @problem.description
69 69 end
70 70
71 71 def update
72 72 @problem = Problem.find(params[:id])
73 73 @description = @problem.description
74 74 if @description.nil? and params[:description][:body]!=''
75 75 @description = Description.new(params[:description])
76 76 if !@description.save
77 77 flash[:notice] = 'Error saving description'
78 78 render :action => 'edit' and return
79 79 end
80 80 @problem.description = @description
81 81 elsif @description
82 82 if !@description.update_attributes(params[:description])
83 83 flash[:notice] = 'Error saving description'
84 84 render :action => 'edit' and return
85 85 end
86 86 end
87 87 if params[:file] and params[:file].content_type != 'application/pdf'
88 88 flash[:notice] = 'Error: Uploaded file is not PDF'
89 89 render :action => 'edit' and return
90 90 end
91 91 if @problem.update_attributes(problem_params)
92 92 flash[:notice] = 'Problem was successfully updated.'
93 93 unless params[:file] == nil or params[:file] == ''
94 94 flash[:notice] = 'Problem was successfully updated and a new PDF file is uploaded.'
95 95 out_dirname = "#{Problem.download_file_basedir}/#{@problem.id}"
96 96 if not FileTest.exists? out_dirname
97 97 Dir.mkdir out_dirname
98 98 end
99 99
100 100 out_filename = "#{out_dirname}/#{@problem.name}.pdf"
101 101 if FileTest.exists? out_filename
102 102 File.delete out_filename
103 103 end
104 104
105 105 File.open(out_filename,"wb") do |file|
106 106 file.write(params[:file].read)
107 107 end
108 108 @problem.description_filename = "#{@problem.name}.pdf"
109 109 @problem.save
110 110 end
111 111 redirect_to :action => 'show', :id => @problem
112 112 else
113 113 render :action => 'edit'
114 114 end
115 115 end
116 116
117 117 def destroy
118 118 p = Problem.find(params[:id]).destroy
119 119 redirect_to action: :index
120 120 end
121 121
122 122 def toggle
123 123 @problem = Problem.find(params[:id])
124 124 @problem.update_attributes(available: !(@problem.available) )
125 125 respond_to do |format|
126 126 format.js { }
127 127 end
128 128 end
129 129
130 130 def toggle_test
131 131 @problem = Problem.find(params[:id])
132 132 @problem.update_attributes(test_allowed: !(@problem.test_allowed?) )
133 133 respond_to do |format|
134 134 format.js { }
135 135 end
136 136 end
137 137
138 138 def toggle_view_testcase
139 139 @problem = Problem.find(params[:id])
140 140 @problem.update_attributes(view_testcase: !(@problem.view_testcase?) )
141 141 respond_to do |format|
142 142 format.js { }
143 143 end
144 144 end
145 145
146 146 def turn_all_off
147 147 Problem.available.all.each do |problem|
148 148 problem.available = false
149 149 problem.save
150 150 end
151 151 redirect_to action: :index
152 152 end
153 153
154 154 def turn_all_on
155 155 Problem.where.not(available: true).each do |problem|
156 156 problem.available = true
157 157 problem.save
158 158 end
159 159 redirect_to action: :index
160 160 end
161 161
162 162 def stat
163 163 @problem = Problem.find(params[:id])
164 164 unless @problem.available or session[:admin]
165 165 redirect_to :controller => 'main', :action => 'list'
166 166 return
167 167 end
168 168 @submissions = Submission.includes(:user).includes(:language).where(problem_id: params[:id]).order(:user_id,:id)
169 169
170 170 #stat summary
171 171 range =65
172 172 @histogram = { data: Array.new(range,0), summary: {} }
173 173 user = Hash.new(0)
174 174 @submissions.find_each do |sub|
175 175 d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
176 176 @histogram[:data][d.to_i] += 1 if d < range
177 177 user[sub.user_id] = [user[sub.user_id], ((sub.try(:points) || 0) >= @problem.full_score) ? 1 : 0].max
178 178 end
179 179 @histogram[:summary][:max] = [@histogram[:data].max,1].max
180 180
181 181 @summary = { attempt: user.count, solve: 0 }
182 182 user.each_value { |v| @summary[:solve] += 1 if v == 1 }
183 183 end
184 184
185 185 def manage
186 186 @problems = Problem.order(date_added: :desc)
187 187 end
188 188
189 189 def do_manage
190 - if params.has_key? 'change_date_added'
190 + if params.has_key? 'change_date_added' and params[:date_added].strip.empty? == false
191 191 change_date_added
192 192 elsif params.has_key? 'add_to_contest'
193 193 add_to_contest
194 194 elsif params.has_key? 'enable_problem'
195 195 set_available(true)
196 196 elsif params.has_key? 'disable_problem'
197 197 set_available(false)
198 198 elsif params.has_key? 'add_group'
199 199 group = Group.find(params[:group_id])
200 200 ok = []
201 201 failed = []
202 202 get_problems_from_params.each do |p|
203 203 begin
204 204 group.problems << p
205 205 ok << p.full_name
206 206 rescue => e
207 207 failed << p.full_name
208 208 end
209 209 end
210 210 flash[:success] = "The following problems are added to the group #{group.name}: " + ok.join(', ') if ok.count > 0
211 211 flash[:alert] = "The following problems are already in the group #{group.name}: " + failed.join(', ') if failed.count > 0
212 212 elsif params.has_key? 'add_tags'
213 213 get_problems_from_params.each do |p|
214 214 p.tag_ids += params[:tag_ids]
215 215 end
216 216 end
217 217
218 218 redirect_to :action => 'manage'
219 219 end
220 220
221 221 def import
222 222 @allow_test_pair_import = allow_test_pair_import?
223 223 end
224 224
225 225 def do_import
226 226 old_problem = Problem.find_by_name(params[:name])
227 227 if !allow_test_pair_import? and params.has_key? :import_to_db
228 228 params.delete :import_to_db
229 229 end
230 230 @problem, import_log = Problem.create_from_import_form_params(params,
231 231 old_problem)
232 232
233 233 if !@problem.errors.empty?
234 234 render :action => 'import' and return
235 235 end
236 236
237 237 if old_problem!=nil
238 238 flash[:notice] = "The test data has been replaced for problem #{@problem.name}"
239 239 end
240 240 @log = import_log
241 241 end
242 242
243 243 def remove_contest
244 244 problem = Problem.find(params[:id])
245 245 contest = Contest.find(params[:contest_id])
246 246 if problem!=nil and contest!=nil
247 247 problem.contests.delete(contest)
248 248 end
249 249 redirect_to :action => 'manage'
250 250 end
251 251
252 252 ##################################
253 253 protected
254 254
255 255 def allow_test_pair_import?
256 256 if defined? ALLOW_TEST_PAIR_IMPORT
257 257 return ALLOW_TEST_PAIR_IMPORT
258 258 else
259 259 return false
260 260 end
261 261 end
262 262
263 263 def change_date_added
264 264 problems = get_problems_from_params
265 265 date = Date.parse(params[:date_added])
266 266 problems.each do |p|
267 267 p.date_added = date
268 268 p.save
269 269 end
270 270 end
271 271
272 272 def add_to_contest
273 273 problems = get_problems_from_params
274 274 contest = Contest.find(params[:contest][:id])
275 275 if contest!=nil and contest.enabled
276 276 problems.each do |p|
277 277 p.contests << contest
278 278 end
279 279 end
280 280 end
281 281
282 282 def set_available(avail)
283 283 problems = get_problems_from_params
284 284 problems.each do |p|
285 285 p.available = avail
286 286 p.save
287 287 end
288 288 end
289 289
290 290 def get_problems_from_params
291 291 problems = []
292 292 params.keys.each do |k|
293 293 if k.index('prob-')==0
294 294 name, id, order = k.split('-')
295 295 problems << Problem.find(id)
296 296 end
297 297 end
298 298 problems
299 299 end
300 300
301 301 def get_problems_stat
302 302 end
303 303
304 304 private
305 305
306 306 def problem_params
307 307 params.require(:problem).permit(:name, :full_name, :full_score, :date_added, :available, :test_allowed,:output_only, :url, :description, tag_ids:[])
308 308 end
309 309
310 310 end
@@ -1,430 +1,430
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, :current_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 37 if params[:problem_id]
38 38 params[:problem_id].each do |id|
39 39 next unless id.strip != ""
40 40 pid = Problem.find_by_id(id.to_i)
41 41 @problems << pid if pid
42 42 end
43 43 end
44 44
45 45 #users
46 - @users = if params[:user] == "all" then
46 + @users = if params[:users] == "all" then
47 47 User.includes(:contests).includes(:contest_stat)
48 48 else
49 49 User.includes(:contests).includes(:contest_stat).where(enabled: true)
50 50 end
51 51
52 52 #set up range from param
53 53 @since_id = params.fetch(:from_id, 0).to_i
54 54 @until_id = params.fetch(:to_id, 0).to_i
55 55 @since_id = nil if @since_id == 0
56 56 @until_id = nil if @until_id == 0
57 57
58 58 #calculate the routine
59 59 @scorearray = calculate_max_score(@problems, @users, @since_id, @until_id)
60 60
61 61 #rencer accordingly
62 62 if params[:button] == 'download' then
63 63 csv = gen_csv_from_scorearray(@scorearray,@problems)
64 64 send_data csv, filename: 'max_score.csv'
65 65 else
66 66 #render template: 'user_admin/user_stat'
67 67 render 'max_score'
68 68 end
69 69
70 70 end
71 71
72 72 def score
73 73 if params[:commit] == 'download csv'
74 74 @problems = Problem.all
75 75 else
76 76 @problems = Problem.available_problems
77 77 end
78 78 @users = User.includes(:contests, :contest_stat).where(enabled: true)
79 79 @scorearray = Array.new
80 80 @users.each do |u|
81 81 ustat = Array.new
82 82 ustat[0] = u
83 83 @problems.each do |p|
84 84 sub = Submission.find_last_by_user_and_problem(u.id,p.id)
85 85 if (sub!=nil) and (sub.points!=nil) and p and p.full_score
86 86 ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)]
87 87 else
88 88 ustat << [0,false]
89 89 end
90 90 end
91 91 @scorearray << ustat
92 92 end
93 93 if params[:commit] == 'download csv' then
94 94 csv = gen_csv_from_scorearray(@scorearray,@problems)
95 95 send_data csv, filename: 'last_score.csv'
96 96 else
97 97 render template: 'user_admin/user_stat'
98 98 end
99 99
100 100 end
101 101
102 102 def login_stat
103 103 @logins = Array.new
104 104
105 105 date_and_time = '%Y-%m-%d %H:%M'
106 106 begin
107 107 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
108 108 @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)
109 109 rescue
110 110 @since_time = DateTime.new(1000,1,1)
111 111 end
112 112 begin
113 113 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
114 114 @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)
115 115 rescue
116 116 @until_time = DateTime.new(3000,1,1)
117 117 end
118 118
119 119 User.all.each do |user|
120 120 @logins << { id: user.id,
121 121 login: user.login,
122 122 full_name: user.full_name,
123 123 count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
124 124 user.id,@since_time,@until_time)
125 125 .count(:id),
126 126 min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
127 127 user.id,@since_time,@until_time)
128 128 .minimum(:created_at),
129 129 max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
130 130 user.id,@since_time,@until_time)
131 131 .maximum(:created_at),
132 132 ip: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?",
133 133 user.id,@since_time,@until_time)
134 134 .select(:ip_address).uniq
135 135
136 136 }
137 137 end
138 138 end
139 139
140 140 def submission_stat
141 141
142 142 date_and_time = '%Y-%m-%d %H:%M'
143 143 begin
144 144 @since_time = DateTime.strptime(params[:since_datetime],date_and_time)
145 145 rescue
146 146 @since_time = DateTime.new(1000,1,1)
147 147 end
148 148 begin
149 149 @until_time = DateTime.strptime(params[:until_datetime],date_and_time)
150 150 rescue
151 151 @until_time = DateTime.new(3000,1,1)
152 152 end
153 153
154 154 @submissions = {}
155 155
156 156 User.find_each do |user|
157 157 @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } }
158 158 end
159 159
160 160 Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s|
161 161 if @submissions[s.user_id]
162 162 if not @submissions[s.user_id][:sub].has_key?(s.problem_id)
163 163 a = Problem.find_by_id(s.problem_id)
164 164 @submissions[s.user_id][:sub][s.problem_id] =
165 165 { prob_name: (a ? a.full_name : '(NULL)'),
166 166 sub_ids: [s.id] }
167 167 else
168 168 @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id
169 169 end
170 170 @submissions[s.user_id][:count] += 1
171 171 end
172 172 end
173 173 end
174 174
175 175 def problem_hof
176 176 # gen problem list
177 177 @user = User.find(session[:user_id])
178 178 @problems = @user.available_problems
179 179
180 180 # get selected problems or the default
181 181 if params[:id]
182 182 begin
183 183 @problem = Problem.available.find(params[:id])
184 184 rescue
185 185 redirect_to action: :problem_hof
186 186 flash[:notice] = 'Error: submissions for that problem are not viewable.'
187 187 return
188 188 end
189 189 end
190 190
191 191 return unless @problem
192 192
193 193 @by_lang = {} #aggregrate by language
194 194
195 195 range =65
196 196 @histogram = { data: Array.new(range,0), summary: {} }
197 197 @summary = {count: 0, solve: 0, attempt: 0}
198 198 user = Hash.new(0)
199 199 Submission.where(problem_id: @problem.id).find_each do |sub|
200 200 #histogram
201 201 d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60
202 202 @histogram[:data][d.to_i] += 1 if d < range
203 203
204 204 next unless sub.points
205 205 @summary[:count] += 1
206 206 user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max
207 207
208 208 lang = Language.find_by_id(sub.language_id)
209 209 next unless lang
210 210 next unless sub.points >= @problem.full_score
211 211
212 212 #initialize
213 213 unless @by_lang.has_key?(lang.pretty_name)
214 214 @by_lang[lang.pretty_name] = {
215 215 runtime: { avail: false, value: 2**30-1 },
216 216 memory: { avail: false, value: 2**30-1 },
217 217 length: { avail: false, value: 2**30-1 },
218 218 first: { avail: false, value: DateTime.new(3000,1,1) }
219 219 }
220 220 end
221 221
222 222 if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value]
223 223 @by_lang[lang.pretty_name][:runtime] = { avail: true, user_id: sub.user_id, value: sub.max_runtime, sub_id: sub.id }
224 224 end
225 225
226 226 if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value]
227 227 @by_lang[lang.pretty_name][:memory] = { avail: true, user_id: sub.user_id, value: sub.peak_memory, sub_id: sub.id }
228 228 end
229 229
230 230 if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and sub.user and
231 231 !sub.user.admin?
232 232 @by_lang[lang.pretty_name][:first] = { avail: true, user_id: sub.user_id, value: sub.submitted_at, sub_id: sub.id }
233 233 end
234 234
235 235 if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length
236 236 @by_lang[lang.pretty_name][:length] = { avail: true, user_id: sub.user_id, value: sub.effective_code_length, sub_id: sub.id }
237 237 end
238 238 end
239 239
240 240 #process user_id
241 241 @by_lang.each do |lang,prop|
242 242 prop.each do |k,v|
243 243 v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)"
244 244 end
245 245 end
246 246
247 247 #sum into best
248 248 if @by_lang and @by_lang.first
249 249 @best = @by_lang.first[1].clone
250 250 @by_lang.each do |lang,prop|
251 251 if @best[:runtime][:value] >= prop[:runtime][:value]
252 252 @best[:runtime] = prop[:runtime]
253 253 @best[:runtime][:lang] = lang
254 254 end
255 255 if @best[:memory][:value] >= prop[:memory][:value]
256 256 @best[:memory] = prop[:memory]
257 257 @best[:memory][:lang] = lang
258 258 end
259 259 if @best[:length][:value] >= prop[:length][:value]
260 260 @best[:length] = prop[:length]
261 261 @best[:length][:lang] = lang
262 262 end
263 263 if @best[:first][:value] >= prop[:first][:value]
264 264 @best[:first] = prop[:first]
265 265 @best[:first][:lang] = lang
266 266 end
267 267 end
268 268 end
269 269
270 270 @histogram[:summary][:max] = [@histogram[:data].max,1].max
271 271 @summary[:attempt] = user.count
272 272 user.each_value { |v| @summary[:solve] += 1 if v == 1 }
273 273 end
274 274
275 275 def stuck #report struggling user,problem
276 276 # init
277 277 user,problem = nil
278 278 solve = true
279 279 tries = 0
280 280 @struggle = Array.new
281 281 record = {}
282 282 Submission.includes(:problem,:user).order(:problem_id,:user_id).find_each do |sub|
283 283 next unless sub.problem and sub.user
284 284 if user != sub.user_id or problem != sub.problem_id
285 285 @struggle << { user: record[:user], problem: record[:problem], tries: tries } unless solve
286 286 record = {user: sub.user, problem: sub.problem}
287 287 user,problem = sub.user_id, sub.problem_id
288 288 solve = false
289 289 tries = 0
290 290 end
291 291 if sub.points >= sub.problem.full_score
292 292 solve = true
293 293 else
294 294 tries += 1
295 295 end
296 296 end
297 297 @struggle.sort!{|a,b| b[:tries] <=> a[:tries] }
298 298 @struggle = @struggle[0..50]
299 299 end
300 300
301 301
302 302 def multiple_login
303 303 #user with multiple IP
304 304 raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:login)
305 305 last,count = 0,0
306 306 first = 0
307 307 @users = []
308 308 raw.each do |r|
309 309 if last != r.user.login
310 310 count = 1
311 311 last = r.user.login
312 312 first = r
313 313 else
314 314 @users << first if count == 1
315 315 @users << r
316 316 count += 1
317 317 end
318 318 end
319 319
320 320 #IP with multiple user
321 321 raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:ip_address)
322 322 last,count = 0,0
323 323 first = 0
324 324 @ip = []
325 325 raw.each do |r|
326 326 if last != r.ip_address
327 327 count = 1
328 328 last = r.ip_address
329 329 first = r
330 330 else
331 331 @ip << first if count == 1
332 332 @ip << r
333 333 count += 1
334 334 end
335 335 end
336 336 end
337 337
338 338 def cheat_report
339 339 date_and_time = '%Y-%m-%d %H:%M'
340 340 begin
341 341 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
342 342 @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)
343 343 rescue
344 344 @since_time = Time.zone.now.ago( 90.minutes)
345 345 end
346 346 begin
347 347 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
348 348 @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)
349 349 rescue
350 350 @until_time = Time.zone.now
351 351 end
352 352
353 353 #multi login
354 354 @ml = Login.joins(:user).where("logins.created_at >= ? and logins.created_at <= ?",@since_time,@until_time).select('users.login,count(distinct ip_address) as count,users.full_name').group("users.id").having("count > 1")
355 355
356 356 st = <<-SQL
357 357 SELECT l2.*
358 358 FROM logins l2 INNER JOIN
359 359 (SELECT u.id,COUNT(DISTINCT ip_address) as count,u.login,u.full_name
360 360 FROM logins l
361 361 INNER JOIN users u ON l.user_id = u.id
362 362 WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}'
363 363 GROUP BY u.id
364 364 HAVING count > 1
365 365 ) ml ON l2.user_id = ml.id
366 366 WHERE l2.created_at >= '#{@since_time.in_time_zone("UTC")}' and l2.created_at <= '#{@until_time.in_time_zone("UTC")}'
367 367 UNION
368 368 SELECT l2.*
369 369 FROM logins l2 INNER JOIN
370 370 (SELECT l.ip_address,COUNT(DISTINCT u.id) as count
371 371 FROM logins l
372 372 INNER JOIN users u ON l.user_id = u.id
373 373 WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}'
374 374 GROUP BY l.ip_address
375 375 HAVING count > 1
376 376 ) ml on ml.ip_address = l2.ip_address
377 377 INNER JOIN users u ON l2.user_id = u.id
378 378 WHERE l2.created_at >= '#{@since_time.in_time_zone("UTC")}' and l2.created_at <= '#{@until_time.in_time_zone("UTC")}'
379 379 ORDER BY ip_address,created_at
380 380 SQL
381 381 @mld = Login.find_by_sql(st)
382 382
383 383 st = <<-SQL
384 384 SELECT s.id,s.user_id,s.ip_address,s.submitted_at,s.problem_id
385 385 FROM submissions s INNER JOIN
386 386 (SELECT u.id,COUNT(DISTINCT ip_address) as count,u.login,u.full_name
387 387 FROM logins l
388 388 INNER JOIN users u ON l.user_id = u.id
389 389 WHERE l.created_at >= ? and l.created_at <= ?
390 390 GROUP BY u.id
391 391 HAVING count > 1
392 392 ) ml ON s.user_id = ml.id
393 393 WHERE s.submitted_at >= ? and s.submitted_at <= ?
394 394 UNION
395 395 SELECT s.id,s.user_id,s.ip_address,s.submitted_at,s.problem_id
396 396 FROM submissions s INNER JOIN
397 397 (SELECT l.ip_address,COUNT(DISTINCT u.id) as count
398 398 FROM logins l
399 399 INNER JOIN users u ON l.user_id = u.id
400 400 WHERE l.created_at >= ? and l.created_at <= ?
401 401 GROUP BY l.ip_address
402 402 HAVING count > 1
403 403 ) ml on ml.ip_address = s.ip_address
404 404 WHERE s.submitted_at >= ? and s.submitted_at <= ?
405 405 ORDER BY ip_address,submitted_at
406 406 SQL
407 407 @subs = Submission.joins(:problem).find_by_sql([st,@since_time,@until_time,
408 408 @since_time,@until_time,
409 409 @since_time,@until_time,
410 410 @since_time,@until_time])
411 411
412 412 end
413 413
414 414 def cheat_scruntinize
415 415 #convert date & time
416 416 date_and_time = '%Y-%m-%d %H:%M'
417 417 begin
418 418 md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
419 419 @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)
420 420 rescue
421 421 @since_time = Time.zone.now.ago( 90.minutes)
422 422 end
423 423 begin
424 424 md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/)
425 425 @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)
426 426 rescue
427 427 @until_time = Time.zone.now
428 428 end
429 429
430 430 #convert sid
@@ -1,118 +1,119
1 1 - content_for :head do
2 2 = stylesheet_link_tag 'problems'
3 3 = javascript_include_tag 'local_jquery'
4 4
5 5 :javascript
6 6 $(document).ready( function() {
7 7 function shiftclick(start,stop,value) {
8 8 $('tr input').each( function(id,input) {
9 9 var $input=$(input);
10 10 var iid=parseInt($input.attr('id').split('-')[2]);
11 11 if(iid>=start&&iid<=stop){
12 12 $input.prop('checked',value)
13 13 }
14 14 });
15 15 }
16 16
17 17 $('tr input').click( function(e) {
18 18 if (e.shiftKey) {
19 19 stop = parseInt($(this).attr('id').split('-')[2]);
20 20 var orig_stop = stop
21 21 if (typeof start !== 'undefined') {
22 22 if (start > stop) {
23 23 var tmp = start;
24 24 start = stop;
25 25 stop = tmp;
26 26 }
27 27 shiftclick(start,stop,$(this).is(':checked') )
28 28 }
29 29 start = orig_stop
30 30 } else {
31 31 start = parseInt($(this).attr('id').split('-')[2]);
32 32 }
33 33 });
34 34 });
35 35
36 36
37 37 %h1 Manage problems
38 38
39 39 %p= link_to '[Back to problem list]', problems_path
40 40
41 41 = form_tag :action=>'do_manage' do
42 42 .panel.panel-primary
43 43 .panel-heading
44 44 Action
45 45 .panel-body
46 46 .submit-box
47 47 What do you want to do to the selected problem?
48 48 %br/
49 49 (You can shift-click to select a range of problems)
50 50 %ul.form-inline
51 51 %li
52 52 Change "Date added" to
53 53 .input-group.date
54 54 = text_field_tag :date_added, class: 'form-control'
55 55 %span.input-group-addon
56 56 %span.glyphicon.glyphicon-calendar
57 57 -# = select_date Date.current, :prefix => 'date_added'
58 58 &nbsp;&nbsp;&nbsp;
59 59 = submit_tag 'Change', :name => 'change_date_added', class: 'btn btn-primary btn-sm'
60 60 %li
61 61 Set "Available" to
62 62 = submit_tag 'True', :name => 'enable_problem', class: 'btn btn-primary btn-sm'
63 63 = submit_tag 'False', :name => 'disable_problem', class: 'btn btn-primary btn-sm'
64 64
65 65 - if GraderConfiguration.multicontests?
66 66 %li
67 67 Add selected problems to contest
68 68 = select("contest","id",Contest.all.collect {|c| [c.title, c.id]})
69 69 = submit_tag 'Add', :name => 'add_to_contest', class: 'btn btn-primary btn-sm'
70 70 %li
71 71 Add selected problems to user group
72 72 = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_name]), id: 'group_name',class: 'select2'
73 73 = submit_tag 'Add', name: 'add_group', class: 'btn btn-primary'
74 74 %li
75 75 Add the following tags to the selected problems
76 76 = select_tag "tag_ids", options_from_collection_for_select( Tag.all, 'id','name'), id: 'tags_name',class: 'select2', multiple: true, data: {placeholder: 'Select tags by clicking', width: "200px"}
77 77 = submit_tag 'Add', name: 'add_tags', class: 'btn btn-primary'
78 78
79 79 %table.table.table-hover.datatable
80 80 %thead
81 81 %tr{style: "text-align: left;"}
82 82 %th= check_box_tag 'select_all'
83 83 %th Name
84 84 %th Full name
85 85 %th Tags
86 86 %th Available
87 87 %th Date added
88 88 - if GraderConfiguration.multicontests?
89 89 %th Contests
90 90
91 91 %tbody
92 92 - num = 0
93 93 - for problem in @problems
94 94 - num += 1
95 95 %tr{:id => "row-prob-#{problem.id}", :name=> "prob-#{problem.id}"}
96 96 %td= check_box_tag "prob-#{problem.id}-#{num}"
97 97 %td= problem.name
98 98 %td= problem.full_name
99 99 %td
100 100 - problem.tags.each do |t|
101 101 %span.label.label-default= t.name
102 102 %td= problem.available
103 103 %td= problem.date_added
104 104 - if GraderConfiguration.multicontests?
105 105 %td
106 106 - problem.contests.each do |contest|
107 107 = "(#{contest.name} [#{link_to 'x', :action => 'remove_contest', :id => problem.id, :contest_id => contest.id }])"
108 108
109 109 :javascript
110 110 $('.input-group.date').datetimepicker({
111 111 format: 'DD/MMM/YYYY',
112 112 showTodayButton: true,
113 + locale: 'en',
113 114 widgetPositioning: {horizontal: 'auto', vertical: 'bottom'},
114 115
115 116 });
116 117 $('.datatable').DataTable({
117 118 paging: false
118 119 });
@@ -1,36 +1,37
1 1 %h1 Editing site
2 2 = error_messages_for :site
3 3 = form_for(@site) do |f|
4 4 .row
5 5 .col-md-4
6 6 .form-group.field
7 7 = f.label :name, "Name"
8 8 = f.text_field :name, class: 'form-control'
9 9 .form-group.field
10 10 = f.label :password, "Password"
11 11 = f.text_field :password, class: 'form-control'
12 12 .form-group.field
13 13 = f.label :started, "Started"
14 14 = f.check_box :started, class: 'form-control'
15 15 .form-group.field
16 16 = f.label :start_time, "Start time"
17 17 -# = f.datetime_select :start_time, :include_blank => true
18 18 .input-group.date
19 19 = f.text_field :start_time, class:'form-control' , value: (@site.start_time ? @site.start_time.strftime('%d/%b/%Y %H:%M') : '')
20 20 %span.input-group-addon
21 21 %span.glyphicon.glyphicon-calendar
22 22 .actions
23 23 = f.submit "Update", class: 'btn btn-primary'
24 24 .col-md-8
25 25
26 26 = link_to 'Show', @site
27 27 |
28 28 = link_to 'Back', sites_path
29 29
30 30
31 31 :javascript
32 32 $('.input-group.date').datetimepicker({
33 33 format: 'DD/MMM/YYYY HH:mm',
34 + locale: 'en',
34 35 showTodayButton: true,
35 36 });
36 37
You need to be logged in to leave comments. Login now