Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 350-registration-secr…
Browse files Browse the repository at this point in the history
…et-validation
  • Loading branch information
just806me committed Oct 1, 2023
2 parents 66ffa70 + dc53e4f commit 4729d32
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
17 changes: 15 additions & 2 deletions app/channels/api_channel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ class ApiChannel < ApplicationCable::Channel

def subscribed
ensure_confirmation_sent
task = Task.find task_id
dispatch_self 'app/start'
dispatch_self 'users/load', task_users.order(:judge_secret).pluck(:judge_secret)
dispatch_self 'criteria/load', task_criterions.order(:position)
dispatch_self 'judges/load', Task.find(task_id).judges
dispatch_self 'judges/load', task.judges
dispatch_self 'resultMultiplier/load', task.result_multiplier
dispatch_self 'results/load', CriterionUserResult.includes(:user).where(criterion: task_criterions)
dispatch_self 'comments/load', Comment.includes(:user).where(task_id:)
dispatch_self 'locks/load', RedisLockManager.all
Expand Down Expand Up @@ -62,6 +64,15 @@ def delete_judge data
end
end

def write_result_multiplier data
return unless scoring_open data

task = Task.find task_id
task.result_multiplier = data['value']
task.save!
dispatch_all 'resultMultiplier/load', task.result_multiplier
end

def drag_drop data
return unless scoring_open data

Expand Down Expand Up @@ -144,11 +155,13 @@ def finish data

users_without_result = []
begin
result_multiplier = Rational task.result_multiplier

ActiveRecord::Base.transaction do
task.contest.users.find_each do |user|
user_result = CriterionUserResult.where user:, criterion: task.criterions
users_without_result << user.judge_secret unless user_result.count == task.criterions_count
score = user_result.sum :value
score = user_result.sum(:value) * result_multiplier
Result.create_or_find_by!(user:, task:).update!(score:)
end

Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20230930203405_add_result_multiplier_to_tasks.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddResultMultiplierToTasks < ActiveRecord::Migration[7.0]
def change
add_column :tasks, :result_multiplier, :string, default: '1', null: false
end
end
6 changes: 4 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ CREATE TABLE public.tasks (
updated_at timestamp(6) without time zone NOT NULL,
criterions_count integer DEFAULT 0 NOT NULL,
scoring_open boolean DEFAULT true NOT NULL,
judges character varying[] DEFAULT '{}'::character varying[] NOT NULL
judges character varying[] DEFAULT '{}'::character varying[] NOT NULL,
result_multiplier character varying DEFAULT '1'::character varying NOT NULL
);


Expand Down Expand Up @@ -919,6 +920,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20230630172057'),
('20230902145307'),
('20230902145308'),
('20230902145309');
('20230902145309'),
('20230930203405');


0 comments on commit 4729d32

Please sign in to comment.