diff --git a/server/lib/wca_live/scoretaking/advancing.ex b/server/lib/wca_live/scoretaking/advancing.ex index ec096a53..18afaa3d 100644 --- a/server/lib/wca_live/scoretaking/advancing.ex +++ b/server/lib/wca_live/scoretaking/advancing.ex @@ -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 @@ -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 diff --git a/server/test/wca_live/scoretaking/advancing_test.exs b/server/test/wca_live/scoretaking/advancing_test.exs index 87098d5d..338062c7 100644 --- a/server/test/wca_live/scoretaking/advancing_test.exs +++ b/server/test/wca_live/scoretaking/advancing_test.exs @@ -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,