Description:
merge
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r837:b9faf3362123 - - 7 files changed: 24 inserted, 11 deleted
@@ -1,369 +1,369 | |||
|
1 | 1 | class MainController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_action :check_valid_login, :except => [:login] |
|
4 | 4 | before_action :check_viewability, :except => [:index, :login] |
|
5 | 5 | |
|
6 | 6 | append_before_action :confirm_and_update_start_time, |
|
7 | 7 | :except => [:index, |
|
8 | 8 | :login, |
|
9 | 9 | :confirm_contest_start] |
|
10 | 10 | |
|
11 | 11 | # to prevent log in box to be shown when user logged out of the |
|
12 | 12 | # system only in some tab |
|
13 | 13 | prepend_before_action :reject_announcement_refresh_when_logged_out, |
|
14 | 14 | :only => [:announcements] |
|
15 | 15 | |
|
16 | 16 | before_action :authenticate_by_ip_address, :only => [:list] |
|
17 | 17 | |
|
18 | 18 | #reset login, clear session |
|
19 | 19 | #front page |
|
20 | 20 | def login |
|
21 | 21 | saved_notice = flash[:notice] |
|
22 | 22 | reset_session |
|
23 | 23 | flash.now[:notice] = saved_notice |
|
24 | 24 | @remote_ip = request.remote_ip |
|
25 | 25 | |
|
26 | 26 | # EXPERIMENT: |
|
27 | 27 | # Hide login if in single user mode and the url does not |
|
28 | 28 | # explicitly specify /login |
|
29 | 29 | # |
|
30 | 30 | # logger.info "PATH: #{request.path}" |
|
31 | 31 | # if GraderConfiguration['system.single_user_mode'] and |
|
32 | 32 | # request.path!='/main/login' |
|
33 | 33 | # @hidelogin = true |
|
34 | 34 | # end |
|
35 | 35 | |
|
36 | 36 | @announcements = Announcement.frontpage |
|
37 | 37 | render :action => 'login', :layout => 'empty' |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | def logout |
|
41 | 41 | reset_session |
|
42 | 42 | redirect_to root_path |
|
43 | 43 | end |
|
44 | 44 | |
|
45 | 45 | def list |
|
46 | 46 | prepare_list_information |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | def help |
|
50 | 50 | @user = User.find(session[:user_id]) |
|
51 | 51 | end |
|
52 | 52 | |
|
53 | 53 | def submit |
|
54 | 54 | user = User.find(session[:user_id]) |
|
55 | 55 | |
|
56 | 56 | @submission = Submission.new |
|
57 | 57 | @submission.problem_id = params[:submission][:problem_id] |
|
58 | 58 | @submission.user = user |
|
59 | 59 | @submission.language_id = 0 |
|
60 | 60 | if (params['file']) and (params['file']!='') |
|
61 | 61 | @submission.source = File.open(params['file'].path,'r:UTF-8',&:read) |
|
62 | 62 | @submission.source.encode!('UTF-8','UTF-8',invalid: :replace, replace: '') |
|
63 | 63 | @submission.source_filename = params['file'].original_filename |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | if (params[:editor_text]) |
|
67 | 67 | language = Language.find_by_id(params[:language_id]) |
|
68 | 68 | @submission.source = params[:editor_text] |
|
69 | 69 | @submission.source_filename = "live_edit.#{language.ext}" |
|
70 | 70 | @submission.language = language |
|
71 | 71 | end |
|
72 | 72 | |
|
73 | 73 | @submission.submitted_at = Time.new.gmtime |
|
74 | 74 | @submission.ip_address = request.remote_ip |
|
75 | 75 | |
|
76 |
- if GraderConfiguration.time_limit_mode? |
|
|
76 | + if @current_user.admin? == false && GraderConfiguration.time_limit_mode? && @current_user.contest_finished? | |
|
77 | 77 | @submission.errors.add(:base,"The contest is over.") |
|
78 | 78 | prepare_list_information |
|
79 | 79 | render :action => 'list' and return |
|
80 | 80 | end |
|
81 | 81 | |
|
82 | 82 | if @submission.valid?(@current_user) |
|
83 | 83 | if @submission.save == false |
|
84 | 84 | flash[:notice] = 'Error saving your submission' |
|
85 | 85 | elsif Task.create(:submission_id => @submission.id, |
|
86 | 86 | :status => Task::STATUS_INQUEUE) == false |
|
87 | 87 | flash[:notice] = 'Error adding your submission to task queue' |
|
88 | 88 | end |
|
89 | 89 | else |
|
90 | 90 | prepare_list_information |
|
91 | 91 | render :action => 'list' and return |
|
92 | 92 | end |
|
93 | 93 | redirect_to edit_submission_path(@submission) |
|
94 | 94 | end |
|
95 | 95 | |
|
96 | 96 | def source |
|
97 | 97 | submission = Submission.find(params[:id]) |
|
98 | 98 | if ((submission.user_id == session[:user_id]) and |
|
99 | 99 | (submission.problem != nil) and |
|
100 | 100 | (submission.problem.available)) |
|
101 | 101 | send_data(submission.source, |
|
102 | 102 | {:filename => submission.download_filename, |
|
103 | 103 | :type => 'text/plain'}) |
|
104 | 104 | else |
|
105 | 105 | flash[:notice] = 'Error viewing source' |
|
106 | 106 | redirect_to :action => 'list' |
|
107 | 107 | end |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | def compiler_msg |
|
111 | 111 | @submission = Submission.find(params[:id]) |
|
112 | 112 | if @submission.user_id == session[:user_id] |
|
113 | 113 | render :action => 'compiler_msg', :layout => 'empty' |
|
114 | 114 | else |
|
115 | 115 | flash[:notice] = 'Error viewing source' |
|
116 | 116 | redirect_to :action => 'list' |
|
117 | 117 | end |
|
118 | 118 | end |
|
119 | 119 | |
|
120 | 120 | def result |
|
121 | 121 | if !GraderConfiguration.show_grading_result |
|
122 | 122 | redirect_to :action => 'list' and return |
|
123 | 123 | end |
|
124 | 124 | @user = User.find(session[:user_id]) |
|
125 | 125 | @submission = Submission.find(params[:id]) |
|
126 | 126 | if @submission.user!=@user |
|
127 | 127 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
128 | 128 | redirect_to :action => 'list' and return |
|
129 | 129 | end |
|
130 | 130 | prepare_grading_result(@submission) |
|
131 | 131 | end |
|
132 | 132 | |
|
133 | 133 | def load_output |
|
134 | 134 | if !GraderConfiguration.show_grading_result or params[:num]==nil |
|
135 | 135 | redirect_to :action => 'list' and return |
|
136 | 136 | end |
|
137 | 137 | @user = User.find(session[:user_id]) |
|
138 | 138 | @submission = Submission.find(params[:id]) |
|
139 | 139 | if @submission.user!=@user |
|
140 | 140 | flash[:notice] = 'You are not allowed to view result of other users.' |
|
141 | 141 | redirect_to :action => 'list' and return |
|
142 | 142 | end |
|
143 | 143 | case_num = params[:num].to_i |
|
144 | 144 | out_filename = output_filename(@user.login, |
|
145 | 145 | @submission.problem.name, |
|
146 | 146 | @submission.id, |
|
147 | 147 | case_num) |
|
148 | 148 | if !FileTest.exists?(out_filename) |
|
149 | 149 | flash[:notice] = 'Output not found.' |
|
150 | 150 | redirect_to :action => 'list' and return |
|
151 | 151 | end |
|
152 | 152 | |
|
153 | 153 | if defined?(USE_APACHE_XSENDFILE) and USE_APACHE_XSENDFILE |
|
154 | 154 | response.headers['Content-Type'] = "application/force-download" |
|
155 | 155 | response.headers['Content-Disposition'] = "attachment; filename=\"output-#{case_num}.txt\"" |
|
156 | 156 | response.headers["X-Sendfile"] = out_filename |
|
157 | 157 | response.headers['Content-length'] = File.size(out_filename) |
|
158 | 158 | render :nothing => true |
|
159 | 159 | else |
|
160 | 160 | send_file out_filename, :stream => false, :filename => "output-#{case_num}.txt", :type => "text/plain" |
|
161 | 161 | end |
|
162 | 162 | end |
|
163 | 163 | |
|
164 | 164 | def error |
|
165 | 165 | @user = User.find(session[:user_id]) |
|
166 | 166 | end |
|
167 | 167 | |
|
168 | 168 | # announcement refreshing and hiding methods |
|
169 | 169 | |
|
170 | 170 | def announcements |
|
171 | 171 | if params.has_key? 'recent' |
|
172 | 172 | prepare_announcements(params[:recent]) |
|
173 | 173 | else |
|
174 | 174 | prepare_announcements |
|
175 | 175 | end |
|
176 | 176 | render(:partial => 'announcement', |
|
177 | 177 | :collection => @announcements, |
|
178 | 178 | :locals => {:announcement_effect => true}) |
|
179 | 179 | end |
|
180 | 180 | |
|
181 | 181 | def confirm_contest_start |
|
182 | 182 | user = User.find(session[:user_id]) |
|
183 | 183 | if request.method == 'POST' |
|
184 | 184 | user.update_start_time |
|
185 | 185 | redirect_to :action => 'list' |
|
186 | 186 | else |
|
187 | 187 | @contests = user.contests |
|
188 | 188 | @user = user |
|
189 | 189 | end |
|
190 | 190 | end |
|
191 | 191 | |
|
192 | 192 | protected |
|
193 | 193 | |
|
194 | 194 | def prepare_announcements(recent=nil) |
|
195 | 195 | if GraderConfiguration.show_tasks_to?(@user) |
|
196 | 196 | @announcements = Announcement.published(true) |
|
197 | 197 | else |
|
198 | 198 | @announcements = Announcement.published |
|
199 | 199 | end |
|
200 | 200 | if recent!=nil |
|
201 | 201 | recent_id = recent.to_i |
|
202 | 202 | @announcements = @announcements.find_all { |a| a.id > recent_id } |
|
203 | 203 | end |
|
204 | 204 | end |
|
205 | 205 | |
|
206 | 206 | def prepare_list_information |
|
207 | 207 | @user = User.find(session[:user_id]) |
|
208 | 208 | if not GraderConfiguration.multicontests? |
|
209 | 209 | @problems = @user.available_problems |
|
210 | 210 | else |
|
211 | 211 | @contest_problems = @user.available_problems_group_by_contests |
|
212 | 212 | @problems = @user.available_problems |
|
213 | 213 | end |
|
214 | 214 | @prob_submissions = {} |
|
215 | 215 | @problems.each do |p| |
|
216 | 216 | sub = Submission.find_last_by_user_and_problem(@user.id,p.id) |
|
217 | 217 | if sub!=nil |
|
218 | 218 | @prob_submissions[p.id] = { :count => sub.number, :submission => sub } |
|
219 | 219 | else |
|
220 | 220 | @prob_submissions[p.id] = { :count => 0, :submission => nil } |
|
221 | 221 | end |
|
222 | 222 | end |
|
223 | 223 | prepare_announcements |
|
224 | 224 | end |
|
225 | 225 | |
|
226 | 226 | def check_viewability |
|
227 | 227 | @user = User.find(session[:user_id]) |
|
228 | 228 | if (!GraderConfiguration.show_tasks_to?(@user)) and |
|
229 | 229 | ((action_name=='submission') or (action_name=='submit')) |
|
230 | 230 | redirect_to :action => 'list' and return |
|
231 | 231 | end |
|
232 | 232 | end |
|
233 | 233 | |
|
234 | 234 | def prepare_grading_result(submission) |
|
235 | 235 | if GraderConfiguration.task_grading_info.has_key? submission.problem.name |
|
236 | 236 | grading_info = GraderConfiguration.task_grading_info[submission.problem.name] |
|
237 | 237 | else |
|
238 | 238 | # guess task info from problem.full_score |
|
239 | 239 | cases = submission.problem.full_score / 10 |
|
240 | 240 | grading_info = { |
|
241 | 241 | 'testruns' => cases, |
|
242 | 242 | 'testcases' => cases |
|
243 | 243 | } |
|
244 | 244 | end |
|
245 | 245 | @test_runs = [] |
|
246 | 246 | if grading_info['testruns'].is_a? Integer |
|
247 | 247 | trun_count = grading_info['testruns'] |
|
248 | 248 | trun_count.times do |i| |
|
249 | 249 | @test_runs << [ read_grading_result(@user.login, |
|
250 | 250 | submission.problem.name, |
|
251 | 251 | submission.id, |
|
252 | 252 | i+1) ] |
|
253 | 253 | end |
|
254 | 254 | else |
|
255 | 255 | grading_info['testruns'].keys.sort.each do |num| |
|
256 | 256 | run = [] |
|
257 | 257 | testrun = grading_info['testruns'][num] |
|
258 | 258 | testrun.each do |c| |
|
259 | 259 | run << read_grading_result(@user.login, |
|
260 | 260 | submission.problem.name, |
|
261 | 261 | submission.id, |
|
262 | 262 | c) |
|
263 | 263 | end |
|
264 | 264 | @test_runs << run |
|
265 | 265 | end |
|
266 | 266 | end |
|
267 | 267 | end |
|
268 | 268 | |
|
269 | 269 | def grading_result_dir(user_name, problem_name, submission_id, case_num) |
|
270 | 270 | return "#{GRADING_RESULT_DIR}/#{user_name}/#{problem_name}/#{submission_id}/test-result/#{case_num}" |
|
271 | 271 | end |
|
272 | 272 | |
|
273 | 273 | def output_filename(user_name, problem_name, submission_id, case_num) |
|
274 | 274 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
275 | 275 | return "#{dir}/output.txt" |
|
276 | 276 | end |
|
277 | 277 | |
|
278 | 278 | def read_grading_result(user_name, problem_name, submission_id, case_num) |
|
279 | 279 | dir = grading_result_dir(user_name,problem_name, submission_id, case_num) |
|
280 | 280 | result_file_name = "#{dir}/result" |
|
281 | 281 | if !FileTest.exists?(result_file_name) |
|
282 | 282 | return {:num => case_num, :msg => 'program did not run'} |
|
283 | 283 | else |
|
284 | 284 | results = File.open(result_file_name).readlines |
|
285 | 285 | run_stat = extract_running_stat(results) |
|
286 | 286 | output_filename = "#{dir}/output.txt" |
|
287 | 287 | if FileTest.exists?(output_filename) |
|
288 | 288 | output_file = true |
|
289 | 289 | output_size = File.size(output_filename) |
|
290 | 290 | else |
|
291 | 291 | output_file = false |
|
292 | 292 | output_size = 0 |
|
293 | 293 | end |
|
294 | 294 | |
|
295 | 295 | return { |
|
296 | 296 | :num => case_num, |
|
297 | 297 | :msg => results[0], |
|
298 | 298 | :run_stat => run_stat, |
|
299 | 299 | :output => output_file, |
|
300 | 300 | :output_size => output_size |
|
301 | 301 | } |
|
302 | 302 | end |
|
303 | 303 | end |
|
304 | 304 | |
|
305 | 305 | # copied from grader/script/lib/test_request_helper.rb |
|
306 | 306 | def extract_running_stat(results) |
|
307 | 307 | running_stat_line = results[-1] |
|
308 | 308 | |
|
309 | 309 | # extract exit status line |
|
310 | 310 | run_stat = "" |
|
311 | 311 | if !(/[Cc]orrect/.match(results[0])) |
|
312 | 312 | run_stat = results[0].chomp |
|
313 | 313 | else |
|
314 | 314 | run_stat = 'Program exited normally' |
|
315 | 315 | end |
|
316 | 316 | |
|
317 | 317 | logger.info "Stat line: #{running_stat_line}" |
|
318 | 318 | |
|
319 | 319 | # extract running time |
|
320 | 320 | if res = /r(.*)u(.*)s/.match(running_stat_line) |
|
321 | 321 | seconds = (res[1].to_f + res[2].to_f) |
|
322 | 322 | time_stat = "Time used: #{seconds} sec." |
|
323 | 323 | else |
|
324 | 324 | seconds = nil |
|
325 | 325 | time_stat = "Time used: n/a sec." |
|
326 | 326 | end |
|
327 | 327 | |
|
328 | 328 | # extract memory usage |
|
329 | 329 | if res = /s(.*)m/.match(running_stat_line) |
|
330 | 330 | memory_used = res[1].to_i |
|
331 | 331 | else |
|
332 | 332 | memory_used = -1 |
|
333 | 333 | end |
|
334 | 334 | |
|
335 | 335 | return { |
|
336 | 336 | :msg => "#{run_stat}\n#{time_stat}", |
|
337 | 337 | :running_time => seconds, |
|
338 | 338 | :exit_status => run_stat, |
|
339 | 339 | :memory_usage => memory_used |
|
340 | 340 | } |
|
341 | 341 | end |
|
342 | 342 | |
|
343 | 343 | def confirm_and_update_start_time |
|
344 | 344 | user = User.find(session[:user_id]) |
|
345 | 345 | if (GraderConfiguration.indv_contest_mode? and |
|
346 | 346 | GraderConfiguration['contest.confirm_indv_contest_start'] and |
|
347 | 347 | !user.contest_started?) |
|
348 | 348 | redirect_to :action => 'confirm_contest_start' and return |
|
349 | 349 | end |
|
350 | 350 | if not GraderConfiguration.analysis_mode? |
|
351 | 351 | user.update_start_time |
|
352 | 352 | end |
|
353 | 353 | end |
|
354 | 354 | |
|
355 | 355 | def reject_announcement_refresh_when_logged_out |
|
356 | 356 | if not session[:user_id] |
|
357 | 357 | render :text => 'Access forbidden', :status => 403 |
|
358 | 358 | end |
|
359 | 359 | |
|
360 | 360 | if GraderConfiguration.multicontests? |
|
361 | 361 | user = User.find(session[:user_id]) |
|
362 | 362 | if user.contest_stat.forced_logout |
|
363 | 363 | render :text => 'Access forbidden', :status => 403 |
|
364 | 364 | end |
|
365 | 365 | end |
|
366 | 366 | end |
|
367 | 367 | |
|
368 | 368 | end |
|
369 | 369 |
@@ -1,440 +1,442 | |||
|
1 | 1 | require 'csv' |
|
2 | 2 | |
|
3 | 3 | class ReportController < ApplicationController |
|
4 | 4 | |
|
5 | 5 | before_action :check_valid_login |
|
6 | 6 | |
|
7 | 7 | before_action :admin_authorization, only: [:login_stat,:submission, :submission_query, |
|
8 | 8 | :login, :login_detail_query, :login_summary_query, |
|
9 | 9 | :stuck, :cheat_report, :cheat_scrutinize, :show_max_score, :current_score] |
|
10 | 10 | |
|
11 | 11 | before_action(only: [:problem_hof]) { |c| |
|
12 | 12 | return false unless check_valid_login |
|
13 | 13 | |
|
14 | 14 | admin_authorization unless GraderConfiguration["right.user_view_submission"] |
|
15 | 15 | } |
|
16 | 16 | |
|
17 | 17 | def max_score |
|
18 | 18 | end |
|
19 | 19 | |
|
20 | 20 | def current_score |
|
21 | 21 | @problems = Problem.available_problems |
|
22 | - if params[:group_id] | |
|
22 | + if params[:group_id] && params[:users] == 'group' | |
|
23 | 23 | @group = Group.find(params[:group_id]) |
|
24 | 24 | @users = @group.users.where(enabled: true) |
|
25 | 25 | else |
|
26 | 26 | @users = User.includes(:contests).includes(:contest_stat).where(enabled: true) |
|
27 | 27 | end |
|
28 | 28 | @scorearray = calculate_max_score(@problems, @users,0,0,true) |
|
29 | 29 | |
|
30 | 30 | #rencer accordingly |
|
31 | 31 | if params[:button] == 'download' then |
|
32 | 32 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
33 | 33 | send_data csv, filename: 'max_score.csv' |
|
34 | 34 | else |
|
35 | 35 | #render template: 'user_admin/user_stat' |
|
36 | 36 | render 'current_score' |
|
37 | 37 | end |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | def show_max_score |
|
41 | 41 | #process parameters |
|
42 | 42 | #problems |
|
43 | 43 | @problems = [] |
|
44 | 44 | if params[:problem_id] |
|
45 | 45 | params[:problem_id].each do |id| |
|
46 | 46 | next unless id.strip != "" |
|
47 | 47 | pid = Problem.find_by_id(id.to_i) |
|
48 | 48 | @problems << pid if pid |
|
49 | 49 | end |
|
50 | 50 | end |
|
51 | 51 | |
|
52 | 52 | #users |
|
53 |
- @users = if params[:users] == " |
|
|
53 | + @users = if params[:users] == "group" then | |
|
54 | + Group.find(params[:group_id]).users.all | |
|
55 | + elsif params[:users] == 'enabled' | |
|
56 | + User.includes(:contests).includes(:contest_stat).where(enabled: true) | |
|
57 | + else | |
|
54 | 58 | User.includes(:contests).includes(:contest_stat) |
|
55 | - else | |
|
56 | - User.includes(:contests).includes(:contest_stat).where(enabled: true) | |
|
57 | 59 | end |
|
58 | 60 | |
|
59 | 61 | #set up range from param |
|
60 | 62 | @since_id = params.fetch(:from_id, 0).to_i |
|
61 | 63 | @until_id = params.fetch(:to_id, 0).to_i |
|
62 | 64 | @since_id = nil if @since_id == 0 |
|
63 | 65 | @until_id = nil if @until_id == 0 |
|
64 | 66 | |
|
65 | 67 | #calculate the routine |
|
66 | 68 | @scorearray = calculate_max_score(@problems, @users, @since_id, @until_id) |
|
67 | 69 | |
|
68 | 70 | #rencer accordingly |
|
69 | 71 | if params[:button] == 'download' then |
|
70 | 72 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
71 | 73 | send_data csv, filename: 'max_score.csv' |
|
72 | 74 | else |
|
73 | 75 | #render template: 'user_admin/user_stat' |
|
74 | 76 | render 'max_score' |
|
75 | 77 | end |
|
76 | 78 | |
|
77 | 79 | end |
|
78 | 80 | |
|
79 | 81 | def score |
|
80 | 82 | if params[:commit] == 'download csv' |
|
81 | 83 | @problems = Problem.all |
|
82 | 84 | else |
|
83 | 85 | @problems = Problem.available_problems |
|
84 | 86 | end |
|
85 | 87 | @users = User.includes(:contests, :contest_stat).where(enabled: true) |
|
86 | 88 | @scorearray = Array.new |
|
87 | 89 | @users.each do |u| |
|
88 | 90 | ustat = Array.new |
|
89 | 91 | ustat[0] = u |
|
90 | 92 | @problems.each do |p| |
|
91 | 93 | sub = Submission.find_last_by_user_and_problem(u.id,p.id) |
|
92 | 94 | if (sub!=nil) and (sub.points!=nil) and p and p.full_score |
|
93 | 95 | ustat << [(sub.points.to_f*100/p.full_score).round, (sub.points>=p.full_score)] |
|
94 | 96 | else |
|
95 | 97 | ustat << [0,false] |
|
96 | 98 | end |
|
97 | 99 | end |
|
98 | 100 | @scorearray << ustat |
|
99 | 101 | end |
|
100 | 102 | if params[:commit] == 'download csv' then |
|
101 | 103 | csv = gen_csv_from_scorearray(@scorearray,@problems) |
|
102 | 104 | send_data csv, filename: 'last_score.csv' |
|
103 | 105 | else |
|
104 | 106 | render template: 'user_admin/user_stat' |
|
105 | 107 | end |
|
106 | 108 | |
|
107 | 109 | end |
|
108 | 110 | |
|
109 | 111 | def login |
|
110 | 112 | end |
|
111 | 113 | |
|
112 | 114 | def login_summary_query |
|
113 | 115 | @users = Array.new |
|
114 | 116 | |
|
115 | 117 | date_and_time = '%Y-%m-%d %H:%M' |
|
116 | 118 | begin |
|
117 | 119 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
118 | 120 | @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) |
|
119 | 121 | rescue |
|
120 | 122 | @since_time = DateTime.new(1000,1,1) |
|
121 | 123 | end |
|
122 | 124 | begin |
|
123 | 125 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
124 | 126 | @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) |
|
125 | 127 | rescue |
|
126 | 128 | @until_time = DateTime.new(3000,1,1) |
|
127 | 129 | end |
|
128 | 130 | |
|
129 | 131 | record = User |
|
130 | 132 | .left_outer_joins(:logins).group('users.id') |
|
131 | 133 | .where("logins.created_at >= ? AND logins.created_at <= ?",@since_time, @until_time) |
|
132 | 134 | case params[:users] |
|
133 | 135 | when 'enabled' |
|
134 | 136 | record = record.where(enabled: true) |
|
135 | 137 | when 'group' |
|
136 | 138 | record = record.joins(:groups).where(groups: {id: params[:groups]}) if params[:groups] |
|
137 | 139 | end |
|
138 | 140 | |
|
139 | 141 | record = record.pluck("users.id,users.login,users.full_name,count(logins.created_at),min(logins.created_at),max(logins.created_at)") |
|
140 | 142 | record.each do |user| |
|
141 | 143 | x = Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
142 | 144 | user[0],@since_time,@until_time) |
|
143 | 145 | .pluck(:ip_address).uniq |
|
144 | 146 | @users << { id: user[0], |
|
145 | 147 | login: user[1], |
|
146 | 148 | full_name: user[2], |
|
147 | 149 | count: user[3], |
|
148 | 150 | min: user[4], |
|
149 | 151 | max: user[5], |
|
150 | 152 | ip: x |
|
151 | 153 | } |
|
152 | 154 | end |
|
153 | 155 | end |
|
154 | 156 | |
|
155 | 157 | def login_detail_query |
|
156 | 158 | @logins = Array.new |
|
157 | 159 | |
|
158 | 160 | date_and_time = '%Y-%m-%d %H:%M' |
|
159 | 161 | begin |
|
160 | 162 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
161 | 163 | @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) |
|
162 | 164 | rescue |
|
163 | 165 | @since_time = DateTime.new(1000,1,1) |
|
164 | 166 | end |
|
165 | 167 | begin |
|
166 | 168 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
167 | 169 | @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) |
|
168 | 170 | rescue |
|
169 | 171 | @until_time = DateTime.new(3000,1,1) |
|
170 | 172 | end |
|
171 | 173 | |
|
172 | 174 | @logins = Login.includes(:user).where("logins.created_at >= ? AND logins.created_at <= ?",@since_time, @until_time) |
|
173 | 175 | case params[:users] |
|
174 | 176 | when 'enabled' |
|
175 | 177 | @logins = @logins.where(users: {enabled: true}) |
|
176 | 178 | when 'group' |
|
177 | 179 | @logins = @logins.joins(user: :groups).where(user: {groups: {id: params[:groups]}}) if params[:groups] |
|
178 | 180 | end |
|
179 | 181 | end |
|
180 | 182 | |
|
181 | 183 | def submission |
|
182 | 184 | end |
|
183 | 185 | |
|
184 | 186 | def submission_query |
|
185 | 187 | @submissions = Submission |
|
186 | 188 | .includes(:problem).includes(:user).includes(:language) |
|
187 | 189 | |
|
188 | 190 | case params[:users] |
|
189 | 191 | when 'enabled' |
|
190 | 192 | @submissions = @submissions.where(users: {enabled: true}) |
|
191 | 193 | when 'group' |
|
192 | 194 | @submissions = @submissions.joins(user: :groups).where(user: {groups: {id: params[:groups]}}) if params[:groups] |
|
193 | 195 | end |
|
194 | 196 | |
|
195 | 197 | case params[:problems] |
|
196 | 198 | when 'enabled' |
|
197 | 199 | @submissions = @submissions.where(problems: {available: true}) |
|
198 | 200 | when 'selected' |
|
199 | 201 | @submissions = @submissions.where(problem_id: params[:problem_id]) |
|
200 | 202 | end |
|
201 | 203 | |
|
202 | 204 | #set default |
|
203 | 205 | params[:since_datetime] = Date.today.to_s if params[:since_datetime].blank? |
|
204 | 206 | |
|
205 | 207 | @submissions, @recordsTotal, @recordsFiltered = process_query_record( @submissions, |
|
206 | 208 | global_search: ['user.login','user.full_name','problem.name','problem.full_name','points'], |
|
207 | 209 | date_filter: 'submitted_at', |
|
208 | 210 | date_param_since: 'since_datetime', |
|
209 | 211 | date_param_until: 'until_datetime', |
|
210 | 212 | hard_limit: 100_000 |
|
211 | 213 | ) |
|
212 | 214 | end |
|
213 | 215 | |
|
214 | 216 | def login |
|
215 | 217 | end |
|
216 | 218 | |
|
217 | 219 | def problem_hof |
|
218 | 220 | # gen problem list |
|
219 | 221 | @user = User.find(session[:user_id]) |
|
220 | 222 | @problems = @user.available_problems |
|
221 | 223 | |
|
222 | 224 | # get selected problems or the default |
|
223 | 225 | if params[:id] |
|
224 | 226 | begin |
|
225 | 227 | @problem = Problem.available.find(params[:id]) |
|
226 | 228 | rescue |
|
227 | 229 | redirect_to action: :problem_hof |
|
228 | 230 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
229 | 231 | return |
|
230 | 232 | end |
|
231 | 233 | end |
|
232 | 234 | |
|
233 | 235 | return unless @problem |
|
234 | 236 | |
|
235 | 237 | @by_lang = {} #aggregrate by language |
|
236 | 238 | |
|
237 | 239 | range =65 |
|
238 | 240 | @histogram = { data: Array.new(range,0), summary: {} } |
|
239 | 241 | @summary = {count: 0, solve: 0, attempt: 0} |
|
240 | 242 | user = Hash.new(0) |
|
241 | 243 | Submission.where(problem_id: @problem.id).find_each do |sub| |
|
242 | 244 | #histogram |
|
243 | 245 | d = (DateTime.now.in_time_zone - sub.submitted_at) / 24 / 60 / 60 |
|
244 | 246 | @histogram[:data][d.to_i] += 1 if d < range |
|
245 | 247 | |
|
246 | 248 | next unless sub.points |
|
247 | 249 | @summary[:count] += 1 |
|
248 | 250 | user[sub.user_id] = [user[sub.user_id], (sub.points >= @problem.full_score) ? 1 : 0].max |
|
249 | 251 | |
|
250 | 252 | lang = Language.find_by_id(sub.language_id) |
|
251 | 253 | next unless lang |
|
252 | 254 | next unless sub.points >= @problem.full_score |
|
253 | 255 | |
|
254 | 256 | #initialize |
|
255 | 257 | unless @by_lang.has_key?(lang.pretty_name) |
|
256 | 258 | @by_lang[lang.pretty_name] = { |
|
257 | 259 | runtime: { avail: false, value: 2**30-1 }, |
|
258 | 260 | memory: { avail: false, value: 2**30-1 }, |
|
259 | 261 | length: { avail: false, value: 2**30-1 }, |
|
260 | 262 | first: { avail: false, value: DateTime.new(3000,1,1) } |
|
261 | 263 | } |
|
262 | 264 | end |
|
263 | 265 | |
|
264 | 266 | if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value] |
|
265 | 267 | @by_lang[lang.pretty_name][:runtime] = { avail: true, user_id: sub.user_id, value: sub.max_runtime, sub_id: sub.id } |
|
266 | 268 | end |
|
267 | 269 | |
|
268 | 270 | if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value] |
|
269 | 271 | @by_lang[lang.pretty_name][:memory] = { avail: true, user_id: sub.user_id, value: sub.peak_memory, sub_id: sub.id } |
|
270 | 272 | end |
|
271 | 273 | |
|
272 | 274 | if sub.submitted_at and sub.submitted_at < @by_lang[lang.pretty_name][:first][:value] and sub.user and |
|
273 | 275 | !sub.user.admin? |
|
274 | 276 | @by_lang[lang.pretty_name][:first] = { avail: true, user_id: sub.user_id, value: sub.submitted_at, sub_id: sub.id } |
|
275 | 277 | end |
|
276 | 278 | |
|
277 | 279 | if @by_lang[lang.pretty_name][:length][:value] > sub.effective_code_length |
|
278 | 280 | @by_lang[lang.pretty_name][:length] = { avail: true, user_id: sub.user_id, value: sub.effective_code_length, sub_id: sub.id } |
|
279 | 281 | end |
|
280 | 282 | end |
|
281 | 283 | |
|
282 | 284 | #process user_id |
|
283 | 285 | @by_lang.each do |lang,prop| |
|
284 | 286 | prop.each do |k,v| |
|
285 | 287 | v[:user] = User.exists?(v[:user_id]) ? User.find(v[:user_id]).full_name : "(NULL)" |
|
286 | 288 | end |
|
287 | 289 | end |
|
288 | 290 | |
|
289 | 291 | #sum into best |
|
290 | 292 | if @by_lang and @by_lang.first |
|
291 | 293 | @best = @by_lang.first[1].clone |
|
292 | 294 | @by_lang.each do |lang,prop| |
|
293 | 295 | if @best[:runtime][:value] >= prop[:runtime][:value] |
|
294 | 296 | @best[:runtime] = prop[:runtime] |
|
295 | 297 | @best[:runtime][:lang] = lang |
|
296 | 298 | end |
|
297 | 299 | if @best[:memory][:value] >= prop[:memory][:value] |
|
298 | 300 | @best[:memory] = prop[:memory] |
|
299 | 301 | @best[:memory][:lang] = lang |
|
300 | 302 | end |
|
301 | 303 | if @best[:length][:value] >= prop[:length][:value] |
|
302 | 304 | @best[:length] = prop[:length] |
|
303 | 305 | @best[:length][:lang] = lang |
|
304 | 306 | end |
|
305 | 307 | if @best[:first][:value] >= prop[:first][:value] |
|
306 | 308 | @best[:first] = prop[:first] |
|
307 | 309 | @best[:first][:lang] = lang |
|
308 | 310 | end |
|
309 | 311 | end |
|
310 | 312 | end |
|
311 | 313 | |
|
312 | 314 | @histogram[:summary][:max] = [@histogram[:data].max,1].max |
|
313 | 315 | @summary[:attempt] = user.count |
|
314 | 316 | user.each_value { |v| @summary[:solve] += 1 if v == 1 } |
|
315 | 317 | end |
|
316 | 318 | |
|
317 | 319 | def stuck #report struggling user,problem |
|
318 | 320 | # init |
|
319 | 321 | user,problem = nil |
|
320 | 322 | solve = true |
|
321 | 323 | tries = 0 |
|
322 | 324 | @struggle = Array.new |
|
323 | 325 | record = {} |
|
324 | 326 | Submission.includes(:problem,:user).order(:problem_id,:user_id).find_each do |sub| |
|
325 | 327 | next unless sub.problem and sub.user |
|
326 | 328 | if user != sub.user_id or problem != sub.problem_id |
|
327 | 329 | @struggle << { user: record[:user], problem: record[:problem], tries: tries } unless solve |
|
328 | 330 | record = {user: sub.user, problem: sub.problem} |
|
329 | 331 | user,problem = sub.user_id, sub.problem_id |
|
330 | 332 | solve = false |
|
331 | 333 | tries = 0 |
|
332 | 334 | end |
|
333 | 335 | if sub.points >= sub.problem.full_score |
|
334 | 336 | solve = true |
|
335 | 337 | else |
|
336 | 338 | tries += 1 |
|
337 | 339 | end |
|
338 | 340 | end |
|
339 | 341 | @struggle.sort!{|a,b| b[:tries] <=> a[:tries] } |
|
340 | 342 | @struggle = @struggle[0..50] |
|
341 | 343 | end |
|
342 | 344 | |
|
343 | 345 | |
|
344 | 346 | def multiple_login |
|
345 | 347 | #user with multiple IP |
|
346 | 348 | raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:login) |
|
347 | 349 | last,count = 0,0 |
|
348 | 350 | first = 0 |
|
349 | 351 | @users = [] |
|
350 | 352 | raw.each do |r| |
|
351 | 353 | if last != r.user.login |
|
352 | 354 | count = 1 |
|
353 | 355 | last = r.user.login |
|
354 | 356 | first = r |
|
355 | 357 | else |
|
356 | 358 | @users << first if count == 1 |
|
357 | 359 | @users << r |
|
358 | 360 | count += 1 |
|
359 | 361 | end |
|
360 | 362 | end |
|
361 | 363 | |
|
362 | 364 | #IP with multiple user |
|
363 | 365 | raw = Submission.joins(:user).joins(:problem).where("problems.available != 0").group("login,ip_address").order(:ip_address) |
|
364 | 366 | last,count = 0,0 |
|
365 | 367 | first = 0 |
|
366 | 368 | @ip = [] |
|
367 | 369 | raw.each do |r| |
|
368 | 370 | if last != r.ip_address |
|
369 | 371 | count = 1 |
|
370 | 372 | last = r.ip_address |
|
371 | 373 | first = r |
|
372 | 374 | else |
|
373 | 375 | @ip << first if count == 1 |
|
374 | 376 | @ip << r |
|
375 | 377 | count += 1 |
|
376 | 378 | end |
|
377 | 379 | end |
|
378 | 380 | end |
|
379 | 381 | |
|
380 | 382 | def cheat_report |
|
381 | 383 | date_and_time = '%Y-%m-%d %H:%M' |
|
382 | 384 | begin |
|
383 | 385 | md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
384 | 386 | @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) |
|
385 | 387 | rescue |
|
386 | 388 | @since_time = Time.zone.now.ago( 90.minutes) |
|
387 | 389 | end |
|
388 | 390 | begin |
|
389 | 391 | md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
390 | 392 | @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) |
|
391 | 393 | rescue |
|
392 | 394 | @until_time = Time.zone.now |
|
393 | 395 | end |
|
394 | 396 | |
|
395 | 397 | #multi login |
|
396 | 398 | @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") |
|
397 | 399 | |
|
398 | 400 | st = <<-SQL |
|
399 | 401 | SELECT l2.* |
|
400 | 402 | FROM logins l2 INNER JOIN |
|
401 | 403 | (SELECT u.id,COUNT(DISTINCT ip_address) as count,u.login,u.full_name |
|
402 | 404 | FROM logins l |
|
403 | 405 | INNER JOIN users u ON l.user_id = u.id |
|
404 | 406 | WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}' |
|
405 | 407 | GROUP BY u.id |
|
406 | 408 | HAVING count > 1 |
|
407 | 409 | ) ml ON l2.user_id = ml.id |
|
408 | 410 | WHERE l2.created_at >= '#{@since_time.in_time_zone("UTC")}' and l2.created_at <= '#{@until_time.in_time_zone("UTC")}' |
|
409 | 411 | UNION |
|
410 | 412 | SELECT l2.* |
|
411 | 413 | FROM logins l2 INNER JOIN |
|
412 | 414 | (SELECT l.ip_address,COUNT(DISTINCT u.id) as count |
|
413 | 415 | FROM logins l |
|
414 | 416 | INNER JOIN users u ON l.user_id = u.id |
|
415 | 417 | WHERE l.created_at >= '#{@since_time.in_time_zone("UTC")}' and l.created_at <= '#{@until_time.in_time_zone("UTC")}' |
|
416 | 418 | GROUP BY l.ip_address |
|
417 | 419 | HAVING count > 1 |
|
418 | 420 | ) ml on ml.ip_address = l2.ip_address |
|
419 | 421 | INNER JOIN users u ON l2.user_id = u.id |
|
420 | 422 | WHERE l2.created_at >= '#{@since_time.in_time_zone("UTC")}' and l2.created_at <= '#{@until_time.in_time_zone("UTC")}' |
|
421 | 423 | ORDER BY ip_address,created_at |
|
422 | 424 | SQL |
|
423 | 425 | @mld = Login.find_by_sql(st) |
|
424 | 426 | |
|
425 | 427 | st = <<-SQL |
|
426 | 428 | SELECT s.id,s.user_id,s.ip_address,s.submitted_at,s.problem_id |
|
427 | 429 | FROM submissions s INNER JOIN |
|
428 | 430 | (SELECT u.id,COUNT(DISTINCT ip_address) as count,u.login,u.full_name |
|
429 | 431 | FROM logins l |
|
430 | 432 | INNER JOIN users u ON l.user_id = u.id |
|
431 | 433 | WHERE l.created_at >= ? and l.created_at <= ? |
|
432 | 434 | GROUP BY u.id |
|
433 | 435 | HAVING count > 1 |
|
434 | 436 | ) ml ON s.user_id = ml.id |
|
435 | 437 | WHERE s.submitted_at >= ? and s.submitted_at <= ? |
|
436 | 438 | UNION |
|
437 | 439 | SELECT s.id,s.user_id,s.ip_address,s.submitted_at,s.problem_id |
|
438 | 440 | FROM submissions s INNER JOIN |
|
439 | 441 | (SELECT l.ip_address,COUNT(DISTINCT u.id) as count |
|
440 | 442 | FROM logins l |
@@ -1,111 +1,111 | |||
|
1 | 1 | class SubmissionsController < ApplicationController |
|
2 | 2 | before_action :check_valid_login |
|
3 | 3 | before_action :submission_authorization, only: [:show, :download, :edit] |
|
4 | 4 | before_action :admin_authorization, only: [:rejudge] |
|
5 | 5 | |
|
6 | 6 | # GET /submissions |
|
7 | 7 | # GET /submissions.json |
|
8 | 8 | # Show problem selection and user's submission of that problem |
|
9 | 9 | def index |
|
10 | 10 | @user = @current_user |
|
11 | 11 | @problems = @user.available_problems |
|
12 | 12 | |
|
13 | 13 | if params[:problem_id]==nil |
|
14 | 14 | @problem = nil |
|
15 | 15 | @submissions = nil |
|
16 | 16 | else |
|
17 | 17 | @problem = Problem.find_by_id(params[:problem_id]) |
|
18 | 18 | if (@problem == nil) or (not @problem.available) |
|
19 | 19 | redirect_to list_main_path |
|
20 | 20 | flash[:error] = 'Authorization error: You have no right to view submissions for this problem' |
|
21 | 21 | return |
|
22 | 22 | end |
|
23 | 23 | @submissions = Submission.find_all_by_user_problem(@user.id, @problem.id).order(id: :desc) |
|
24 | 24 | end |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | 27 | # GET /submissions/1 |
|
28 | 28 | # GET /submissions/1.json |
|
29 | 29 | def show |
|
30 | 30 | @submission = Submission.find(params[:id]) |
|
31 | 31 | |
|
32 | 32 | #log the viewing |
|
33 | 33 | user = User.find(session[:user_id]) |
|
34 | 34 | SubmissionViewLog.create(user_id: session[:user_id],submission_id: @submission.id) unless user.admin? |
|
35 | 35 | |
|
36 | 36 | @task = @submission.task |
|
37 | 37 | end |
|
38 | 38 | |
|
39 | 39 | def download |
|
40 | 40 | @submission = Submission.find(params[:id]) |
|
41 | 41 | send_data(@submission.source, {:filename => @submission.download_filename, :type => 'text/plain'}) |
|
42 | 42 | end |
|
43 | 43 | |
|
44 | 44 | def compiler_msg |
|
45 | 45 | @submission = Submission.find(params[:id]) |
|
46 | 46 | respond_to do |format| |
|
47 | 47 | format.js |
|
48 | 48 | end |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | 51 | #on-site new submission on specific problem |
|
52 | 52 | def direct_edit_problem |
|
53 | 53 | @problem = Problem.find(params[:problem_id]) |
|
54 | 54 | unless @current_user.can_view_problem?(@problem) |
|
55 | 55 | unauthorized_redirect |
|
56 | 56 | return |
|
57 | 57 | end |
|
58 | 58 | @source = '' |
|
59 | 59 | if (params[:view_latest]) |
|
60 | 60 | sub = Submission.find_last_by_user_and_problem(@current_user.id,@problem.id) |
|
61 | 61 | @source = @submission.source.to_s if @submission and @submission.source |
|
62 | 62 | end |
|
63 | 63 | render 'edit' |
|
64 | 64 | end |
|
65 | 65 | |
|
66 | 66 | # GET /submissions/1/edit |
|
67 | 67 | def edit |
|
68 | 68 | @submission = Submission.find(params[:id]) |
|
69 | 69 | @source = @submission.source.to_s |
|
70 | 70 | @problem = @submission.problem |
|
71 | 71 | @lang_id = @submission.language.id |
|
72 | 72 | end |
|
73 | 73 | |
|
74 | 74 | |
|
75 | 75 | def get_latest_submission_status |
|
76 | 76 | @problem = Problem.find(params[:pid]) |
|
77 | 77 | @submission = Submission.find_last_by_user_and_problem(params[:uid],params[:pid]) |
|
78 | 78 | respond_to do |format| |
|
79 | 79 | format.js |
|
80 | 80 | end |
|
81 | 81 | end |
|
82 | 82 | |
|
83 | 83 | # GET /submissions/:id/rejudge |
|
84 | 84 | def rejudge |
|
85 | 85 | @submission = Submission.find(params[:id]) |
|
86 | 86 | @task = @submission.task |
|
87 | 87 | @task.status_inqueue! if @task |
|
88 | 88 | respond_to do |format| |
|
89 | 89 | format.js |
|
90 | 90 | end |
|
91 | 91 | end |
|
92 | 92 | |
|
93 | 93 | protected |
|
94 | 94 | |
|
95 | 95 | def submission_authorization |
|
96 | 96 | #admin always has privileged |
|
97 | 97 | return true if @current_user.admin? |
|
98 |
- return true if @current_user.has_role?(' |
|
|
98 | + return true if @current_user.has_role?('ta') && (['show','download'].include? action_name) | |
|
99 | 99 | |
|
100 | 100 | sub = Submission.find(params[:id]) |
|
101 | 101 | if @current_user.available_problems.include? sub.problem |
|
102 | 102 | return true if GraderConfiguration["right.user_view_submission"] or sub.user == @current_user |
|
103 | 103 | end |
|
104 | 104 | |
|
105 | 105 | #default to NO |
|
106 | 106 | unauthorized_redirect |
|
107 | 107 | return false |
|
108 | 108 | end |
|
109 | 109 | |
|
110 | 110 | |
|
111 | 111 | end |
@@ -1,11 +1,15 | |||
|
1 | 1 | .container-fluid |
|
2 | 2 | %h1 Current Score |
|
3 | 3 | = form_tag current_score_report_path, method: 'get' do |
|
4 | - Show only users from this group | |
|
4 | + .radio-inline | |
|
5 | + = radio_button_tag 'users', 'all', (params[:users] == 'all') | |
|
6 | + = label_tag(:users_all,'Show all users') | |
|
7 | + %br | |
|
8 | + .radio-inline | |
|
9 | + = radio_button_tag 'users', 'group', (params[:users] == 'group') | |
|
10 | + = label_tag(:users_group, 'Show only users from this group') | |
|
5 | 11 | = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_id]), id: 'group_name',class: 'select2', style: 'width: 20em'; |
|
6 | 12 | = submit_tag 'Apply',class: 'btn btn-default' |
|
7 | 13 | |
|
8 | 14 | %br |
|
9 | - | |
|
10 | - | |
|
11 | 15 | = render "score_table" |
@@ -1,49 +1,54 | |||
|
1 | 1 | %h1 Maximum score |
|
2 | 2 | |
|
3 | 3 | = form_tag show_max_score_report_path |
|
4 | 4 | .row |
|
5 | 5 | .col-md-4 |
|
6 | 6 | .panel.panel-primary |
|
7 | 7 | .panel-heading |
|
8 | 8 | Problems |
|
9 | 9 | .panel-body |
|
10 | 10 | %p |
|
11 | 11 | Select problem(s) that we wish to know the score. |
|
12 | 12 | = label_tag :problem_id, "Problems" |
|
13 | 13 | = select_tag 'problem_id[]', |
|
14 | 14 | options_for_select(Problem.all.collect {|p| ["[#{p.name}] #{p.full_name}", p.id]},params[:problem_id]), |
|
15 | 15 | { class: 'select2 form-control', multiple: "true" } |
|
16 | 16 | .col-md-4 |
|
17 | 17 | .panel.panel-primary |
|
18 | 18 | .panel-heading |
|
19 | 19 | Submission range |
|
20 | 20 | .panel-body |
|
21 | 21 | %p |
|
22 | 22 | Input minimum and maximum range of submission ID that should be included. A blank value for min and max means -1 and infinity, respectively. |
|
23 | 23 | .form-group |
|
24 | 24 | = label_tag :from, "Min" |
|
25 | 25 | = text_field_tag 'from_id', @since_id, class: "form-control" |
|
26 | 26 | .form-group |
|
27 | 27 | = label_tag :from, "Max" |
|
28 | 28 | = text_field_tag 'to_id', @until_id, class: "form-control" |
|
29 | 29 | .col-md-4 |
|
30 | 30 | .panel.panel-primary |
|
31 | 31 | .panel-heading |
|
32 | 32 | Users |
|
33 | 33 | .panel-body |
|
34 | 34 | .radio |
|
35 | 35 | %label |
|
36 | 36 | = radio_button_tag 'users', 'all', (params[:users] == "all") |
|
37 | 37 | All users |
|
38 | 38 | .radio |
|
39 | 39 | %label |
|
40 | 40 | = radio_button_tag 'users', 'enabled', (params[:users] == "enabled") |
|
41 | 41 | Only enabled users |
|
42 | + .radio | |
|
43 | + %label | |
|
44 | + = radio_button_tag 'users', 'group', (params[:users] == "group") | |
|
45 | + Only users from this group | |
|
46 | + = select_tag "group_id", options_from_collection_for_select( Group.all, 'id','name',params[:group_id]), id: 'group_name',class: 'select2', style: 'width: 20em'; | |
|
42 | 47 | .row |
|
43 | 48 | .col-md-12 |
|
44 | 49 | = button_tag 'Show', class: "btn btn-primary btn-large", value: "show" |
|
45 | 50 | = button_tag 'Download CSV', class: "btn btn-primary btn-large", value: "download" |
|
46 | 51 | |
|
47 | 52 | - if @scorearray |
|
48 | 53 | %h2 Result |
|
49 | 54 | =render "score_table" |
@@ -1,308 +1,310 | |||
|
1 | 1 | # This file is auto-generated from the current state of the database. Instead |
|
2 | 2 | # of editing this file, please use the migrations feature of Active Record to |
|
3 | 3 | # incrementally modify your database, and then regenerate this schema definition. |
|
4 | 4 | # |
|
5 | 5 | # Note that this schema.rb definition is the authoritative source for your |
|
6 | 6 | # database schema. If you need to create the application database on another |
|
7 | 7 | # system, you should be using db:schema:load, not running all the migrations |
|
8 | 8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
9 | 9 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
10 | 10 | # |
|
11 | 11 | # It's strongly recommended that you check this file into your version control system. |
|
12 | 12 | |
|
13 | 13 | ActiveRecord::Schema.define(version: 2020_08_13_083020) do |
|
14 | 14 | |
|
15 | 15 | create_table "announcements", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
16 | 16 | t.string "author" |
|
17 | 17 | t.text "body" |
|
18 | 18 | t.boolean "published" |
|
19 | 19 | t.datetime "created_at", null: false |
|
20 | 20 | t.datetime "updated_at", null: false |
|
21 | 21 | t.boolean "frontpage", default: false |
|
22 | 22 | t.boolean "contest_only", default: false |
|
23 | 23 | t.string "title" |
|
24 | 24 | t.string "notes" |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | 27 | create_table "contests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
28 | 28 | t.string "title" |
|
29 | 29 | t.boolean "enabled" |
|
30 | 30 | t.datetime "created_at", null: false |
|
31 | 31 | t.datetime "updated_at", null: false |
|
32 | 32 | t.string "name" |
|
33 | 33 | end |
|
34 | 34 | |
|
35 | 35 | create_table "contests_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
36 | 36 | t.integer "contest_id" |
|
37 | 37 | t.integer "problem_id" |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | create_table "contests_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
41 | 41 | t.integer "contest_id" |
|
42 | 42 | t.integer "user_id" |
|
43 | 43 | end |
|
44 | 44 | |
|
45 | 45 | create_table "countries", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
46 | 46 | t.string "name" |
|
47 | 47 | t.datetime "created_at", null: false |
|
48 | 48 | t.datetime "updated_at", null: false |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | 51 | create_table "descriptions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
52 | 52 | t.text "body" |
|
53 | 53 | t.boolean "markdowned" |
|
54 | 54 | t.datetime "created_at", null: false |
|
55 | 55 | t.datetime "updated_at", null: false |
|
56 | 56 | end |
|
57 | 57 | |
|
58 | 58 | create_table "grader_configurations", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
59 | 59 | t.string "key" |
|
60 | 60 | t.string "value_type" |
|
61 | 61 | t.string "value" |
|
62 | 62 | t.datetime "created_at", null: false |
|
63 | 63 | t.datetime "updated_at", null: false |
|
64 | 64 | t.text "description" |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | create_table "grader_processes", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
68 | 68 | t.string "host" |
|
69 | 69 | t.integer "pid" |
|
70 | 70 | t.string "mode" |
|
71 | 71 | t.boolean "active" |
|
72 | 72 | t.datetime "created_at", null: false |
|
73 | 73 | t.datetime "updated_at", null: false |
|
74 | 74 | t.integer "task_id" |
|
75 | 75 | t.string "task_type" |
|
76 | 76 | t.boolean "terminated" |
|
77 | 77 | t.index ["host", "pid"], name: "index_grader_processes_on_ip_and_pid" |
|
78 | 78 | end |
|
79 | 79 | |
|
80 | 80 | create_table "groups", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
81 | 81 | t.string "name" |
|
82 | 82 | t.string "description" |
|
83 | 83 | t.boolean "enabled", default: true |
|
84 | 84 | end |
|
85 | 85 | |
|
86 | 86 | create_table "groups_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
87 | 87 | t.integer "problem_id", null: false |
|
88 | 88 | t.integer "group_id", null: false |
|
89 | 89 | t.index ["group_id", "problem_id"], name: "index_groups_problems_on_group_id_and_problem_id" |
|
90 | 90 | end |
|
91 | 91 | |
|
92 |
- create_table "groups_users" |
|
|
92 | + create_table "groups_users", options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| | |
|
93 | 93 | t.integer "group_id", null: false |
|
94 | 94 | t.integer "user_id", null: false |
|
95 | 95 | t.index ["user_id", "group_id"], name: "index_groups_users_on_user_id_and_group_id" |
|
96 | 96 | end |
|
97 | 97 | |
|
98 | 98 | create_table "heart_beats", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
99 | 99 | t.integer "user_id" |
|
100 | 100 | t.string "ip_address" |
|
101 | 101 | t.datetime "created_at", null: false |
|
102 | 102 | t.datetime "updated_at", null: false |
|
103 | 103 | t.string "status" |
|
104 | 104 | t.index ["updated_at"], name: "index_heart_beats_on_updated_at" |
|
105 | 105 | end |
|
106 | 106 | |
|
107 | 107 | create_table "languages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
108 | 108 | t.string "name", limit: 10 |
|
109 | 109 | t.string "pretty_name" |
|
110 | 110 | t.string "ext", limit: 10 |
|
111 | 111 | t.string "common_ext" |
|
112 | 112 | end |
|
113 | 113 | |
|
114 | 114 | create_table "logins", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
115 | 115 | t.integer "user_id" |
|
116 | 116 | t.string "ip_address" |
|
117 | 117 | t.datetime "created_at", null: false |
|
118 | 118 | t.datetime "updated_at", null: false |
|
119 | + t.index ["user_id"], name: "index_logins_on_user_id" | |
|
119 | 120 | end |
|
120 | 121 | |
|
121 | 122 | create_table "messages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
122 | 123 | t.integer "sender_id" |
|
123 | 124 | t.integer "receiver_id" |
|
124 | 125 | t.integer "replying_message_id" |
|
125 | 126 | t.text "body" |
|
126 | 127 | t.boolean "replied" |
|
127 | 128 | t.datetime "created_at", null: false |
|
128 | 129 | t.datetime "updated_at", null: false |
|
129 | 130 | end |
|
130 | 131 | |
|
131 | 132 | create_table "problems", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
132 | 133 | t.string "name", limit: 30 |
|
133 | 134 | t.string "full_name" |
|
134 | 135 | t.integer "full_score" |
|
135 | 136 | t.date "date_added" |
|
136 | 137 | t.boolean "available" |
|
137 | 138 | t.string "url" |
|
138 | 139 | t.integer "description_id" |
|
139 | 140 | t.boolean "test_allowed" |
|
140 | 141 | t.boolean "output_only" |
|
141 | 142 | t.string "description_filename" |
|
142 | 143 | t.boolean "view_testcase" |
|
143 | 144 | end |
|
144 | 145 | |
|
145 | 146 | create_table "problems_tags", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
146 | 147 | t.integer "problem_id" |
|
147 | 148 | t.integer "tag_id" |
|
148 | 149 | t.index ["problem_id", "tag_id"], name: "index_problems_tags_on_problem_id_and_tag_id", unique: true |
|
149 | 150 | t.index ["problem_id"], name: "index_problems_tags_on_problem_id" |
|
150 | 151 | t.index ["tag_id"], name: "index_problems_tags_on_tag_id" |
|
151 | 152 | end |
|
152 | 153 | |
|
153 | 154 | create_table "rights", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
154 | 155 | t.string "name" |
|
155 | 156 | t.string "controller" |
|
156 | 157 | t.string "action" |
|
157 | 158 | end |
|
158 | 159 | |
|
159 | 160 | create_table "rights_roles", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
160 | 161 | t.integer "right_id" |
|
161 | 162 | t.integer "role_id" |
|
162 | 163 | t.index ["role_id"], name: "index_rights_roles_on_role_id" |
|
163 | 164 | end |
|
164 | 165 | |
|
165 | 166 | create_table "roles", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
166 | 167 | t.string "name" |
|
167 | 168 | end |
|
168 | 169 | |
|
169 | 170 | create_table "roles_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
170 | 171 | t.integer "role_id" |
|
171 | 172 | t.integer "user_id" |
|
172 | 173 | t.index ["user_id"], name: "index_roles_users_on_user_id" |
|
173 | 174 | end |
|
174 | 175 | |
|
175 | 176 | create_table "sessions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
176 | 177 | t.string "session_id" |
|
177 | 178 | t.text "data" |
|
178 | 179 | t.datetime "updated_at" |
|
179 | 180 | t.index ["session_id"], name: "index_sessions_on_session_id" |
|
180 | 181 | t.index ["updated_at"], name: "index_sessions_on_updated_at" |
|
181 | 182 | end |
|
182 | 183 | |
|
183 | 184 | create_table "sites", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
184 | 185 | t.string "name" |
|
185 | 186 | t.boolean "started" |
|
186 | 187 | t.datetime "start_time" |
|
187 | 188 | t.datetime "created_at", null: false |
|
188 | 189 | t.datetime "updated_at", null: false |
|
189 | 190 | t.integer "country_id" |
|
190 | 191 | t.string "password" |
|
191 | 192 | end |
|
192 | 193 | |
|
193 | 194 | create_table "submission_view_logs", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
194 | 195 | t.integer "user_id" |
|
195 | 196 | t.integer "submission_id" |
|
196 | 197 | t.datetime "created_at", null: false |
|
197 | 198 | t.datetime "updated_at", null: false |
|
198 | 199 | end |
|
199 | 200 | |
|
200 | 201 | create_table "submissions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
201 | 202 | t.integer "user_id" |
|
202 | 203 | t.integer "problem_id" |
|
203 | 204 | t.integer "language_id" |
|
204 | 205 | t.text "source", limit: 16777215 |
|
205 | 206 | t.binary "binary" |
|
206 | 207 | t.datetime "submitted_at" |
|
207 | 208 | t.datetime "compiled_at" |
|
208 | 209 | t.text "compiler_message" |
|
209 | 210 | t.datetime "graded_at" |
|
210 | 211 | t.integer "points" |
|
211 | 212 | t.text "grader_comment" |
|
212 | 213 | t.integer "number" |
|
213 | 214 | t.string "source_filename" |
|
214 | 215 | t.float "max_runtime" |
|
215 | 216 | t.integer "peak_memory" |
|
216 | 217 | t.integer "effective_code_length" |
|
217 | 218 | t.string "ip_address" |
|
219 | + t.index ["submitted_at"], name: "index_submissions_on_submitted_at" | |
|
218 | 220 | t.index ["user_id", "problem_id", "number"], name: "index_submissions_on_user_id_and_problem_id_and_number", unique: true |
|
219 | 221 | t.index ["user_id", "problem_id"], name: "index_submissions_on_user_id_and_problem_id" |
|
220 | 222 | end |
|
221 | 223 | |
|
222 | 224 | create_table "tags", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
223 | 225 | t.string "name", null: false |
|
224 | 226 | t.text "description" |
|
225 | 227 | t.boolean "public" |
|
226 | 228 | t.datetime "created_at", null: false |
|
227 | 229 | t.datetime "updated_at", null: false |
|
228 | 230 | end |
|
229 | 231 | |
|
230 | 232 | create_table "tasks", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
231 | 233 | t.integer "submission_id" |
|
232 | 234 | t.datetime "created_at" |
|
233 | 235 | t.integer "status" |
|
234 | 236 | t.datetime "updated_at" |
|
235 | 237 | t.index ["submission_id"], name: "index_tasks_on_submission_id" |
|
236 | 238 | end |
|
237 | 239 | |
|
238 | 240 | create_table "test_pairs", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
239 | 241 | t.integer "problem_id" |
|
240 | 242 | t.text "input", limit: 16777215 |
|
241 | 243 | t.text "solution", limit: 16777215 |
|
242 | 244 | t.datetime "created_at", null: false |
|
243 | 245 | t.datetime "updated_at", null: false |
|
244 | 246 | end |
|
245 | 247 | |
|
246 | 248 | create_table "test_requests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
247 | 249 | t.integer "user_id" |
|
248 | 250 | t.integer "problem_id" |
|
249 | 251 | t.integer "submission_id" |
|
250 | 252 | t.string "input_file_name" |
|
251 | 253 | t.string "output_file_name" |
|
252 | 254 | t.string "running_stat" |
|
253 | 255 | t.integer "status" |
|
254 | 256 | t.datetime "updated_at", null: false |
|
255 | 257 | t.datetime "submitted_at" |
|
256 | 258 | t.datetime "compiled_at" |
|
257 | 259 | t.text "compiler_message" |
|
258 | 260 | t.datetime "graded_at" |
|
259 | 261 | t.string "grader_comment" |
|
260 | 262 | t.datetime "created_at", null: false |
|
261 | 263 | t.float "running_time" |
|
262 | 264 | t.string "exit_status" |
|
263 | 265 | t.integer "memory_usage" |
|
264 | 266 | t.index ["user_id", "problem_id"], name: "index_test_requests_on_user_id_and_problem_id" |
|
265 | 267 | end |
|
266 | 268 | |
|
267 | 269 | create_table "testcases", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| |
|
268 | 270 | t.integer "problem_id" |
|
269 | 271 | t.integer "num" |
|
270 | 272 | t.integer "group" |
|
271 | 273 | t.integer "score" |
|
272 | 274 | t.text "input", limit: 4294967295 |
|
273 | 275 | t.text "sol", limit: 4294967295 |
|
274 | 276 | t.datetime "created_at" |
|
275 | 277 | t.datetime "updated_at" |
|
276 | 278 | t.index ["problem_id"], name: "index_testcases_on_problem_id" |
|
277 | 279 | end |
|
278 | 280 | |
|
279 | 281 | create_table "user_contest_stats", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
280 | 282 | t.integer "user_id" |
|
281 | 283 | t.datetime "started_at" |
|
282 | 284 | t.datetime "created_at", null: false |
|
283 | 285 | t.datetime "updated_at", null: false |
|
284 | 286 | t.boolean "forced_logout" |
|
285 | 287 | end |
|
286 | 288 | |
|
287 | 289 | create_table "users", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
288 | 290 | t.string "login", limit: 50 |
|
289 | 291 | t.string "full_name" |
|
290 | 292 | t.string "hashed_password" |
|
291 | 293 | t.string "salt", limit: 5 |
|
292 | 294 | t.string "alias" |
|
293 | 295 | t.string "email" |
|
294 | 296 | t.integer "site_id" |
|
295 | 297 | t.integer "country_id" |
|
296 | 298 | t.boolean "activated", default: false |
|
297 | 299 | t.datetime "created_at" |
|
298 | 300 | t.datetime "updated_at" |
|
299 | 301 | t.boolean "enabled", default: true |
|
300 | 302 | t.string "remark" |
|
301 | 303 | t.string "last_ip" |
|
302 | 304 | t.string "section" |
|
303 | 305 | t.index ["login"], name: "index_users_on_login", unique: true |
|
304 | 306 | end |
|
305 | 307 | |
|
306 | 308 | add_foreign_key "problems_tags", "problems" |
|
307 | 309 | add_foreign_key "problems_tags", "tags" |
|
308 | 310 | end |
@@ -1,289 +1,289 | |||
|
1 | 1 | CONFIGURATIONS = |
|
2 | 2 | [ |
|
3 | 3 | { |
|
4 | 4 | :key => 'system.single_user_mode', |
|
5 | 5 | :value_type => 'boolean', |
|
6 | 6 | :default_value => 'false', |
|
7 | 7 | :description => 'Only admins can log in to the system when running under single user mode.' |
|
8 | 8 | }, |
|
9 | 9 | |
|
10 | 10 | { |
|
11 | 11 | :key => 'ui.front.title', |
|
12 | 12 | :value_type => 'string', |
|
13 | 13 | :default_value => 'Grader' |
|
14 | 14 | }, |
|
15 | 15 | |
|
16 | 16 | { |
|
17 | 17 | :key => 'ui.front.welcome_message', |
|
18 | 18 | :value_type => 'string', |
|
19 | 19 | :default_value => 'Welcome!' |
|
20 | 20 | }, |
|
21 | 21 | |
|
22 | 22 | { |
|
23 | 23 | :key => 'ui.show_score', |
|
24 | 24 | :value_type => 'boolean', |
|
25 | 25 | :default_value => 'true' |
|
26 | 26 | }, |
|
27 | 27 | |
|
28 | 28 | { |
|
29 | 29 | :key => 'contest.time_limit', |
|
30 | 30 | :value_type => 'string', |
|
31 | 31 | :default_value => 'unlimited', |
|
32 | 32 | :description => 'Time limit in format hh:mm, or "unlimited" for contests with no time limits. This config is CACHED. Restart the server before the change can take effect.' |
|
33 | 33 | }, |
|
34 | 34 | |
|
35 | 35 | { |
|
36 | 36 | :key => 'system.mode', |
|
37 | 37 | :value_type => 'string', |
|
38 | 38 | :default_value => 'standard', |
|
39 | 39 | :description => 'Current modes are "standard", "contest", "indv-contest", and "analysis".' |
|
40 | 40 | }, |
|
41 | 41 | |
|
42 | 42 | { |
|
43 | 43 | :key => 'contest.name', |
|
44 | 44 | :value_type => 'string', |
|
45 | 45 | :default_value => 'Grader', |
|
46 | 46 | :description => 'This name will be shown on the user header bar.' |
|
47 | 47 | }, |
|
48 | 48 | |
|
49 | 49 | { |
|
50 | 50 | :key => 'contest.multisites', |
|
51 | 51 | :value_type => 'boolean', |
|
52 | 52 | :default_value => 'false', |
|
53 | 53 | :description => 'If the server is in contest mode and this option is true, on the log in of the admin a menu for site selections is shown.' |
|
54 | 54 | }, |
|
55 | 55 | |
|
56 | 56 | #---------------------------- right -------------------------------- |
|
57 | 57 | { |
|
58 | 58 | :key => 'right.user_hall_of_fame', |
|
59 | 59 | :value_type => 'boolean', |
|
60 | 60 | :default_value => 'false', |
|
61 | 61 | :description => 'If true, any user can access hall of fame page.' |
|
62 | 62 | }, |
|
63 | 63 | |
|
64 | 64 | { |
|
65 | 65 | :key => 'right.multiple_ip_login', |
|
66 | 66 | :value_type => 'boolean', |
|
67 | 67 | :default_value => 'true', |
|
68 | 68 | :description => 'When change from true to false, a user can login from the first IP they logged into afterward.' |
|
69 | 69 | }, |
|
70 | 70 | |
|
71 | 71 | { |
|
72 | 72 | :key => 'right.user_view_submission', |
|
73 | 73 | :value_type => 'boolean', |
|
74 | 74 | :default_value => 'false', |
|
75 | 75 | :description => 'If true, any user can view submissions of every one.' |
|
76 | 76 | }, |
|
77 | 77 | |
|
78 | 78 | { |
|
79 | 79 | :key => 'right.bypass_agreement', |
|
80 | 80 | :value_type => 'boolean', |
|
81 | 81 | :default_value => 'true', |
|
82 | 82 | :description => 'When false, a user must accept usage agreement before login' |
|
83 | 83 | }, |
|
84 | 84 | |
|
85 | 85 | { |
|
86 | 86 | :key => 'right.heartbeat_response', |
|
87 | 87 | :value_type => 'string', |
|
88 | 88 | :default_value => 'OK', |
|
89 | 89 | :description => 'Heart beat response text' |
|
90 | 90 | }, |
|
91 | 91 | |
|
92 | 92 | { |
|
93 | 93 | :key => 'right.heartbeat_response_full', |
|
94 | 94 | :value_type => 'string', |
|
95 | 95 | :default_value => 'OK', |
|
96 | 96 | :description => 'Heart beat response text when user got full score (set this value to the empty string to disable this feature)' |
|
97 | 97 | }, |
|
98 | 98 | |
|
99 | 99 | { |
|
100 | 100 | :key => 'right.view_testcase', |
|
101 | 101 | :value_type => 'boolean', |
|
102 | 102 | :default_value => 'false', |
|
103 | 103 | :description => 'If true, any user can view/download test data' |
|
104 | 104 | }, |
|
105 | 105 | |
|
106 | 106 | { |
|
107 | 107 | :key => 'system.online_registration', |
|
108 | 108 | :value_type => 'boolean', |
|
109 | 109 | :default_value => 'false', |
|
110 | 110 | :description => 'This option enables online registration.' |
|
111 | 111 | }, |
|
112 | 112 | |
|
113 | 113 | # If Configuration['system.online_registration'] is true, the |
|
114 | 114 | # system allows online registration, and will use these |
|
115 | 115 | # information for sending confirmation emails. |
|
116 | 116 | { |
|
117 | 117 | :key => 'system.online_registration.smtp', |
|
118 | 118 | :value_type => 'string', |
|
119 | 119 | :default_value => 'smtp.somehost.com' |
|
120 | 120 | }, |
|
121 | 121 | |
|
122 | 122 | { |
|
123 | 123 | :key => 'system.online_registration.from', |
|
124 | 124 | :value_type => 'string', |
|
125 | 125 | :default_value => 'your.email@address' |
|
126 | 126 | }, |
|
127 | 127 | |
|
128 | 128 | { |
|
129 | 129 | :key => 'system.admin_email', |
|
130 | 130 | :value_type => 'string', |
|
131 | 131 | :default_value => 'admin@admin.email' |
|
132 | 132 | }, |
|
133 | 133 | |
|
134 | 134 | { |
|
135 | 135 | :key => 'system.user_setting_enabled', |
|
136 | 136 | :value_type => 'boolean', |
|
137 | 137 | :default_value => 'true', |
|
138 | 138 | :description => 'If this option is true, users can change their settings' |
|
139 | 139 | }, |
|
140 | 140 | |
|
141 | 141 | { |
|
142 | 142 | :key => 'system.user_setting_enabled', |
|
143 | 143 | :value_type => 'boolean', |
|
144 | 144 | :default_value => 'true', |
|
145 | 145 | :description => 'If this option is true, users can change their settings' |
|
146 | 146 | }, |
|
147 | 147 | |
|
148 | 148 | # If Configuration['contest.test_request.early_timeout'] is true |
|
149 | 149 | # the user will not be able to use test request at 30 minutes |
|
150 | 150 | # before the contest ends. |
|
151 | 151 | { |
|
152 | 152 | :key => 'contest.test_request.early_timeout', |
|
153 | 153 | :value_type => 'boolean', |
|
154 | 154 | :default_value => 'false' |
|
155 | 155 | }, |
|
156 | 156 | |
|
157 | 157 | { |
|
158 | 158 | :key => 'system.multicontests', |
|
159 | 159 | :value_type => 'boolean', |
|
160 | 160 | :default_value => 'false' |
|
161 | 161 | }, |
|
162 | 162 | |
|
163 | 163 | { |
|
164 | 164 | :key => 'contest.confirm_indv_contest_start', |
|
165 | 165 | :value_type => 'boolean', |
|
166 | 166 | :default_value => 'false' |
|
167 | 167 | }, |
|
168 | 168 | |
|
169 | 169 | { |
|
170 | 170 | :key => 'contest.default_contest_name', |
|
171 | 171 | :value_type => 'string', |
|
172 | 172 | :default_value => 'none', |
|
173 | 173 | :description => "New user will be assigned to this contest automatically, if it exists. Set to 'none' if there is no default contest." |
|
174 | 174 | }, |
|
175 | 175 | |
|
176 | 176 | { |
|
177 | 177 | :key => 'system.use_problem_group', |
|
178 | 178 | :value_type => 'boolean', |
|
179 | 179 | :default_value => 'false', |
|
180 | 180 | :description => "If true, available problem to the user will be only ones associated with the group of the user." |
|
181 | 181 | }, |
|
182 | 182 | |
|
183 | 183 | |
|
184 | 184 | { |
|
185 | 185 | :key => 'right.whitelist_ignore', |
|
186 | 186 | :value_type => 'boolean', |
|
187 | 187 | :default_value => 'true', |
|
188 | 188 | :description => "If true, no IP check against whitelist_ip is perform. However, when false, non-admin user must have their ip in 'whitelist_ip' to be able to login." |
|
189 | 189 | }, |
|
190 | 190 | |
|
191 | 191 | { |
|
192 | 192 | :key => 'right.whitelist_ip', |
|
193 | 193 | :value_type => 'string', |
|
194 | 194 | :default_value => '0.0.0.0/0', |
|
195 | 195 | :description => "list of whitelist ip, given in comma separated CIDR notation. For example '192.168.90.0/23, 192.168.1.23/32'" |
|
196 | 196 | }, |
|
197 | 197 | |
|
198 | 198 | ] |
|
199 | 199 | |
|
200 | 200 | |
|
201 | 201 | def create_configuration_key(key, |
|
202 | 202 | value_type, |
|
203 | 203 | default_value, |
|
204 | 204 | description='') |
|
205 | 205 | conf = (GraderConfiguration.find_by_key(key) || |
|
206 | 206 | GraderConfiguration.new(:key => key, |
|
207 | 207 | :value_type => value_type, |
|
208 | 208 | :value => default_value)) |
|
209 | 209 | conf.description = description |
|
210 | 210 | conf.save |
|
211 | 211 | end |
|
212 | 212 | |
|
213 | 213 | def seed_config |
|
214 | 214 | CONFIGURATIONS.each do |conf| |
|
215 | 215 | if conf.has_key? :description |
|
216 | 216 | desc = conf[:description] |
|
217 | 217 | else |
|
218 | 218 | desc = '' |
|
219 | 219 | end |
|
220 | 220 | create_configuration_key(conf[:key], |
|
221 | 221 | conf[:value_type], |
|
222 | 222 | conf[:default_value], |
|
223 | 223 | desc) |
|
224 | 224 | end |
|
225 | 225 | end |
|
226 | 226 | |
|
227 | 227 | def seed_roles |
|
228 |
- Role.find_or_create_by(name: ' |
|
|
228 | + Role.find_or_create_by(name: 'ta') | |
|
229 | 229 | return if Role.find_by_name('admin') |
|
230 | 230 | |
|
231 | 231 | role = Role.create(:name => 'admin') |
|
232 | 232 | user_admin_right = Right.create(:name => 'user_admin', |
|
233 | 233 | :controller => 'user_admin', |
|
234 | 234 | :action => 'all') |
|
235 | 235 | problem_admin_right = Right.create(:name=> 'problem_admin', |
|
236 | 236 | :controller => 'problems', |
|
237 | 237 | :action => 'all') |
|
238 | 238 | |
|
239 | 239 | graders_right = Right.create(:name => 'graders_admin', |
|
240 | 240 | :controller => 'graders', |
|
241 | 241 | :action => 'all') |
|
242 | 242 | |
|
243 | 243 | role.rights << user_admin_right; |
|
244 | 244 | role.rights << problem_admin_right; |
|
245 | 245 | role.rights << graders_right; |
|
246 | 246 | role.save |
|
247 | 247 | end |
|
248 | 248 | |
|
249 | 249 | def seed_root |
|
250 | 250 | return if User.find_by_login('root') |
|
251 | 251 | |
|
252 | 252 | root = User.new(:login => 'root', |
|
253 | 253 | :full_name => 'Administrator', |
|
254 | 254 | :alias => 'root') |
|
255 | 255 | root.password = 'ioionrails'; |
|
256 | 256 | |
|
257 | 257 | class << root |
|
258 | 258 | public :encrypt_new_password |
|
259 | 259 | def valid?(context=nil) |
|
260 | 260 | true |
|
261 | 261 | end |
|
262 | 262 | end |
|
263 | 263 | |
|
264 | 264 | root.encrypt_new_password |
|
265 | 265 | |
|
266 | 266 | root.roles << Role.find_by_name('admin') |
|
267 | 267 | |
|
268 | 268 | root.activated = true |
|
269 | 269 | root.save |
|
270 | 270 | end |
|
271 | 271 | |
|
272 | 272 | def seed_users_and_roles |
|
273 | 273 | seed_roles |
|
274 | 274 | seed_root |
|
275 | 275 | end |
|
276 | 276 | |
|
277 | 277 | def seed_more_languages |
|
278 | 278 | #Language.delete_all |
|
279 | 279 | Language.find_or_create_by( name: 'c', pretty_name: 'C', ext: 'c', common_ext: 'c' ) |
|
280 | 280 | Language.find_or_create_by( name: 'cpp', pretty_name: 'C++', ext: 'cpp', common_ext: 'cpp,cc' ) |
|
281 | 281 | Language.find_or_create_by( name: 'pas', pretty_name: 'Pascal', ext: 'pas', common_ext: 'pas' ) |
|
282 | 282 | Language.find_or_create_by( name: 'ruby', pretty_name: 'Ruby', ext: 'rb', common_ext: 'rb' ) |
|
283 | 283 | Language.find_or_create_by( name: 'python', pretty_name: 'Python', ext: 'py', common_ext: 'py' ) |
|
284 | 284 | Language.find_or_create_by( name: 'java', pretty_name: 'Java', ext: 'java', common_ext: 'java' ) |
|
285 | 285 | end |
|
286 | 286 | |
|
287 | 287 | seed_config |
|
288 | 288 | seed_users_and_roles |
|
289 | 289 | seed_more_languages |
You need to be logged in to leave comments.
Login now