Description:
fix date time
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r443:2d5e2b9fa726 - - 1 file changed: 4 inserted, 2 deleted
@@ -1,120 +1,122 | |||||
|
1 | class ReportController < ApplicationController |
|
1 | class ReportController < ApplicationController |
|
2 |
|
2 | ||
|
3 | before_filter :admin_authorization, only: [:login_stat,:submission_stat] |
|
3 | before_filter :admin_authorization, only: [:login_stat,:submission_stat] |
|
4 | before_filter(only: [:problem_hof]) { |c| |
|
4 | before_filter(only: [:problem_hof]) { |c| |
|
5 | return false unless authenticate |
|
5 | return false unless authenticate |
|
6 |
|
6 | ||
|
7 | if GraderConfiguration["right.user_view_submission"] |
|
7 | if GraderConfiguration["right.user_view_submission"] |
|
8 | return true; |
|
8 | return true; |
|
9 | end |
|
9 | end |
|
10 |
|
10 | ||
|
11 | admin_authorization |
|
11 | admin_authorization |
|
12 | } |
|
12 | } |
|
13 |
|
13 | ||
|
14 | def login_stat |
|
14 | def login_stat |
|
15 | @logins = Array.new |
|
15 | @logins = Array.new |
|
16 |
|
16 | ||
|
17 | date_and_time = '%Y-%m-%d %H:%M' |
|
17 | date_and_time = '%Y-%m-%d %H:%M' |
|
18 | begin |
|
18 | begin |
|
19 | - @since_time = DateTime.strptime(params[:since_datetime],date_and_time) |
|
19 | + md = params[:since_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
|
20 | + @since_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) | ||
|
20 | rescue |
|
21 | rescue |
|
21 | @since_time = DateTime.new(1000,1,1) |
|
22 | @since_time = DateTime.new(1000,1,1) |
|
22 | end |
|
23 | end |
|
23 | begin |
|
24 | begin |
|
24 | - @until_time = DateTime.strptime(params[:until_datetime],date_and_time) |
|
25 | + md = params[:until_datetime].match(/(\d+)-(\d+)-(\d+) (\d+):(\d+)/) |
|
|
26 | + @until_time = Time.zone.local(md[1].to_i,md[2].to_i,md[3].to_i,md[4].to_i,md[5].to_i) | ||
|
25 | rescue |
|
27 | rescue |
|
26 | @until_time = DateTime.new(3000,1,1) |
|
28 | @until_time = DateTime.new(3000,1,1) |
|
27 | end |
|
29 | end |
|
28 |
|
30 | ||
|
29 | User.all.each do |user| |
|
31 | User.all.each do |user| |
|
30 | @logins << { id: user.id, |
|
32 | @logins << { id: user.id, |
|
31 | login: user.login, |
|
33 | login: user.login, |
|
32 | full_name: user.full_name, |
|
34 | full_name: user.full_name, |
|
33 | count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
35 | count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
34 | user.id,@since_time,@until_time) |
|
36 | user.id,@since_time,@until_time) |
|
35 | .count(:id), |
|
37 | .count(:id), |
|
36 | min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
38 | min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
37 | user.id,@since_time,@until_time) |
|
39 | user.id,@since_time,@until_time) |
|
38 | .minimum(:created_at), |
|
40 | .minimum(:created_at), |
|
39 | max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
41 | max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
40 | user.id,@since_time,@until_time) |
|
42 | user.id,@since_time,@until_time) |
|
41 | .maximum(:created_at), |
|
43 | .maximum(:created_at), |
|
42 | ip: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
44 | ip: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
43 | user.id,@since_time,@until_time) |
|
45 | user.id,@since_time,@until_time) |
|
44 | .select(:ip_address).uniq |
|
46 | .select(:ip_address).uniq |
|
45 |
|
47 | ||
|
46 | } |
|
48 | } |
|
47 | end |
|
49 | end |
|
48 | end |
|
50 | end |
|
49 |
|
51 | ||
|
50 | def submission_stat |
|
52 | def submission_stat |
|
51 |
|
53 | ||
|
52 | date_and_time = '%Y-%m-%d %H:%M' |
|
54 | date_and_time = '%Y-%m-%d %H:%M' |
|
53 | begin |
|
55 | begin |
|
54 | @since_time = DateTime.strptime(params[:since_datetime],date_and_time) |
|
56 | @since_time = DateTime.strptime(params[:since_datetime],date_and_time) |
|
55 | rescue |
|
57 | rescue |
|
56 | @since_time = DateTime.new(1000,1,1) |
|
58 | @since_time = DateTime.new(1000,1,1) |
|
57 | end |
|
59 | end |
|
58 | begin |
|
60 | begin |
|
59 | @until_time = DateTime.strptime(params[:until_datetime],date_and_time) |
|
61 | @until_time = DateTime.strptime(params[:until_datetime],date_and_time) |
|
60 | rescue |
|
62 | rescue |
|
61 | @until_time = DateTime.new(3000,1,1) |
|
63 | @until_time = DateTime.new(3000,1,1) |
|
62 | end |
|
64 | end |
|
63 |
|
65 | ||
|
64 | @submissions = {} |
|
66 | @submissions = {} |
|
65 |
|
67 | ||
|
66 | User.find_each do |user| |
|
68 | User.find_each do |user| |
|
67 | @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } } |
|
69 | @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } } |
|
68 | end |
|
70 | end |
|
69 |
|
71 | ||
|
70 | Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s| |
|
72 | Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s| |
|
71 | if @submissions[s.user_id] |
|
73 | if @submissions[s.user_id] |
|
72 | if not @submissions[s.user_id][:sub].has_key?(s.problem_id) |
|
74 | if not @submissions[s.user_id][:sub].has_key?(s.problem_id) |
|
73 | a = nil |
|
75 | a = nil |
|
74 | begin |
|
76 | begin |
|
75 | a = Problem.find(s.problem_id) |
|
77 | a = Problem.find(s.problem_id) |
|
76 | rescue |
|
78 | rescue |
|
77 | a = nil |
|
79 | a = nil |
|
78 | end |
|
80 | end |
|
79 | @submissions[s.user_id][:sub][s.problem_id] = |
|
81 | @submissions[s.user_id][:sub][s.problem_id] = |
|
80 | { prob_name: (a ? a.full_name : '(NULL)'), |
|
82 | { prob_name: (a ? a.full_name : '(NULL)'), |
|
81 | sub_ids: [s.id] } |
|
83 | sub_ids: [s.id] } |
|
82 | else |
|
84 | else |
|
83 | @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id |
|
85 | @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id |
|
84 | end |
|
86 | end |
|
85 | @submissions[s.user_id][:count] += 1 |
|
87 | @submissions[s.user_id][:count] += 1 |
|
86 | end |
|
88 | end |
|
87 | end |
|
89 | end |
|
88 | end |
|
90 | end |
|
89 |
|
91 | ||
|
90 | def problem_hof |
|
92 | def problem_hof |
|
91 | # gen problem list |
|
93 | # gen problem list |
|
92 | @user = User.find(session[:user_id]) |
|
94 | @user = User.find(session[:user_id]) |
|
93 | @problems = @user.available_problems |
|
95 | @problems = @user.available_problems |
|
94 |
|
96 | ||
|
95 | # get selected problems or the default |
|
97 | # get selected problems or the default |
|
96 | if params[:id] |
|
98 | if params[:id] |
|
97 | begin |
|
99 | begin |
|
98 | @problem = Problem.available.find(params[:id]) |
|
100 | @problem = Problem.available.find(params[:id]) |
|
99 | rescue |
|
101 | rescue |
|
100 | redirect_to action: :problem_hof |
|
102 | redirect_to action: :problem_hof |
|
101 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
103 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
102 | return |
|
104 | return |
|
103 | end |
|
105 | end |
|
104 | end |
|
106 | end |
|
105 |
|
107 | ||
|
106 | if @problem |
|
108 | if @problem |
|
107 | #aggregrate by language |
|
109 | #aggregrate by language |
|
108 | @by_lang = {} |
|
110 | @by_lang = {} |
|
109 | Submission.where(problem_id: @problem.id).find_each do |sub| |
|
111 | Submission.where(problem_id: @problem.id).find_each do |sub| |
|
110 | lang = Language.find_by_id(sub.language_id) |
|
112 | lang = Language.find_by_id(sub.language_id) |
|
111 | next unless lang |
|
113 | next unless lang |
|
112 | next unless sub.points >= @problem.full_score |
|
114 | next unless sub.points >= @problem.full_score |
|
113 |
|
115 | ||
|
114 | #initialize |
|
116 | #initialize |
|
115 | unless @by_lang.has_key?(lang.pretty_name) |
|
117 | unless @by_lang.has_key?(lang.pretty_name) |
|
116 | @by_lang[lang.pretty_name] = { |
|
118 | @by_lang[lang.pretty_name] = { |
|
117 | runtime: { avail: false, value: 2**30-1 }, |
|
119 | runtime: { avail: false, value: 2**30-1 }, |
|
118 | memory: { avail: false, value: 2**30-1 }, |
|
120 | memory: { avail: false, value: 2**30-1 }, |
|
119 | length: { avail: false, value: 2**30-1 }, |
|
121 | length: { avail: false, value: 2**30-1 }, |
|
120 | first: { avail: false, value: DateTime.new(3000,1,1) } |
|
122 | first: { avail: false, value: DateTime.new(3000,1,1) } |
You need to be logged in to leave comments.
Login now