Skip to content

Commit 80051b7

Browse files
committed
🐛 Fix "rest of the world" introduced in 2023
1 parent 4ff6f48 commit 80051b7

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

src/__main__.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def sort_dict[A, B](d: dict[A, B], *, reverse: bool = True) -> dict[A, B]:
6060

6161

6262
@app.command()
63-
def run(jury_path: Path = "jury.txt", participating_countries: int = 37) -> None: # pyright: ignore [reportArgumentType]
63+
def run(jury_path: Path = "jury.txt", participating_countries: int = 37, rest_of_world_vote: bool = True) -> None: # pyright: ignore [reportArgumentType]
6464
"""Run the ESC jury and televoting scoring prediction system."""
6565
jury_file = Path(jury_path)
6666
if not jury_file.exists():
@@ -118,10 +118,11 @@ def run(jury_path: Path = "jury.txt", participating_countries: int = 37) -> None
118118
for _ in range(20):
119119
time.sleep(0.1)
120120

121-
# Compute the (participating_countries + 1)x58 total and subtract the N-1 sum
122-
total_available = sum((12, 10, 8, 7, 6, 5, 4, 3, 2, 1)) * (
123-
participating_countries + 1
124-
) # N-1 televoting + 1 rest of the world
121+
# Compute the total available points
122+
# Each voting country gives 58 points total (12+10+8+7+6+5+4+3+2+1)
123+
# From 2023 onwards, there's also a "rest of the world" televote (+1)
124+
voting_countries = participating_countries + (1 if rest_of_world_vote else 0)
125+
total_available = sum((12, 10, 8, 7, 6, 5, 4, 3, 2, 1)) * voting_countries
125126
sum_entered = sum(televoting_data.values())
126127
missing = set(jury_scores) - set(televoting_data)
127128
country_to_predict = missing.pop()

tests/test_esc.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
YEARS_TO_TEST = list(range(2016, 2026))
2424

25+
# Rest of world televote was introduced in Eurovision 2023
26+
REST_OF_WORLD_VOTE_YEAR = 2023
27+
2528

2629
class ESCData(TypedDict):
2730
"""TypedDict for ESC data."""
@@ -161,10 +164,17 @@ def test_esc_grand_final(year: int, data: ESCData) -> None:
161164
inputs.append(str(televote_scores[country])) # noqa: PERF401
162165
inputs.append("y") # to confirm the winner
163166

167+
# Determine if rest of world vote should be included based on the year
168+
rest_of_world_vote = year >= REST_OF_WORLD_VOTE_YEAR
169+
164170
runner = CliRunner()
165171
result = runner.invoke(
166172
app,
167-
["--jury-path", f.name, "--participating-countries", str(participating_countries)],
173+
[
174+
"--jury-path", f.name,
175+
"--participating-countries", str(participating_countries),
176+
"--rest-of-world-vote" if rest_of_world_vote else "--no-rest-of-world-vote",
177+
],
168178
input="\n".join(inputs),
169179
)
170180

0 commit comments

Comments
 (0)