# HG changeset patch # User Nattee Niparnan # Date 2017-04-27 07:22:27 # Node ID 3cb38436f7f6d5c6d4490038e78576c39b58135e # Parent 4514b4701ae2275ce4ac24b071ed7c70c83db877 heartbeat response full diff --git a/app/controllers/heartbeat_controller.rb b/app/controllers/heartbeat_controller.rb --- a/app/controllers/heartbeat_controller.rb +++ b/app/controllers/heartbeat_controller.rb @@ -21,7 +21,22 @@ #end #HeartBeat.create(user_id: @user.id, ip_address: request.remote_ip, status: params[:status]) - render text: (GraderConfiguration['right.heartbeat_response'] || 'OK') + res = GraderConfiguration['right.heartbeat_response'] + res.strip! if res + full = GraderConfiguration['right.heartbeat_response_full'] + full.strip! if full + + if full and full != '' + l = Login.where(ip_address: request.remote_ip).last + @user = l.user + if @user.solve_all_available_problems? + render text: (full || 'OK') + else + render text: (res || 'OK') + end + else + render text: (GraderConfiguration['right.heartbeat_response'] || 'OK') + end end def index diff --git a/app/models/user.rb b/app/models/user.rb --- a/app/models/user.rb +++ b/app/models/user.rb @@ -279,6 +279,15 @@ return contest_problems end + def solve_all_available_problems? + available_problems.each do |p| + u = self + sub = Submission.find_last_by_user_and_problem(u.id,p.id) + return false if !p or !sub or sub.points < p.full_score + end + return true + end + def available_problems if not GraderConfiguration.multicontests? return Problem.available_problems diff --git a/config/routes.rb b/config/routes.rb --- a/config/routes.rb +++ b/config/routes.rb @@ -88,9 +88,7 @@ #grader get 'graders/list', to: 'graders#list', as: 'grader_list' - - get 'heartbeat/:id/edit' => 'heartbeat#edit' # See how all your routes lay out with "rake routes" diff --git a/db/migrate/20170427070345_add_heart_beat_full.rb b/db/migrate/20170427070345_add_heart_beat_full.rb new file mode 100644 --- /dev/null +++ b/db/migrate/20170427070345_add_heart_beat_full.rb @@ -0,0 +1,9 @@ +class AddHeartBeatFull < ActiveRecord::Migration + def up + 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)' + end + + def down + + end +end diff --git a/db/schema.rb b/db/schema.rb --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170310110146) do +ActiveRecord::Schema.define(version: 20170427070345) do create_table "announcements", force: :cascade do |t| t.string "author", limit: 255 diff --git a/db/seeds.rb b/db/seeds.rb --- a/db/seeds.rb +++ b/db/seeds.rb @@ -90,6 +90,13 @@ }, { + :key => 'right.heartbeat_response_full', + :value_type => 'string', + :default_value => 'OK', + :description => 'Heart beat response text when user got full score (set this value to the empty string to disable this feature)' + }, + + { :key => 'right.view_testcase', :value_type => 'boolean', :default_value => 'false',