Description:
more heart beat feature add reset last login ip (grafted from 6efa41a1cfdc5e910b85eec6d8b874ed651776bd)
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r541:11c20f65a6b8 - - 7 files changed: 92 inserted, 33 deleted

@@ -0,0 +1,30
1 + - content_for :header do
2 + = javascript_include_tag 'local_jquery'
3 + = stylesheet_link_tag 'tablesorter-theme.cafe'
4 +
5 + %script{:type=>"text/javascript"}
6 + $(function () {
7 + $('#since_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
8 + $('#until_datetime').datetimepicker({ showButtonPanel: true, dateFormat: "yy-mm-dd", controlType: "slider"} );
9 + $('#my_table').tablesorter({widgets: ['zebra']});
10 + });
11 +
12 + %h1 Heart Beat Count
13 + = "Last 5 minutes distinct user count = #{@num}"
14 +
15 + %h1 Heart Beat List
16 +
17 + %table.tablesorter-cafe#my_table
18 + %thead
19 + %tr
20 + %th Login
21 + %th Full name
22 + %th IP
23 + %th Last Update
24 + %tbody
25 + - @hb.each do |hb|
26 + %tr{class: cycle('info-even','info-odd')}
27 + %td= link_to hb.user.login, controller: :users, :action => 'profile', :id => hb.user.id
28 + %td= hb.user.full_name
29 + %td= hb.ip_address
30 + %td= "#{time_ago_in_words(hb.updated_at)} ago"
@@ -0,0 +1,5
1 + class AddStatusToHeartBeat < ActiveRecord::Migration
2 + def change
3 + add_column :heart_beats, :status, :string
4 + end
5 + end
@@ -1,14 +1,29
1 1 class HeartbeatController < ApplicationController
2 + before_filter :admin_authorization, :only => ['index']
3 +
2 4 def edit
3 - render layout: 'empty'
4 5 @user = User.find_by_login(params[:id])
5 - return unless @user
6 -
6 + unless @user
7 + render text: "LOGIN_NOT_FOUND"
8 + return
9 + end
10 +
7 11 hb = HeartBeat.where(user_id: @user.id, ip_address: request.remote_ip).first
12 + puts "status = #{params[:status]}"
8 13 if hb
14 + if params[:status]
15 + hb.status = params[:status]
16 + hb.save
17 + end
9 18 hb.touch
10 19 else
11 - HeartBeat.create(user_id: @user.id, ip_address: request.remote_ip)
20 + HeartBeat.creae(user_id: @user.id, ip_address: request.remote_ip)
12 21 end
22 + render text: "OK"
23 + end
24 +
25 + def index
26 + @hb = HeartBeat.includes(:user).order(:user_id).all
27 + @num = HeartBeat.where("updated_at >= ?",Time.zone.now-5.minutes).count
13 28 end
14 29 end
@@ -17,96 +17,103
17 17
18 18 def index
19 19 list
20 20 render :action => 'list'
21 21 end
22 22
23 23 def list
24 24 @user_count = User.count
25 25 if params[:page] == 'all'
26 26 @users = User.all
27 27 @paginated = false
28 28 else
29 29 @users = User.paginate :page => params[:page]
30 30 @paginated = true
31 31 end
32 32 @hidden_columns = ['hashed_password', 'salt', 'created_at', 'updated_at']
33 33 @contests = Contest.enabled
34 34 end
35 35
36 36 def active
37 37 sessions = ActiveRecord::SessionStore::Session.find(:all, :conditions => ["updated_at >= ?", 60.minutes.ago])
38 38 @users = []
39 39 sessions.each do |session|
40 40 if session.data[:user_id]
41 41 @users << User.find(session.data[:user_id])
42 42 end
43 43 end
44 44 end
45 45
46 46 def show
47 47 @user = User.find(params[:id])
48 48 end
49 49
50 50 def new
51 51 @user = User.new
52 52 end
53 53
54 54 def create
55 55 @user = User.new(params[:user])
56 56 @user.activated = true
57 57 if @user.save
58 58 flash[:notice] = 'User was successfully created.'
59 59 redirect_to :action => 'list'
60 60 else
61 61 render :action => 'new'
62 62 end
63 63 end
64 64
65 + def clear_last_ip
66 + @user = User.find(params[:id])
67 + @user.last_ip = nil
68 + @user.save
69 + redirect_to action: 'list', page: params[:page]
70 + end
71 +
65 72 def create_from_list
66 73 lines = params[:user_list]
67 74
68 75 note = []
69 76
70 77 lines.split("\n").each do |line|
71 78 items = line.chomp.split(',')
72 79 if items.length>=2
73 80 login = items[0]
74 81 full_name = items[1]
75 82
76 83 added_random_password = false
77 84 if items.length>=3
78 85 password = items[2].chomp(" ")
79 86 user_alias = (items.length>=4) ? items[3] : login
80 87 else
81 88 password = random_password
82 89 user_alias = (items.length>=4) ? items[3] : login
83 90 added_random_password = true
84 91 end
85 92
86 93 user = User.find_by_login(login)
87 94 if (user)
88 95 user.full_name = full_name
89 96 user.password = password
90 97 else
91 98 user = User.new({:login => login,
92 99 :full_name => full_name,
93 100 :password => password,
94 101 :password_confirmation => password,
95 102 :alias => user_alias})
96 103 end
97 104 user.activated = true
98 105 user.save
99 106
100 107 if added_random_password
101 108 note << "'#{login}' (+)"
102 109 else
103 110 note << login
104 111 end
105 112 end
106 113 end
107 114 flash[:notice] = 'User(s) ' + note.join(', ') +
108 115 ' were successfully created. ' +
109 116 '( (+) - created with random passwords.)'
110 117 redirect_to :action => 'list'
111 118 end
112 119
@@ -168,97 +175,97
168 175 @scorearray = Array.new
169 176 #set up range from param
170 177 since_id = params.fetch(:since_id, 0).to_i
171 178 until_id = params.fetch(:until_id, 0).to_i
172 179 @users.each do |u|
173 180 ustat = Array.new
174 181 ustat[0] = u
175 182 @problems.each do |p|
176 183 max_points = 0
177 184 Submission.find_in_range_by_user_and_problem(u.id,p.id,since_id,until_id).each do |sub|
178 185 max_points = sub.points if sub and sub.points and (sub.points > max_points)
179 186 end
180 187 ustat << [(max_points.to_f*100/p.full_score).round, (max_points>=p.full_score)]
181 188 end
182 189 @scorearray << ustat
183 190 end
184 191
185 192 if params[:commit] == 'download csv' then
186 193 csv = gen_csv_from_scorearray(@scorearray,@problems)
187 194 send_data csv, filename: 'max_score.csv'
188 195 else
189 196 render template: 'user_admin/user_stat'
190 197 end
191 198 end
192 199
193 200 def import
194 201 if params[:file]==''
195 202 flash[:notice] = 'Error importing no file'
196 203 redirect_to :action => 'list' and return
197 204 end
198 205 import_from_file(params[:file])
199 206 end
200 207
201 208 def random_all_passwords
202 209 users = User.find(:all)
203 210 @prefix = params[:prefix] || ''
204 211 @non_admin_users = User.find_non_admin_with_prefix(@prefix)
205 212 @changed = false
206 213 if request.request_method == 'POST'
207 214 @non_admin_users.each do |user|
208 215 password = random_password
209 216 user.password = password
210 217 user.password_confirmation = password
211 218 user.save
212 219 end
213 220 @changed = true
214 221 end
215 222 end
216 -
223 +
217 224 # contest management
218 225
219 226 def contests
220 227 @contest, @users = find_contest_and_user_from_contest_id(params[:id])
221 228 @contests = Contest.enabled
222 229 end
223 230
224 231 def assign_from_list
225 232 contest_id = params[:users_contest_id]
226 233 org_contest, users = find_contest_and_user_from_contest_id(contest_id)
227 234 contest = Contest.find(params[:new_contest][:id])
228 235 if !contest
229 236 flash[:notice] = 'Error: no contest'
230 237 redirect_to :action => 'contests', :id =>contest_id
231 238 end
232 239
233 240 note = []
234 241 users.each do |u|
235 242 u.contests = [contest]
236 243 note << u.login
237 244 end
238 245 flash[:notice] = 'User(s) ' + note.join(', ') +
239 246 " were successfully reassigned to #{contest.title}."
240 247 redirect_to :action => 'contests', :id =>contest.id
241 248 end
242 249
243 250 def add_to_contest
244 251 user = User.find(params[:id])
245 252 contest = Contest.find(params[:contest_id])
246 253 if user and contest
247 254 user.contests << contest
248 255 end
249 256 redirect_to :action => 'list'
250 257 end
251 258
252 259 def remove_from_contest
253 260 user = User.find(params[:id])
254 261 contest = Contest.find(params[:contest_id])
255 262 if user and contest
256 263 user.contests.delete(contest)
257 264 end
258 265 redirect_to :action => 'list'
259 266 end
260 267
261 268 def contest_management
262 269 end
263 270
264 271 def manage_contest
@@ -19,69 +19,71
19 19 <td><%= email_field 'user', 'email', :size => 15 %></td>
20 20 <td><%= submit_tag "Create" %></td>
21 21 </tr>
22 22 </table>
23 23 <% end %>
24 24 <br/>
25 25 <b>Import from site management</b>
26 26 <%= form_tag({:action => 'import'}, :multipart => true) do %>
27 27 File: <%= file_field_tag 'file' %> <%= submit_tag 'Import' %>
28 28 <% end %>
29 29 <br/>
30 30 <b>What else: </b>
31 31 <%= link_to '[New user]', :action => 'new' %>
32 32 <%= link_to '[New list of users]', :action => 'new_list' %>
33 33 <%= link_to '[View administrators]', :action => 'admin' %>
34 34 <%= link_to '[Random passwords]', :action => 'random_all_passwords' %>
35 35 <%= link_to '[View active users]', :action => 'active' %>
36 36 <%= link_to '[Mass mailing]', :action => 'mass_mailing' %>
37 37 <% if GraderConfiguration.multicontests? %>
38 38 <br/><b>Multi-contest:</b>
39 39 <%= link_to '[Manage bulk users in contests]', :action => 'contest_management' %>
40 40 View users in:
41 41 <% @contests.each do |contest| %>
42 42 <%= link_to "[#{contest.name}]", :action => 'contests', :id => contest.id %>
43 43 <% end %>
44 44 <%= link_to "[no contest]", :action => 'contests', :id => 'none' %>
45 45 <% end %>
46 46 </div>
47 47
48 48 Total <%= @user_count %> users |
49 49 <% if !@paginated %>
50 50 Display all users.
51 51 <%= link_to '[show in pages]', :action => 'list', :page => '1' %>
52 52 <% else %>
53 53 Display in pages.
54 54 <%= link_to '[display all]', :action => 'list', :page => 'all' %> |
55 55 <%= will_paginate @users, :container => false %>
56 56 <% end %>
57 57 <table class="info">
58 58 <tr class="info-head">
59 59 <% for column in User.content_columns %>
60 60 <% if !@hidden_columns.index(column.name) %>
61 61 <th><%= column.human_name %></th>
62 62 <% end %>
63 63 <% end %>
64 64 <th></th>
65 65 <th></th>
66 66 <th></th>
67 + <th></th>
67 68 </tr>
68 69
69 70 <% for user in @users %>
70 71 <tr class="info-<%= cycle("odd","even") %>">
71 72 <td><%= link_to user.login, controller: :users, :action => 'profile', :id => user %></td>
72 73 <% for column in User.content_columns %>
73 74 <% if !@hidden_columns.index(column.name) and column.name != 'login' %>
74 75 <td><%=h user.send(column.name) %></td>
75 76 <% end %>
76 77 <% end %>
78 + <td><%= link_to 'Clear IP', {:action => 'clear_last_ip', :id => user, :page=>params[:page]}, :confirm => 'This will reset last logging in ip of the user, are you sure?' %></td>
77 79 <td><%= link_to 'Show', :action => 'show', :id => user %></td>
78 80 <td><%= link_to 'Edit', :action => 'edit', :id => user %></td>
79 81 <td><%= link_to 'Destroy', { :action => 'destroy', :id => user }, :confirm => 'Are you sure?', :method => :post %></td>
80 82 </tr>
81 83 <% end %>
82 84 </table>
83 85
84 86 <br />
85 87
86 88 <%= link_to '[New user]', :action => 'new' %>
87 89 <%= link_to '[New list of users]', :action => 'new_list' %>
@@ -1,264 +1,265
1 1 # encoding: UTF-8
2 2 # This file is auto-generated from the current state of the database. Instead
3 3 # of editing this file, please use the migrations feature of Active Record to
4 4 # incrementally modify your database, and then regenerate this schema definition.
5 5 #
6 6 # Note that this schema.rb definition is the authoritative source for your
7 7 # database schema. If you need to create the application database on another
8 8 # system, you should be using db:schema:load, not running all the migrations
9 9 # from scratch. The latter is a flawed and unsustainable approach (the more migrations
10 10 # you'll amass, the slower it'll run and the greater likelihood for issues).
11 11 #
12 12 # It's strongly recommended to check this file into your version control system.
13 13
14 - ActiveRecord::Schema.define(:version => 20150914090545) do
14 + ActiveRecord::Schema.define(:version => 20150914155101) do
15 15
16 16 create_table "announcements", :force => true do |t|
17 17 t.string "author"
18 - t.text "body"
18 + t.text "body", :limit => 16777215
19 19 t.boolean "published"
20 - t.datetime "created_at", :null => false
21 - t.datetime "updated_at", :null => false
22 - t.boolean "frontpage", :default => false
23 - t.boolean "contest_only", :default => false
20 + t.datetime "created_at", :null => false
21 + t.datetime "updated_at", :null => false
22 + t.boolean "frontpage", :default => false
23 + t.boolean "contest_only", :default => false
24 24 t.string "title"
25 25 t.string "notes"
26 26 end
27 27
28 28 create_table "contests", :force => true do |t|
29 29 t.string "title"
30 30 t.boolean "enabled"
31 31 t.datetime "created_at", :null => false
32 32 t.datetime "updated_at", :null => false
33 33 t.string "name"
34 34 end
35 35
36 36 create_table "contests_problems", :id => false, :force => true do |t|
37 37 t.integer "contest_id"
38 38 t.integer "problem_id"
39 39 end
40 40
41 41 create_table "contests_users", :id => false, :force => true do |t|
42 42 t.integer "contest_id"
43 43 t.integer "user_id"
44 44 end
45 45
46 46 create_table "countries", :force => true do |t|
47 47 t.string "name"
48 48 t.datetime "created_at", :null => false
49 49 t.datetime "updated_at", :null => false
50 50 end
51 51
52 52 create_table "descriptions", :force => true do |t|
53 - t.text "body"
53 + t.text "body", :limit => 16777215
54 54 t.boolean "markdowned"
55 - t.datetime "created_at", :null => false
56 - t.datetime "updated_at", :null => false
55 + t.datetime "created_at", :null => false
56 + t.datetime "updated_at", :null => false
57 57 end
58 58
59 59 create_table "grader_configurations", :force => true do |t|
60 60 t.string "key"
61 61 t.string "value_type"
62 62 t.string "value"
63 - t.datetime "created_at", :null => false
64 - t.datetime "updated_at", :null => false
65 - t.text "description"
63 + t.datetime "created_at", :null => false
64 + t.datetime "updated_at", :null => false
65 + t.text "description", :limit => 16777215
66 66 end
67 67
68 68 create_table "grader_processes", :force => true do |t|
69 69 t.string "host", :limit => 20
70 70 t.integer "pid"
71 71 t.string "mode"
72 72 t.boolean "active"
73 73 t.datetime "created_at", :null => false
74 74 t.datetime "updated_at", :null => false
75 75 t.integer "task_id"
76 76 t.string "task_type"
77 77 t.boolean "terminated"
78 78 end
79 79
80 80 add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
81 81
82 82 create_table "heart_beats", :force => true do |t|
83 83 t.integer "user_id"
84 84 t.string "ip_address"
85 85 t.datetime "created_at", :null => false
86 86 t.datetime "updated_at", :null => false
87 + t.string "status"
87 88 end
88 89
89 90 create_table "languages", :force => true do |t|
90 91 t.string "name", :limit => 10
91 92 t.string "pretty_name"
92 93 t.string "ext", :limit => 10
93 94 t.string "common_ext"
94 95 end
95 96
96 97 create_table "logins", :force => true do |t|
97 98 t.integer "user_id"
98 99 t.string "ip_address"
99 100 t.datetime "created_at", :null => false
100 101 t.datetime "updated_at", :null => false
101 102 end
102 103
103 104 create_table "messages", :force => true do |t|
104 105 t.integer "sender_id"
105 106 t.integer "receiver_id"
106 107 t.integer "replying_message_id"
107 - t.text "body"
108 + t.text "body", :limit => 16777215
108 109 t.boolean "replied"
109 - t.datetime "created_at", :null => false
110 - t.datetime "updated_at", :null => false
110 + t.datetime "created_at", :null => false
111 + t.datetime "updated_at", :null => false
111 112 end
112 113
113 114 create_table "problems", :force => true do |t|
114 115 t.string "name", :limit => 30
115 116 t.string "full_name"
116 117 t.integer "full_score"
117 118 t.date "date_added"
118 119 t.boolean "available"
119 120 t.string "url"
120 121 t.integer "description_id"
121 122 t.boolean "test_allowed"
122 123 t.boolean "output_only"
123 124 t.string "description_filename"
124 125 end
125 126
126 127 create_table "rights", :force => true do |t|
127 128 t.string "name"
128 129 t.string "controller"
129 130 t.string "action"
130 131 end
131 132
132 133 create_table "rights_roles", :id => false, :force => true do |t|
133 134 t.integer "right_id"
134 135 t.integer "role_id"
135 136 end
136 137
137 138 add_index "rights_roles", ["role_id"], :name => "index_rights_roles_on_role_id"
138 139
139 140 create_table "roles", :force => true do |t|
140 141 t.string "name"
141 142 end
142 143
143 144 create_table "roles_users", :id => false, :force => true do |t|
144 145 t.integer "role_id"
145 146 t.integer "user_id"
146 147 end
147 148
148 149 add_index "roles_users", ["user_id"], :name => "index_roles_users_on_user_id"
149 150
150 151 create_table "sessions", :force => true do |t|
151 152 t.string "session_id"
152 - t.text "data"
153 + t.text "data", :limit => 16777215
153 154 t.datetime "updated_at"
154 155 end
155 156
156 157 add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
157 158 add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
158 159
159 160 create_table "sites", :force => true do |t|
160 161 t.string "name"
161 162 t.boolean "started"
162 163 t.datetime "start_time"
163 164 t.datetime "created_at", :null => false
164 165 t.datetime "updated_at", :null => false
165 166 t.integer "country_id"
166 167 t.string "password"
167 168 end
168 169
169 170 create_table "submission_view_logs", :force => true do |t|
170 171 t.integer "user_id"
171 172 t.integer "submission_id"
172 173 t.datetime "created_at", :null => false
173 174 t.datetime "updated_at", :null => false
174 175 end
175 176
176 177 create_table "submissions", :force => true do |t|
177 178 t.integer "user_id"
178 179 t.integer "problem_id"
179 180 t.integer "language_id"
180 - t.text "source"
181 + t.text "source", :limit => 16777215
181 182 t.binary "binary"
182 183 t.datetime "submitted_at"
183 184 t.datetime "compiled_at"
184 - t.text "compiler_message"
185 + t.text "compiler_message", :limit => 16777215
185 186 t.datetime "graded_at"
186 187 t.integer "points"
187 - t.text "grader_comment"
188 + t.text "grader_comment", :limit => 16777215
188 189 t.integer "number"
189 190 t.string "source_filename"
190 191 t.float "max_runtime"
191 192 t.integer "peak_memory"
192 193 t.integer "effective_code_length"
193 194 t.string "ip_address"
194 195 end
195 196
196 197 add_index "submissions", ["user_id", "problem_id", "number"], :name => "index_submissions_on_user_id_and_problem_id_and_number", :unique => true
197 198 add_index "submissions", ["user_id", "problem_id"], :name => "index_submissions_on_user_id_and_problem_id"
198 199
199 200 create_table "tasks", :force => true do |t|
200 201 t.integer "submission_id"
201 202 t.datetime "created_at"
202 203 t.integer "status"
203 204 t.datetime "updated_at"
204 205 end
205 206
206 207 create_table "test_pairs", :force => true do |t|
207 208 t.integer "problem_id"
208 - t.text "input", :limit => 16777215
209 - t.text "solution", :limit => 16777215
210 - t.datetime "created_at", :null => false
211 - t.datetime "updated_at", :null => false
209 + t.text "input", :limit => 2147483647
210 + t.text "solution", :limit => 2147483647
211 + t.datetime "created_at", :null => false
212 + t.datetime "updated_at", :null => false
212 213 end
213 214
214 215 create_table "test_requests", :force => true do |t|
215 216 t.integer "user_id"
216 217 t.integer "problem_id"
217 218 t.integer "submission_id"
218 219 t.string "input_file_name"
219 220 t.string "output_file_name"
220 221 t.string "running_stat"
221 222 t.integer "status"
222 - t.datetime "updated_at", :null => false
223 + t.datetime "updated_at", :null => false
223 224 t.datetime "submitted_at"
224 225 t.datetime "compiled_at"
225 - t.text "compiler_message"
226 + t.text "compiler_message", :limit => 16777215
226 227 t.datetime "graded_at"
227 228 t.string "grader_comment"
228 - t.datetime "created_at", :null => false
229 + t.datetime "created_at", :null => false
229 230 t.float "running_time"
230 231 t.string "exit_status"
231 232 t.integer "memory_usage"
232 233 end
233 234
234 235 add_index "test_requests", ["user_id", "problem_id"], :name => "index_test_requests_on_user_id_and_problem_id"
235 236
236 237 create_table "user_contest_stats", :force => true do |t|
237 238 t.integer "user_id"
238 239 t.datetime "started_at"
239 240 t.datetime "created_at", :null => false
240 241 t.datetime "updated_at", :null => false
241 242 t.boolean "forced_logout"
242 243 end
243 244
244 245 create_table "users", :force => true do |t|
245 246 t.string "login", :limit => 50
246 247 t.string "full_name"
247 248 t.string "hashed_password"
248 249 t.string "salt", :limit => 5
249 250 t.string "alias"
250 251 t.string "email"
251 252 t.integer "site_id"
252 253 t.integer "country_id"
253 254 t.boolean "activated", :default => false
254 255 t.datetime "created_at"
255 256 t.datetime "updated_at"
257 + t.string "section"
256 258 t.boolean "enabled", :default => true
257 259 t.string "remark"
258 260 t.string "last_ip"
259 - t.string "section"
260 261 end
261 262
262 263 add_index "users", ["login"], :name => "index_users_on_login", :unique => true
263 264
264 265 end
deleted file
You need to be logged in to leave comments. Login now