Skip to content

Commit

Permalink
update tiebreakers
Browse files Browse the repository at this point in the history
  • Loading branch information
matsonj authored Nov 14, 2023
1 parent 2a90774 commit 4b3d1d3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 14 deletions.
2 changes: 1 addition & 1 deletion docs/manifest.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions evidence/pages/nba/in-season tournament/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ sources:
```wildcard_standings
SELECT *
FROM ${tournament_standings}
ORDER BY conf, wins DESC, losses, margin DESC
ORDER BY conf, made_tournament_pct1 DESC
```

# NBA In-season Tournament
Expand All @@ -19,7 +19,7 @@ New for the 2023-2024 season, the NBA has introduced an In-Season Tournament. Th

## Standings

_It should be noted that predicted results do not have tiebreakers applied._
_It should be noted that predicted results have tiebreakers approximated._
<Tabs>
<Tab label="East">

Expand Down
4 changes: 2 additions & 2 deletions evidence/sources/nba/tournament_results.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ SELECT
winning_team,
tournament_group,
sum(made_tournament) / 10000.0 as won_group,
sum(made_wildcard) / 30000.0 as made_wildcard,
sum(made_tournament) / 10000.0 + sum(made_wildcard) / 30000.0 as made_tournament,
sum(made_wildcard) / 10000.0 as made_wildcard,
sum(made_tournament) / 10000.0 + sum(made_wildcard) / 10000.0 as made_tournament,
avg(wins) as wins,
avg(losses) as losses
GROUP BY ALL
Expand Down
4 changes: 4 additions & 0 deletions transform/models/nba/analysis/reg_season_predictions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ SELECT
COUNT(*) AS occurances,
{{ american_odds( 'home_team_win_probability/10000' ) }} AS american_odds,
type,
actual_home_team_score,
actual_visiting_team_score,
CASE WHEN actual_home_team_score > actual_visiting_team_score
THEN actual_margin*-1 ELSE actual_margin END AS actual_margin,
(H.pts + V.pts) / 2.0 AS avg_score,
ROUND( CASE
WHEN home_team_win_probability/10000 >= 0.50 THEN ROUND( -30.564 * home_team_win_probability/10000 + 14.763, 1 )
Expand Down
51 changes: 43 additions & 8 deletions transform/models/nba/analysis/tournament_end.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,25 @@ cte_results_with_group AS (
LEFT JOIN cte_losses L ON T.team = L.losing_team AND scenarios.scenario_id = L.scenario_id
),

cte_home_margin AS (
SELECT
T.Team,
SUM(COALESCE(-H.actual_margin,-H.implied_line)) AS home_pt_diff
FROM {{ ref( 'nba_teams') }} T
LEFT JOIN {{ ref( 'reg_season_predictions' ) }} H ON H.home_team = T.team AND H.type = 'tournament' AND H.winning_team = H.home_team
GROUP BY ALL
),

cte_visitor_margin AS (
SELECT
T.Team,
SUM(COALESCE(V.actual_margin,V.implied_line)) AS visitor_pt_diff
FROM {{ ref( 'nba_teams') }} T
LEFT JOIN {{ ref( 'reg_season_predictions' ) }} V ON V.visiting_team = T.team AND V.type = 'tournament' AND V.winning_team = V.home_team
GROUP BY ALL
),


/* tiebreaking criteria: https://www.nba.com/news/in-season-tournament-101
• Head-to-head record in the Group Stage;
Expand All @@ -56,26 +75,42 @@ cte_results_with_group AS (

cte_ranked_wins AS (
SELECT
*,
R.*,
home_pt_diff + visitor_pt_diff AS pt_diff,
--no tiebreaker, so however row number handles order ties will need to be dealt with
ROW_NUMBER() OVER (PARTITION BY scenario_id, tournament_group ORDER BY wins DESC, winning_team DESC ) AS season_rank
FROM cte_results_with_group
ROW_NUMBER() OVER (PARTITION BY scenario_id, tournament_group ORDER BY wins DESC, pt_diff DESC ) AS group_rank
FROM cte_results_with_group R
LEFT JOIN cte_home_margin H ON H.team = R.winning_team
LEFT JOIN cte_visitor_margin V ON V.team = R.winning_team

),

cte_wildcard AS (
SELECT
scenario_id,
winning_team,
conf,
pt_diff,
group_rank,
ROW_NUMBER() OVER (PARTITION BY scenario_id, conf ORDER BY pt_diff DESC ) AS wildcard_rank
FROM cte_ranked_wins R
WHERE group_rank = 2
),

cte_made_tournament AS (
SELECT
*,
W.*,
CASE
WHEN season_rank = 1 THEN 1
WHEN W.group_rank = 1 THEN 1
ELSE 0
END AS made_tournament,
CASE
WHEN season_rank = 2 THEN 1
WHEN WC.wildcard_rank = 1 AND WC.wildcard_rank IS NOT NULL THEN 1
ELSE 0
END AS made_wildcard,
tournament_group || '-' || season_rank::text AS seed
FROM cte_ranked_wins
W.tournament_group || '-' || W.group_rank::text AS seed
FROM cte_ranked_wins W
LEFT JOIN cte_wildcard WC ON WC.winning_team = W.winning_team and WC.scenario_id = W.scenario_id
)

SELECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ SELECT
WHEN {{ elo_calc( 'S.home_team_elo_rating', 'S.visiting_team_elo_rating', var('nba_elo_offset') ) }} >= R.rand_result THEN S.home_team
ELSE S.visiting_team
END AS winning_team,
COALESCE(LR.include_actuals, false) AS include_actuals
COALESCE(LR.include_actuals, false) AS include_actuals,
LR.home_team_score AS actual_home_team_score,
LR.visiting_team_score AS actual_visiting_team_score,
LR.margin AS actual_margin
FROM {{ ref( 'nba_schedules' ) }} S
LEFT JOIN {{ ref( 'nba_random_num_gen' ) }} R ON R.game_id = S.game_id
LEFT JOIN {{ ref( 'nba_latest_results' ) }} LR ON LR.game_id = S.game_id
Expand Down

0 comments on commit 4b3d1d3

Please sign in to comment.