Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Advancing when round is in progress: don't take the no-shows into account. Fixes #109 #111

Merged
merged 4 commits into from
Sep 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions server/lib/wca_live/scoretaking/advancing.ex
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,16 @@ defmodule WcaLive.Scoretaking.Advancing do
%{results: results, advancement_condition: advancement_condition} = round
format = Format.get_by_id!(round.format_id)

# We ignore unranked results until they are entered. For percentage-based
# advancement rules this means that we qualify less results initially and
# start qualifying more as the missing results are entered. This way, in
# case the remaining missing results are quit, we don't un-qualify anyone
results = Enum.filter(results, & &1.ranking)

# See: https://www.worldcubeassociation.org/regulations/#9p1
max_qualifying = floor(length(results) * 0.75)
rankings = results |> Enum.map(& &1.ranking) |> Enum.reject(&is_nil/1) |> Enum.sort()

rankings = results |> Enum.map(& &1.ranking) |> Enum.sort()

first_non_qualifying_ranking =
if length(rankings) > max_qualifying do
Expand Down Expand Up @@ -181,12 +188,12 @@ defmodule WcaLive.Scoretaking.Advancing do
end

defp qualifying_results_ignoring(round, ignored_results) do
# Empty attempts rank ignored people at the end (making sure they don't qualify).
# DNF attempts rank ignored people at the end (making sure they don't qualify).
# Then recompute rankings and see who would qualify as a result.
hypothetical_results =
Enum.map(round.results, fn result ->
if result in ignored_results do
%{result | attempts: [], best: 0, average: 0}
%{result | attempts: [-1], best: -1, average: -1}
else
result
end
Expand Down
12 changes: 12 additions & 0 deletions server/test/wca_live/scoretaking/advancing_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,18 @@ defmodule WcaLive.Scoretaking.AdvancingTest do
assert ids([result1, result2]) == ids(Advancing.qualifying_results(round))
end

test "qualifying_results/1 given `percent` advancement condition, ignores results that are not entered yet" do
round = insert(:round, number: 1, advancement_condition: %{type: "percent", level: 50})
result1 = insert(:result, round: round, ranking: 1, best: 1000)
result2 = insert(:result, round: round, ranking: 2, best: 1100)
_result3 = insert(:result, round: round, ranking: 3, best: 1200)
_result4 = insert(:result, round: round, ranking: 4, best: 1400)
_result5 = insert(:result, round: round, ranking: nil)
_result6 = insert(:result, round: round, ranking: nil)

assert ids([result1, result2]) == ids(Advancing.qualifying_results(round))
end

test "qualifying_results/1 given `attemptResult` advancement condition and format sorting by best, returns results with best strictly better than the specified value" do
round =
insert(:round,
Expand Down