Support remaining pieces in completions and scoreboards
Some checks failed
CI / scan_ruby (push) Failing after 16s
CI / scan_js (push) Successful in 13s
CI / lint (push) Successful in 13s
CI / test (push) Successful in 36s

This commit is contained in:
sto
2025-10-28 15:13:29 +01:00
parent 1fa7bf10ec
commit bbd2cef168
11 changed files with 66 additions and 19 deletions

View File

@@ -109,6 +109,6 @@ class CompletionsController < ApplicationController
end
def completion_params
params.expect(completion: [ :display_time_from_start, :contestant_id, :message_id, :puzzle_id ])
params.expect(completion: [ :display_time_from_start, :remaining_pieces, :contestant_id, :message_id, :puzzle_id ])
end
end

View File

@@ -15,7 +15,12 @@ class ContestsController < ApplicationController
@title = I18n.t("contests.show.title", name: @contest.name)
@action_name = t("helpers.buttons.edit")
@action_path = edit_contest_path(@contest)
@contestants = @contest.contestants.sort_by { |contestant| [ -contestant.completions.size, contestant.time_seconds ] }
@contestants = @contest.contestants.sort_by { |contestant| [
-contestant.completions.where(remaining_pieces: nil).size,
(contestant.completions.where(remaining_pieces: nil).size == @contest.puzzles.length ? 1 : 0) * contestant.time_seconds,
contestant.completions.size > 0 && contestant.completions[-1].remaining_pieces ? contestant.completions[-1].remaining_pieces : 1000000,
contestant.time_seconds
] }
filter_contestants_per_category
@puzzles = @contest.puzzles.order(:id)
@messages = @contest.messages.order(:time_seconds)
@@ -77,7 +82,12 @@ class ContestsController < ApplicationController
I18n.locale = @contest.lang
@title = I18n.t("contests.scoreboard.title", name: @contest.name)
@contestants = @contest.contestants.sort_by { |contestant| [ -contestant.completions.size, contestant.time_seconds ] }
@contestants = @contest.contestants.sort_by { |contestant| [
-contestant.completions.where(remaining_pieces: nil).size,
(contestant.completions.where(remaining_pieces: nil).size == @contest.puzzles.length ? 1 : 0) * contestant.time_seconds,
contestant.completions.size > 0 && contestant.completions[-1].remaining_pieces ? contestant.completions[-1].remaining_pieces : 1000000,
contestant.time_seconds
] }
filter_contestants_per_category
@puzzles = @contest.puzzles.order(:id)
@action_name = t("helpers.buttons.refresh")