Description:
heartbeat response full
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r649:3cb38436f7f6 - - 6 files changed: 41 inserted, 3 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 | class HeartbeatController < ApplicationController |
|
1 | class HeartbeatController < ApplicationController |
|
2 | before_filter :admin_authorization, :only => ['index'] |
|
2 | before_filter :admin_authorization, :only => ['index'] |
|
3 |
|
3 | ||
|
4 | def edit |
|
4 | def edit |
|
5 | #@user = User.find_by_login(params[:id]) |
|
5 | #@user = User.find_by_login(params[:id]) |
|
6 | #unless @user |
|
6 | #unless @user |
|
7 | # render text: "LOGIN_NOT_FOUND" |
|
7 | # render text: "LOGIN_NOT_FOUND" |
|
8 | # return |
|
8 | # return |
|
9 | #end |
|
9 | #end |
|
10 |
|
10 | ||
|
11 | #hb = HeartBeat.where(user_id: @user.id, ip_address: request.remote_ip).first |
|
11 | #hb = HeartBeat.where(user_id: @user.id, ip_address: request.remote_ip).first |
|
12 | #puts "status = #{params[:status]}" |
|
12 | #puts "status = #{params[:status]}" |
|
13 | #if hb |
|
13 | #if hb |
|
14 | # if params[:status] |
|
14 | # if params[:status] |
|
15 | # hb.status = params[:status] |
|
15 | # hb.status = params[:status] |
|
16 | # hb.save |
|
16 | # hb.save |
|
17 | # end |
|
17 | # end |
|
18 | # hb.touch |
|
18 | # hb.touch |
|
19 | #else |
|
19 | #else |
|
20 | # HeartBeat.creae(user_id: @user.id, ip_address: request.remote_ip) |
|
20 | # HeartBeat.creae(user_id: @user.id, ip_address: request.remote_ip) |
|
21 | #end |
|
21 | #end |
|
22 | #HeartBeat.create(user_id: @user.id, ip_address: request.remote_ip, status: params[:status]) |
|
22 | #HeartBeat.create(user_id: @user.id, ip_address: request.remote_ip, status: params[:status]) |
|
23 |
|
23 | ||
|
|
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 | ||
|
24 | render text: (GraderConfiguration['right.heartbeat_response'] || 'OK') |
|
38 | render text: (GraderConfiguration['right.heartbeat_response'] || 'OK') |
|
25 | end |
|
39 | end |
|
|
40 | + end | ||
|
26 |
|
41 | ||
|
27 | def index |
|
42 | def index |
|
28 | @hb = HeartBeat.where("updated_at >= ?",Time.zone.now-2.hours).includes(:user).order(:user_id).all |
|
43 | @hb = HeartBeat.where("updated_at >= ?",Time.zone.now-2.hours).includes(:user).order(:user_id).all |
|
29 | @num = HeartBeat.where("updated_at >= ?",Time.zone.now-5.minutes).count(:user_id,distinct: true) |
|
44 | @num = HeartBeat.where("updated_at >= ?",Time.zone.now-5.minutes).count(:user_id,distinct: true) |
|
30 | end |
|
45 | end |
|
31 | end |
|
46 | end |
@@ -258,48 +258,57 | |||||
|
258 | end |
|
258 | end |
|
259 | end |
|
259 | end |
|
260 | return false |
|
260 | return false |
|
261 | end |
|
261 | end |
|
262 |
|
262 | ||
|
263 | def available_problems_group_by_contests |
|
263 | def available_problems_group_by_contests |
|
264 | contest_problems = [] |
|
264 | contest_problems = [] |
|
265 | pin = {} |
|
265 | pin = {} |
|
266 | contests.enabled.each do |contest| |
|
266 | contests.enabled.each do |contest| |
|
267 | available_problems = contest.problems.available |
|
267 | available_problems = contest.problems.available |
|
268 | contest_problems << { |
|
268 | contest_problems << { |
|
269 | :contest => contest, |
|
269 | :contest => contest, |
|
270 | :problems => available_problems |
|
270 | :problems => available_problems |
|
271 | } |
|
271 | } |
|
272 | available_problems.each {|p| pin[p.id] = true} |
|
272 | available_problems.each {|p| pin[p.id] = true} |
|
273 | end |
|
273 | end |
|
274 | other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} |
|
274 | other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} |
|
275 | contest_problems << { |
|
275 | contest_problems << { |
|
276 | :contest => nil, |
|
276 | :contest => nil, |
|
277 | :problems => other_avaiable_problems |
|
277 | :problems => other_avaiable_problems |
|
278 | } |
|
278 | } |
|
279 | return contest_problems |
|
279 | return contest_problems |
|
280 | end |
|
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 | def available_problems |
|
291 | def available_problems |
|
283 | if not GraderConfiguration.multicontests? |
|
292 | if not GraderConfiguration.multicontests? |
|
284 | return Problem.available_problems |
|
293 | return Problem.available_problems |
|
285 | else |
|
294 | else |
|
286 | contest_problems = [] |
|
295 | contest_problems = [] |
|
287 | pin = {} |
|
296 | pin = {} |
|
288 | contests.enabled.each do |contest| |
|
297 | contests.enabled.each do |contest| |
|
289 | contest.problems.available.each do |problem| |
|
298 | contest.problems.available.each do |problem| |
|
290 | if not pin.has_key? problem.id |
|
299 | if not pin.has_key? problem.id |
|
291 | contest_problems << problem |
|
300 | contest_problems << problem |
|
292 | end |
|
301 | end |
|
293 | pin[problem.id] = true |
|
302 | pin[problem.id] = true |
|
294 | end |
|
303 | end |
|
295 | end |
|
304 | end |
|
296 | other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} |
|
305 | other_avaiable_problems = Problem.available.find_all {|p| pin[p.id]==nil and p.contests.length==0} |
|
297 | return contest_problems + other_avaiable_problems |
|
306 | return contest_problems + other_avaiable_problems |
|
298 | end |
|
307 | end |
|
299 | end |
|
308 | end |
|
300 |
|
309 | ||
|
301 | def can_view_problem?(problem) |
|
310 | def can_view_problem?(problem) |
|
302 | if not GraderConfiguration.multicontests? |
|
311 | if not GraderConfiguration.multicontests? |
|
303 | return problem.available |
|
312 | return problem.available |
|
304 | else |
|
313 | else |
|
305 | return problem_in_user_contests? problem |
|
314 | return problem_in_user_contests? problem |
@@ -69,32 +69,30 | |||||
|
69 | #main |
|
69 | #main |
|
70 | get "main/list" |
|
70 | get "main/list" |
|
71 | get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission' |
|
71 | get 'main/submission(/:id)', to: 'main#submission', as: 'main_submission' |
|
72 |
|
72 | ||
|
73 | #user admin |
|
73 | #user admin |
|
74 | get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin' |
|
74 | get 'user_admin/bulk_manage', to: 'user_admin#bulk_manage', as: 'bulk_manage_user_admin' |
|
75 |
|
75 | ||
|
76 | #report |
|
76 | #report |
|
77 | get 'report/current_score', to: 'report#current_score', as: 'report_current_score' |
|
77 | get 'report/current_score', to: 'report#current_score', as: 'report_current_score' |
|
78 | get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof' |
|
78 | get 'report/problem_hof(/:id)', to: 'report#problem_hof', as: 'report_problem_hof' |
|
79 | get "report/login" |
|
79 | get "report/login" |
|
80 | get 'report/max_score', to: 'report#max_score', as: 'report_max_score' |
|
80 | get 'report/max_score', to: 'report#max_score', as: 'report_max_score' |
|
81 | post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score' |
|
81 | post 'report/show_max_score', to: 'report#show_max_score', as: 'report_show_max_score' |
|
82 |
|
82 | ||
|
83 |
|
83 | ||
|
84 | # |
|
84 | # |
|
85 | get 'tasks/view/:file.:ext' => 'tasks#view' |
|
85 | get 'tasks/view/:file.:ext' => 'tasks#view' |
|
86 | get 'tasks/download/:id/:file.:ext' => 'tasks#download' |
|
86 | get 'tasks/download/:id/:file.:ext' => 'tasks#download' |
|
87 | get 'heartbeat/:id/edit' => 'heartbeat#edit' |
|
87 | get 'heartbeat/:id/edit' => 'heartbeat#edit' |
|
88 |
|
88 | ||
|
89 | #grader |
|
89 | #grader |
|
90 | get 'graders/list', to: 'graders#list', as: 'grader_list' |
|
90 | get 'graders/list', to: 'graders#list', as: 'grader_list' |
|
91 |
|
91 | ||
|
92 |
|
92 | ||
|
93 | - get 'heartbeat/:id/edit' => 'heartbeat#edit' |
|
||
|
94 | - |
|
||
|
95 | # See how all your routes lay out with "rake routes" |
|
93 | # See how all your routes lay out with "rake routes" |
|
96 |
|
94 | ||
|
97 | # This is a legacy wild controller route that's not recommended for RESTful applications. |
|
95 | # This is a legacy wild controller route that's not recommended for RESTful applications. |
|
98 | # Note: This route will make all actions in every controller accessible via GET requests. |
|
96 | # Note: This route will make all actions in every controller accessible via GET requests. |
|
99 | match ':controller(/:action(/:id))(.:format)', via: [:get, :post] |
|
97 | match ':controller(/:action(/:id))(.:format)', via: [:get, :post] |
|
100 | end |
|
98 | end |
@@ -1,38 +1,38 | |||||
|
1 | # encoding: UTF-8 |
|
1 | # encoding: UTF-8 |
|
2 | # This file is auto-generated from the current state of the database. Instead |
|
2 | # This file is auto-generated from the current state of the database. Instead |
|
3 | # of editing this file, please use the migrations feature of Active Record to |
|
3 | # of editing this file, please use the migrations feature of Active Record to |
|
4 | # incrementally modify your database, and then regenerate this schema definition. |
|
4 | # incrementally modify your database, and then regenerate this schema definition. |
|
5 | # |
|
5 | # |
|
6 | # Note that this schema.rb definition is the authoritative source for your |
|
6 | # Note that this schema.rb definition is the authoritative source for your |
|
7 | # database schema. If you need to create the application database on another |
|
7 | # database schema. If you need to create the application database on another |
|
8 | # system, you should be using db:schema:load, not running all the migrations |
|
8 | # system, you should be using db:schema:load, not running all the migrations |
|
9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
9 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
10 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
10 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
11 | # |
|
11 | # |
|
12 | # It's strongly recommended that you check this file into your version control system. |
|
12 | # It's strongly recommended that you check this file into your version control system. |
|
13 |
|
13 | ||
|
14 |
- ActiveRecord::Schema.define(version: 20170 |
|
14 | + ActiveRecord::Schema.define(version: 20170427070345) do |
|
15 |
|
15 | ||
|
16 | create_table "announcements", force: :cascade do |t| |
|
16 | create_table "announcements", force: :cascade do |t| |
|
17 | t.string "author", limit: 255 |
|
17 | t.string "author", limit: 255 |
|
18 | t.text "body", limit: 65535 |
|
18 | t.text "body", limit: 65535 |
|
19 | t.boolean "published" |
|
19 | t.boolean "published" |
|
20 | t.datetime "created_at", null: false |
|
20 | t.datetime "created_at", null: false |
|
21 | t.datetime "updated_at", null: false |
|
21 | t.datetime "updated_at", null: false |
|
22 | t.boolean "frontpage", default: false |
|
22 | t.boolean "frontpage", default: false |
|
23 | t.boolean "contest_only", default: false |
|
23 | t.boolean "contest_only", default: false |
|
24 | t.string "title", limit: 255 |
|
24 | t.string "title", limit: 255 |
|
25 | t.string "notes", limit: 255 |
|
25 | t.string "notes", limit: 255 |
|
26 | end |
|
26 | end |
|
27 |
|
27 | ||
|
28 | create_table "contests", force: :cascade do |t| |
|
28 | create_table "contests", force: :cascade do |t| |
|
29 | t.string "title", limit: 255 |
|
29 | t.string "title", limit: 255 |
|
30 | t.boolean "enabled" |
|
30 | t.boolean "enabled" |
|
31 | t.datetime "created_at", null: false |
|
31 | t.datetime "created_at", null: false |
|
32 | t.datetime "updated_at", null: false |
|
32 | t.datetime "updated_at", null: false |
|
33 | t.string "name", limit: 255 |
|
33 | t.string "name", limit: 255 |
|
34 | end |
|
34 | end |
|
35 |
|
35 | ||
|
36 | create_table "contests_problems", id: false, force: :cascade do |t| |
|
36 | create_table "contests_problems", id: false, force: :cascade do |t| |
|
37 | t.integer "contest_id", limit: 4 |
|
37 | t.integer "contest_id", limit: 4 |
|
38 | t.integer "problem_id", limit: 4 |
|
38 | t.integer "problem_id", limit: 4 |
@@ -69,48 +69,55 | |||||
|
69 | }, |
|
69 | }, |
|
70 |
|
70 | ||
|
71 | { |
|
71 | { |
|
72 | :key => 'right.user_view_submission', |
|
72 | :key => 'right.user_view_submission', |
|
73 | :value_type => 'boolean', |
|
73 | :value_type => 'boolean', |
|
74 | :default_value => 'false', |
|
74 | :default_value => 'false', |
|
75 | :description => 'If true, any user can view submissions of every one.' |
|
75 | :description => 'If true, any user can view submissions of every one.' |
|
76 | }, |
|
76 | }, |
|
77 |
|
77 | ||
|
78 | { |
|
78 | { |
|
79 | :key => 'right.bypass_agreement', |
|
79 | :key => 'right.bypass_agreement', |
|
80 | :value_type => 'boolean', |
|
80 | :value_type => 'boolean', |
|
81 | :default_value => 'true', |
|
81 | :default_value => 'true', |
|
82 | :description => 'When false, a user must accept usage agreement before login' |
|
82 | :description => 'When false, a user must accept usage agreement before login' |
|
83 | }, |
|
83 | }, |
|
84 |
|
84 | ||
|
85 | { |
|
85 | { |
|
86 | :key => 'right.heartbeat_response', |
|
86 | :key => 'right.heartbeat_response', |
|
87 | :value_type => 'string', |
|
87 | :value_type => 'string', |
|
88 | :default_value => 'OK', |
|
88 | :default_value => 'OK', |
|
89 | :description => 'Heart beat response text' |
|
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 | :key => 'right.view_testcase', |
|
100 | :key => 'right.view_testcase', |
|
94 | :value_type => 'boolean', |
|
101 | :value_type => 'boolean', |
|
95 | :default_value => 'false', |
|
102 | :default_value => 'false', |
|
96 | :description => 'When true, any user can view/download test data' |
|
103 | :description => 'When true, any user can view/download test data' |
|
97 | }, |
|
104 | }, |
|
98 | # If Configuration['system.online_registration'] is true, the |
|
105 | # If Configuration['system.online_registration'] is true, the |
|
99 | # system allows online registration, and will use these |
|
106 | # system allows online registration, and will use these |
|
100 | # information for sending confirmation emails. |
|
107 | # information for sending confirmation emails. |
|
101 | { |
|
108 | { |
|
102 | :key => 'system.online_registration.smtp', |
|
109 | :key => 'system.online_registration.smtp', |
|
103 | :value_type => 'string', |
|
110 | :value_type => 'string', |
|
104 | :default_value => 'smtp.somehost.com' |
|
111 | :default_value => 'smtp.somehost.com' |
|
105 | }, |
|
112 | }, |
|
106 |
|
113 | ||
|
107 | { |
|
114 | { |
|
108 | :key => 'system.online_registration.from', |
|
115 | :key => 'system.online_registration.from', |
|
109 | :value_type => 'string', |
|
116 | :value_type => 'string', |
|
110 | :default_value => 'your.email@address' |
|
117 | :default_value => 'your.email@address' |
|
111 | }, |
|
118 | }, |
|
112 |
|
119 | ||
|
113 | { |
|
120 | { |
|
114 | :key => 'system.admin_email', |
|
121 | :key => 'system.admin_email', |
|
115 | :value_type => 'string', |
|
122 | :value_type => 'string', |
|
116 | :default_value => 'admin@admin.email' |
|
123 | :default_value => 'admin@admin.email' |
You need to be logged in to leave comments.
Login now