Description:
heartbeat response full
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r649:3cb38436f7f6 - - 6 files changed: 42 inserted, 4 deleted

@@ -0,0 +1,9
1 + class AddHeartBeatFull < ActiveRecord::Migration
2 + def up
3 + GraderConfiguration.create key: 'right.heartbeat_response_full', value_type: 'string', value:'RESTART', description:'Heart beat response text when user got full score (set this value to the empty string to disable this feature)'
4 + end
5 +
6 + def down
7 +
8 + end
9 + end
@@ -1,31 +1,46
1 1 class HeartbeatController < ApplicationController
2 2 before_filter :admin_authorization, :only => ['index']
3 3
4 4 def edit
5 5 #@user = User.find_by_login(params[:id])
6 6 #unless @user
7 7 # render text: "LOGIN_NOT_FOUND"
8 8 # return
9 9 #end
10 10
11 11 #hb = HeartBeat.where(user_id: @user.id, ip_address: request.remote_ip).first
12 12 #puts "status = #{params[:status]}"
13 13 #if hb
14 14 # if params[:status]
15 15 # hb.status = params[:status]
16 16 # hb.save
17 17 # end
18 18 # hb.touch
19 19 #else
20 20 # HeartBeat.creae(user_id: @user.id, ip_address: request.remote_ip)
21 21 #end
22 22 #HeartBeat.create(user_id: @user.id, ip_address: request.remote_ip, status: params[:status])
23 23
24 - render text: (GraderConfiguration['right.heartbeat_response'] || 'OK')
24 + res = GraderConfiguration['right.heartbeat_response']
25 + res.strip! if res
26 + full = GraderConfiguration['right.heartbeat_response_full']
27 + full.strip! if full
28 +
29 + if full and full != ''
30 + l = Login.where(ip_address: request.remote_ip).last
31 + @user = l.user
32 + if @user.solve_all_available_problems?
33 + render text: (full || 'OK')
34 + else
35 + render text: (res || 'OK')
36 + end
37 + else
38 + render text: (GraderConfiguration['right.heartbeat_response'] || 'OK')
39 + end
25 40 end
26 41
27 42 def index
28 43 @hb = HeartBeat.where("updated_at >= ?",Time.zone.now-2.hours).includes(:user).order(:user_id).all
29 44 @num = HeartBeat.where("updated_at >= ?",Time.zone.now-5.minutes).count(:user_id,distinct: true)
30 45 end
31 46 end
@@ -234,96 +234,105
234 234 else
235 235 return true
236 236 end
237 237 end
238 238
239 239 def update_start_time
240 240 stat = self.contest_stat
241 241 if stat.nil? or stat.started_at.nil?
242 242 stat ||= UserContestStat.new(:user => self)
243 243 stat.started_at = Time.now.gmtime
244 244 stat.save
245 245 end
246 246 end
247 247
248 248 def problem_in_user_contests?(problem)
249 249 problem_contests = problem.contests.all
250 250
251 251 if problem_contests.length == 0 # this is public contest
252 252 return true
253 253 end
254 254
255 255 contests.each do |contest|
256 256 if problem_contests.find {|c| c.id == contest.id }
257 257 return true
258 258 end
259 259 end
260 260 return false
261 261 end
262 262
263 263 def available_problems_group_by_contests
264 264 contest_problems = []
265 265 pin = {}
266 266 contests.enabled.each do |contest|
267 267 available_problems = contest.problems.available
268 268 contest_problems << {
269 269 :contest => contest,
270 270 :problems => available_problems
271 271 }
272 272 available_problems.each {|p| pin[p.id] = true}
273 273 end
274 274 other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0}
275 275 contest_problems << {
276 276 :contest => nil,
277 277 :problems => other_avaiable_problems
278 278 }
279 279 return contest_problems
280 280 end
281 281
282 + def solve_all_available_problems?
283 + available_problems.each do |p|
284 + u = self
285 + sub = Submission.find_last_by_user_and_problem(u.id,p.id)
286 + return false if !p or !sub or sub.points < p.full_score
287 + end
288 + return true
289 + end
290 +
282 291 def available_problems
283 292 if not GraderConfiguration.multicontests?
284 293 return Problem.available_problems
285 294 else
286 295 contest_problems = []
287 296 pin = {}
288 297 contests.enabled.each do |contest|
289 298 contest.problems.available.each do |problem|
290 299 if not pin.has_key? problem.id
291 300 contest_problems << problem
292 301 end
293 302 pin[problem.id] = true
294 303 end
295 304 end
296 305 other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0}
297 306 return contest_problems + other_avaiable_problems
298 307 end
299 308 end
300 309
301 310 def can_view_problem?(problem)
302 311 if not GraderConfiguration.multicontests?
303 312 return problem.available
304 313 else
305 314 return problem_in_user_contests? problem
306 315 end
307 316 end
308 317
309 318 def self.clear_last_login
310 319 User.update_all(:last_ip => nil)
311 320 end
312 321
313 322 protected
314 323 def encrypt_new_password
315 324 return if password.blank?
316 325 self.salt = (10+rand(90)).to_s
317 326 self.hashed_password = User.encrypt(self.password,self.salt)
318 327 end
319 328
320 329 def assign_default_site
321 330 # have to catch error when migrating (because self.site is not available).
322 331 begin
323 332 if self.site==nil
324 333 self.site = Site.find_by_name('default')
325 334 if self.site==nil
326 335 self.site = Site.find(1) # when 'default has be renamed'
327 336 end
328 337 end
329 338 rescue
@@ -43,58 +43,56
43 43 end
44 44
45 45 resources :grader_configuration, controller: 'configurations'
46 46
47 47 resources :users do
48 48 member do
49 49 get 'toggle_activate', 'toggle_enable'
50 50 get 'stat'
51 51 end
52 52 end
53 53
54 54 resources :submissions do
55 55 member do
56 56 get 'download'
57 57 get 'compiler_msg'
58 58 get 'rejudge'
59 59 end
60 60 collection do
61 61 get 'prob/:problem_id', to: 'submissions#index', as: 'problem'
62 62 get 'direct_edit_problem/:problem_id', to: 'submissions#direct_edit_problem', as: 'direct_edit_problem'
63 63 get 'get_latest_submission_status/:uid/:pid', to: 'submissions#get_latest_submission_status', as: 'get_latest_submission_status'
64 64 end
65 65 end
66 66
67 67
68 68
69 69 #main
70 70 get "main/list"
71 71 get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission'
72 72
73 73 #user admin
74 74 get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin'
75 75
76 76 #report
77 77 get 'report/current_score', to: 'report#current_score', as: 'report_current_score'
78 78 get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof'
79 79 get "report/login"
80 80 get 'report/max_score', to: 'report#max_score', as: 'report_max_score'
81 81 post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score'
82 82
83 83
84 84 #
85 85 get 'tasks/view/:file.:ext' => 'tasks#view'
86 86 get 'tasks/download/:id/:file.:ext' => 'tasks#download'
87 87 get 'heartbeat/:id/edit' => 'heartbeat#edit'
88 88
89 89 #grader
90 90 get 'graders/list', to: 'graders#list', as: 'grader_list'
91 -
92 91
93 - get 'heartbeat/:id/edit' => 'heartbeat#edit'
94 92
95 93 # See how all your routes lay out with "rake routes"
96 94
97 95 # This is a legacy wild controller route that's not recommended for RESTful applications.
98 96 # Note: This route will make all actions in every controller accessible via GET requests.
99 97 match ':controller(/:action(/:id))(.:format)', via: [:get, :post]
100 98 end
@@ -1,62 +1,62
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 that you check this file into your version control system.
13 13
14 - ActiveRecord::Schema.define(version: 20170310110146) do
14 + ActiveRecord::Schema.define(version: 20170427070345) do
15 15
16 16 create_table "announcements", force: :cascade do |t|
17 17 t.string "author", limit: 255
18 18 t.text "body", limit: 65535
19 19 t.boolean "published"
20 20 t.datetime "created_at", null: false
21 21 t.datetime "updated_at", null: false
22 22 t.boolean "frontpage", default: false
23 23 t.boolean "contest_only", default: false
24 24 t.string "title", limit: 255
25 25 t.string "notes", limit: 255
26 26 end
27 27
28 28 create_table "contests", force: :cascade do |t|
29 29 t.string "title", limit: 255
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", limit: 255
34 34 end
35 35
36 36 create_table "contests_problems", id: false, force: :cascade do |t|
37 37 t.integer "contest_id", limit: 4
38 38 t.integer "problem_id", limit: 4
39 39 end
40 40
41 41 create_table "contests_users", id: false, force: :cascade do |t|
42 42 t.integer "contest_id", limit: 4
43 43 t.integer "user_id", limit: 4
44 44 end
45 45
46 46 create_table "countries", force: :cascade do |t|
47 47 t.string "name", limit: 255
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: :cascade do |t|
53 53 t.text "body", limit: 65535
54 54 t.boolean "markdowned"
55 55 t.datetime "created_at", null: false
56 56 t.datetime "updated_at", null: false
57 57 end
58 58
59 59 create_table "grader_configurations", force: :cascade do |t|
60 60 t.string "key", limit: 255
61 61 t.string "value_type", limit: 255
62 62 t.string "value", limit: 255
@@ -45,96 +45,103
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 + :key => 'right.heartbeat_response_full',
94 + :value_type => 'string',
95 + :default_value => 'OK',
96 + :description => 'Heart beat response text when user got full score (set this value to the empty string to disable this feature)'
97 + },
98 +
99 + {
93 100 :key => 'right.view_testcase',
94 101 :value_type => 'boolean',
95 102 :default_value => 'false',
96 103 :description => 'When true, any user can view/download test data'
97 104 },
98 105 # If Configuration['system.online_registration'] is true, the
99 106 # system allows online registration, and will use these
100 107 # information for sending confirmation emails.
101 108 {
102 109 :key => 'system.online_registration.smtp',
103 110 :value_type => 'string',
104 111 :default_value => 'smtp.somehost.com'
105 112 },
106 113
107 114 {
108 115 :key => 'system.online_registration.from',
109 116 :value_type => 'string',
110 117 :default_value => 'your.email@address'
111 118 },
112 119
113 120 {
114 121 :key => 'system.admin_email',
115 122 :value_type => 'string',
116 123 :default_value => 'admin@admin.email'
117 124 },
118 125
119 126 {
120 127 :key => 'system.user_setting_enabled',
121 128 :value_type => 'boolean',
122 129 :default_value => 'true',
123 130 :description => 'If this option is true, users can change their settings'
124 131 },
125 132
126 133 {
127 134 :key => 'system.user_setting_enabled',
128 135 :value_type => 'boolean',
129 136 :default_value => 'true',
130 137 :description => 'If this option is true, users can change their settings'
131 138 },
132 139
133 140 # If Configuration['contest.test_request.early_timeout'] is true
134 141 # the user will not be able to use test request at 30 minutes
135 142 # before the contest ends.
136 143 {
137 144 :key => 'contest.test_request.early_timeout',
138 145 :value_type => 'boolean',
139 146 :default_value => 'false'
140 147 },
You need to be logged in to leave comments. Login now