Description:
report ip
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r442:ce576ec8e8c3 - - 2 files changed: 10 inserted, 2 deleted
@@ -1,137 +1,141 | |||
|
1 | 1 | class ReportController < ApplicationController |
|
2 | 2 | |
|
3 | 3 | before_filter :admin_authorization, only: [:login_stat,:submission_stat] |
|
4 | 4 | before_filter(only: [:problem_hof]) { |c| |
|
5 | 5 | return false unless authenticate |
|
6 | 6 | |
|
7 | 7 | if GraderConfiguration["right.user_view_submission"] |
|
8 | 8 | return true; |
|
9 | 9 | end |
|
10 | 10 | |
|
11 | 11 | admin_authorization |
|
12 | 12 | } |
|
13 | 13 | |
|
14 | 14 | def login_stat |
|
15 | 15 | @logins = Array.new |
|
16 | 16 | |
|
17 | 17 | date_and_time = '%Y-%m-%d %H:%M' |
|
18 | 18 | begin |
|
19 | 19 | @since_time = DateTime.strptime(params[:since_datetime],date_and_time) |
|
20 | 20 | rescue |
|
21 | 21 | @since_time = DateTime.new(1000,1,1) |
|
22 | 22 | end |
|
23 | 23 | begin |
|
24 | 24 | @until_time = DateTime.strptime(params[:until_datetime],date_and_time) |
|
25 | 25 | rescue |
|
26 | 26 | @until_time = DateTime.new(3000,1,1) |
|
27 | 27 | end |
|
28 | 28 | |
|
29 | 29 | User.all.each do |user| |
|
30 | 30 | @logins << { id: user.id, |
|
31 | 31 | login: user.login, |
|
32 | 32 | full_name: user.full_name, |
|
33 | 33 | count: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
34 | 34 | user.id,@since_time,@until_time) |
|
35 | 35 | .count(:id), |
|
36 | 36 | min: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
37 | 37 | user.id,@since_time,@until_time) |
|
38 | 38 | .minimum(:created_at), |
|
39 | 39 | max: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", |
|
40 | 40 | user.id,@since_time,@until_time) |
|
41 | - .maximum(:created_at) | |
|
41 | + .maximum(:created_at), | |
|
42 | + ip: Login.where("user_id = ? AND created_at >= ? AND created_at <= ?", | |
|
43 | + user.id,@since_time,@until_time) | |
|
44 | + .select(:ip_address).uniq | |
|
45 | + | |
|
42 | 46 | } |
|
43 | 47 | end |
|
44 | 48 | end |
|
45 | 49 | |
|
46 | 50 | def submission_stat |
|
47 | 51 | |
|
48 | 52 | date_and_time = '%Y-%m-%d %H:%M' |
|
49 | 53 | begin |
|
50 | 54 | @since_time = DateTime.strptime(params[:since_datetime],date_and_time) |
|
51 | 55 | rescue |
|
52 | 56 | @since_time = DateTime.new(1000,1,1) |
|
53 | 57 | end |
|
54 | 58 | begin |
|
55 | 59 | @until_time = DateTime.strptime(params[:until_datetime],date_and_time) |
|
56 | 60 | rescue |
|
57 | 61 | @until_time = DateTime.new(3000,1,1) |
|
58 | 62 | end |
|
59 | 63 | |
|
60 | 64 | @submissions = {} |
|
61 | 65 | |
|
62 | 66 | User.find_each do |user| |
|
63 | 67 | @submissions[user.id] = { login: user.login, full_name: user.full_name, count: 0, sub: { } } |
|
64 | 68 | end |
|
65 | 69 | |
|
66 | 70 | Submission.where("submitted_at >= ? AND submitted_at <= ?",@since_time,@until_time).find_each do |s| |
|
67 | 71 | if @submissions[s.user_id] |
|
68 | 72 | if not @submissions[s.user_id][:sub].has_key?(s.problem_id) |
|
69 | 73 | a = nil |
|
70 | 74 | begin |
|
71 | 75 | a = Problem.find(s.problem_id) |
|
72 | 76 | rescue |
|
73 | 77 | a = nil |
|
74 | 78 | end |
|
75 | 79 | @submissions[s.user_id][:sub][s.problem_id] = |
|
76 | 80 | { prob_name: (a ? a.full_name : '(NULL)'), |
|
77 | 81 | sub_ids: [s.id] } |
|
78 | 82 | else |
|
79 | 83 | @submissions[s.user_id][:sub][s.problem_id][:sub_ids] << s.id |
|
80 | 84 | end |
|
81 | 85 | @submissions[s.user_id][:count] += 1 |
|
82 | 86 | end |
|
83 | 87 | end |
|
84 | 88 | end |
|
85 | 89 | |
|
86 | 90 | def problem_hof |
|
87 | 91 | # gen problem list |
|
88 | 92 | @user = User.find(session[:user_id]) |
|
89 | 93 | @problems = @user.available_problems |
|
90 | 94 | |
|
91 | 95 | # get selected problems or the default |
|
92 | 96 | if params[:id] |
|
93 | 97 | begin |
|
94 | 98 | @problem = Problem.available.find(params[:id]) |
|
95 | 99 | rescue |
|
96 | 100 | redirect_to action: :problem_hof |
|
97 | 101 | flash[:notice] = 'Error: submissions for that problem are not viewable.' |
|
98 | 102 | return |
|
99 | 103 | end |
|
100 | 104 | end |
|
101 | 105 | |
|
102 | 106 | if @problem |
|
103 | 107 | #aggregrate by language |
|
104 | 108 | @by_lang = {} |
|
105 | 109 | Submission.where(problem_id: @problem.id).find_each do |sub| |
|
106 | 110 | lang = Language.find_by_id(sub.language_id) |
|
107 | 111 | next unless lang |
|
108 | 112 | next unless sub.points >= @problem.full_score |
|
109 | 113 | |
|
110 | 114 | #initialize |
|
111 | 115 | unless @by_lang.has_key?(lang.pretty_name) |
|
112 | 116 | @by_lang[lang.pretty_name] = { |
|
113 | 117 | runtime: { avail: false, value: 2**30-1 }, |
|
114 | 118 | memory: { avail: false, value: 2**30-1 }, |
|
115 | 119 | length: { avail: false, value: 2**30-1 }, |
|
116 | 120 | first: { avail: false, value: DateTime.new(3000,1,1) } |
|
117 | 121 | } |
|
118 | 122 | end |
|
119 | 123 | |
|
120 | 124 | if sub.max_runtime and sub.max_runtime < @by_lang[lang.pretty_name][:runtime][:value] |
|
121 | 125 | @by_lang[lang.pretty_name][:runtime] = { |
|
122 | 126 | avail: true, |
|
123 | 127 | user_id: sub.user_id, |
|
124 | 128 | value: sub.max_runtime, |
|
125 | 129 | sub_id: sub.id |
|
126 | 130 | } |
|
127 | 131 | end |
|
128 | 132 | |
|
129 | 133 | if sub.peak_memory and sub.peak_memory < @by_lang[lang.pretty_name][:memory][:value] |
|
130 | 134 | @by_lang[lang.pretty_name][:memory] = { |
|
131 | 135 | avail: true, |
|
132 | 136 | user_id: sub.user_id, |
|
133 | 137 | value: sub.peak_memory, |
|
134 | 138 | sub_id: sub.id |
|
135 | 139 | } |
|
136 | 140 | end |
|
137 | 141 |
@@ -1,32 +1,36 | |||
|
1 | 1 | - content_for :header do |
|
2 | 2 | = stylesheet_link_tag 'tablesorter-theme.cafe' |
|
3 | 3 | = javascript_include_tag 'new' |
|
4 | 4 | |
|
5 | 5 | %script{:type=>"text/javascript"} |
|
6 | 6 | $(function () { |
|
7 | 7 | $('#since_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} ); |
|
8 | 8 | $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} ); |
|
9 | 9 | $('#my_table').tablesorter({widthFixed: true, widgets: ['zebra']}); |
|
10 | 10 | }); |
|
11 | 11 | |
|
12 | 12 | %h1 Login status |
|
13 | 13 | |
|
14 | 14 | =render partial: 'report_menu' |
|
15 | 15 | =render partial: 'date_range', locals: {param_text: 'Login date range:', title: 'Query login stat in the range' } |
|
16 | 16 | |
|
17 | 17 | %table.tablesorter-cafe#my_table |
|
18 | 18 | %thead |
|
19 | 19 | %tr |
|
20 | 20 | %th login |
|
21 | 21 | %th full name |
|
22 | 22 | %th login count |
|
23 | 23 | %th earliest |
|
24 | 24 | %th latest |
|
25 | + %th IP | |
|
25 | 26 | %tbody |
|
26 | 27 | - @logins.each do |l| |
|
27 | 28 | %tr{class: cycle('info-even','info-odd')} |
|
28 | 29 | %td= link_to l[:login], controller: 'users', action: 'profile', id: l[:id] |
|
29 | 30 | %td= l[:full_name] |
|
30 | 31 | %td= l[:count] |
|
31 | 32 | %td= l[:min] ? l[:min].in_time_zone.strftime('%Y-%m-%d %H:%M') : '' |
|
32 | - %td= l[:max] ? "#{l[:max].in_time_zone.strftime('%Y-%m-%d %H:%M')} (#{time_ago_in_words(l[:max].in_time_zone)} ago)" : '' | |
|
33 | + %td= l[:max] ? "#{l[:max].in_time_zone.strftime('%Y-%m-%d %H:%M.%S')} (#{time_ago_in_words(l[:max].in_time_zone)} ago)" : '' | |
|
34 | + %td | |
|
35 | + - l[:ip].each do |ip| | |
|
36 | + #{ip.ip_address} <br/> |
You need to be logged in to leave comments.
Login now