From 80051b7dd70bd11775c9b16ac4e394e2df021e13 Mon Sep 17 00:00:00 2001 From: Paillat-dev Date: Wed, 5 Nov 2025 16:17:23 +0100 Subject: [PATCH] :bug: Fix "rest of the world" introduced in 2023 --- src/__main__.py | 11 ++++++----- tests/test_esc.py | 12 +++++++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/__main__.py b/src/__main__.py index 4e1cd85..81c9184 100644 --- a/src/__main__.py +++ b/src/__main__.py @@ -60,7 +60,7 @@ def sort_dict[A, B](d: dict[A, B], *, reverse: bool = True) -> dict[A, B]: @app.command() -def run(jury_path: Path = "jury.txt", participating_countries: int = 37) -> None: # pyright: ignore [reportArgumentType] +def run(jury_path: Path = "jury.txt", participating_countries: int = 37, rest_of_world_vote: bool = True) -> None: # pyright: ignore [reportArgumentType] """Run the ESC jury and televoting scoring prediction system.""" jury_file = Path(jury_path) if not jury_file.exists(): @@ -118,10 +118,11 @@ def run(jury_path: Path = "jury.txt", participating_countries: int = 37) -> None for _ in range(20): time.sleep(0.1) - # Compute the (participating_countries + 1)x58 total and subtract the N-1 sum - total_available = sum((12, 10, 8, 7, 6, 5, 4, 3, 2, 1)) * ( - participating_countries + 1 - ) # N-1 televoting + 1 rest of the world + # Compute the total available points + # Each voting country gives 58 points total (12+10+8+7+6+5+4+3+2+1) + # From 2023 onwards, there's also a "rest of the world" televote (+1) + voting_countries = participating_countries + (1 if rest_of_world_vote else 0) + total_available = sum((12, 10, 8, 7, 6, 5, 4, 3, 2, 1)) * voting_countries sum_entered = sum(televoting_data.values()) missing = set(jury_scores) - set(televoting_data) country_to_predict = missing.pop() diff --git a/tests/test_esc.py b/tests/test_esc.py index bdb8222..e81faa0 100644 --- a/tests/test_esc.py +++ b/tests/test_esc.py @@ -22,6 +22,9 @@ DATASET_PATH = DATASET_BASE / "senior" YEARS_TO_TEST = list(range(2016, 2026)) +# Rest of world televote was introduced in Eurovision 2023 +REST_OF_WORLD_VOTE_YEAR = 2023 + class ESCData(TypedDict): """TypedDict for ESC data.""" @@ -161,10 +164,17 @@ def test_esc_grand_final(year: int, data: ESCData) -> None: inputs.append(str(televote_scores[country])) # noqa: PERF401 inputs.append("y") # to confirm the winner + # Determine if rest of world vote should be included based on the year + rest_of_world_vote = year >= REST_OF_WORLD_VOTE_YEAR + runner = CliRunner() result = runner.invoke( app, - ["--jury-path", f.name, "--participating-countries", str(participating_countries)], + [ + "--jury-path", f.name, + "--participating-countries", str(participating_countries), + "--rest-of-world-vote" if rest_of_world_vote else "--no-rest-of-world-vote", + ], input="\n".join(inputs), )