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

In_season_tournament #132

Merged
merged 3 commits into from
Nov 5, 2023
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
11 changes: 11 additions & 0 deletions data/nba/nba_results.csv
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,14 @@ Wed Nov 1 2023,8:30p,Chicago Bulls,105,Dallas Mavericks,114,Box Score,,20103,Ame
Wed Nov 1 2023,9:00p,Memphis Grizzlies,109,Utah Jazz,133,Box Score,,18206,Delta Center,
Wed Nov 1 2023,10:00p,Sacramento Kings,101,Golden State Warriors,102,Box Score,,18064,Chase Center,
Wed Nov 1 2023,10:00p,Los Angeles Clippers,125,Los Angeles Lakers,130,Box Score,OT,18997,Crypto.com Arena,
Thu Nov 2 2023,7:00p,Toronto Raptors,99,Philadelphia 76ers,114,Box Score,,19773,Wells Fargo Center,
Thu Nov 2 2023,8:00p,Detroit Pistons,116,New Orleans Pelicans,125,Box Score,,15884,Smoothie King Center,
Thu Nov 2 2023,9:00p,Orlando Magic,115,Utah Jazz,113,Box Score,,18206,Delta Center,
Thu Nov 2 2023,10:00p,San Antonio Spurs,132,Phoenix Suns,121,Box Score,,17071,Footprint Center,
Fri Nov 3 2023,7:00p,Cleveland Cavaliers,116,Indiana Pacers,121,Box Score,,16744,Gainbridge Fieldhouse,In-Season Tournament
Fri Nov 3 2023,7:30p,New York Knicks,105,Milwaukee Bucks,110,Box Score,,17717,Fiserv Forum,In-Season Tournament
Fri Nov 3 2023,8:00p,Brooklyn Nets,109,Chicago Bulls,107,Box Score,,20645,United Center,In-Season Tournament
Fri Nov 3 2023,8:00p,Washington Wizards,114,Miami Heat,121,Box Score,,19660,Kaseya Center,In-Season Tournament
Fri Nov 3 2023,8:00p,Golden State Warriors,141,Oklahoma City Thunder,139,Box Score,,16827,Paycom Center,In-Season Tournament
Fri Nov 3 2023,10:00p,Dallas Mavericks,114,Denver Nuggets,125,Box Score,,19729,Ball Arena,In-Season Tournament
Fri Nov 3 2023,10:00p,Memphis Grizzlies,113,Portland Trail Blazers,115,Box Score,OT,18592,Moda Center,In-Season Tournament
2,400 changes: 1,200 additions & 1,200 deletions data/nba/nba_schedule.csv

Large diffs are not rendered by default.

62 changes: 31 additions & 31 deletions data/nba/nba_team_ratings.csv
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
team,team_long,conf,elo_rating,win_total
BOS,Boston Celtics,East,1710,54.7
MIL,Milwaukee Bucks,East,1702,53.9
MIA,Miami Heat,East,1624,45.3
BRK,Brooklyn Nets,East,1563,37.3
PHO,Phoenix Suns,West,1684,51.5
LAC,Los Angeles Clippers,West,1646,46.5
PHI,Philadelphia 76ers,East,1652,48.1
DEN,Denver Nuggets,West,1694,52.5
GSW,Golden State Warriors,West,1661,48.3
DAL,Dallas Mavericks,West,1625,44.3
MEM,Memphis Grizzlies,West,1638,45.9
UTA,Utah Jazz,West,1552,35.5
ATL,Atlanta Hawks,East,1603,42.5
NOP,New Orleans Pelicans,West,1626,44.5
TOR,Toronto Raptors,East,1554,36.5
MIN,Minnesota Timberwolves,West,1629,44.7
LAL,Los Angeles Lakers,West,1654,47.5
POR,Portland Trail Blazers,West,1491,28.5
CHI,Chicago Bulls,East,1563,37.5
CHO,Charlotte Hornets,East,1506,30.9
NYK,New York Knicks,East,1631,45.5
IND,Indiana Pacers,East,1573,38.7
CLE,Cleveland Cavaliers,East,1671,50.5
SAC,Sacramento Kings,West,1631,44.5
SAS,San Antonio Spurs,West,1498,29.1
WAS,Washington Wizards,East,1445,24.5
ORL,Orlando Magic,East,1555,36.7
DET,Detroit Pistons,East,1475,27.5
OKC,Oklahoma City Thunder,West,1626,44.5
HOU,Houston Rockets,West,1516,31.5
team,team_long,conf,elo_rating,win_total,tournament_group
BOS,Boston Celtics,East,1710,54.7,east_c
MIL,Milwaukee Bucks,East,1702,53.9,east_b
MIA,Miami Heat,East,1624,45.3,east_b
BRK,Brooklyn Nets,East,1563,37.3,east_c
PHO,Phoenix Suns,West,1684,51.5,west_a
LAC,Los Angeles Clippers,West,1646,46.5,west_b
PHI,Philadelphia 76ers,East,1652,48.1,east_a
DEN,Denver Nuggets,West,1694,52.5,west_b
GSW,Golden State Warriors,West,1661,48.3,west_c
DAL,Dallas Mavericks,West,1625,44.3,west_b
MEM,Memphis Grizzlies,West,1638,45.9,west_a
UTA,Utah Jazz,West,1552,35.5,west_a
ATL,Atlanta Hawks,East,1603,42.5,east_a
NOP,New Orleans Pelicans,West,1626,44.5,west_b
TOR,Toronto Raptors,East,1554,36.5,east_c
MIN,Minnesota Timberwolves,West,1629,44.7,west_c
LAL,Los Angeles Lakers,West,1654,47.5,west_a
POR,Portland Trail Blazers,West,1491,28.5,west_a
CHI,Chicago Bulls,East,1563,37.5,east_c
CHO,Charlotte Hornets,East,1506,30.9,east_b
NYK,New York Knicks,East,1631,45.5,east_b
IND,Indiana Pacers,East,1573,38.7,east_a
CLE,Cleveland Cavaliers,East,1671,50.5,east_a
SAC,Sacramento Kings,West,1631,44.5,west_c
SAS,San Antonio Spurs,West,1498,29.1,west_c
WAS,Washington Wizards,East,1445,24.5,east_b
ORL,Orlando Magic,East,1555,36.7,east_c
DET,Detroit Pistons,East,1475,27.5,east_a
OKC,Oklahoma City Thunder,West,1626,44.5,west_c
HOU,Houston Rockets,West,1516,31.5,west_b
2 changes: 1 addition & 1 deletion docs/catalog.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/manifest.json

Large diffs are not rendered by default.

189 changes: 189 additions & 0 deletions evidence/pages/nba/in-season tournament/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
```future_games
SELECT
date,
visiting_team as visitor,
visiting_team_elo_rating AS visitor_ELO,
home_team as home,
home_team_elo_rating AS home_ELO,
home_team_win_probability/10000 AS home_team_win_pct1,
american_odds
FROM reg_season_predictions
WHERE include_actuals = false AND winning_team = home_team and type = 'tournament'
ORDER BY game_id
```

```past_games
SELECT *,
CASE
WHEN (home_team_win_probability > 5000.0 AND winning_team = home_team)
OR (home_team_win_probability < 5000.0 AND winning_team = visiting_team)
THEN 1 ELSE 0 END AS 'accurate_guess'
FROM reg_season_predictions
WHERE include_actuals = true and type = 'tournament'
ORDER BY game_id
```

```standings
WITH cte_wins AS (
SELECT
S.winning_team,
COUNT(*) AS wins
FROM ${past_games} S
GROUP BY ALL
),
cte_losses AS (
SELECT
CASE WHEN S.home_team = S.winning_team
THEN S.visiting_team ELSE S.home_team
END AS losing_team,
COUNT(*) AS losses
FROM ${past_games} S
GROUP BY ALL
)
SELECT
T.team,
'/nba/teams/' || T.team as team_link,
T.conf,
COALESCE(W.wins,0) AS wins,
COALESCE(L.losses,0) as losses,
COALESCE(W.wins,0) || '-' || COALESCE(L.losses,0) AS record,
T.tournament_group as group,
R.won_group AS won_group_pct1,
R.made_wildcard AS won_wildcard_pct1,
R.made_tournament AS made_tournament_pct1,
ROUND(R.wins,1) || '-' || ROUND(R.losses,1) AS proj_record
FROM nba_teams T
LEFT JOIN cte_wins W ON W.winning_team = T.team
LEFT JOIN cte_losses L ON L .losing_team = T.team
LEFT JOIN ${tournament_results} R ON R.winning_team = T.team
GROUP BY ALL
ORDER BY T.tournament_group, made_tournament_pct1 DESC
```


```tournament_results
FROM tournament_end
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,
avg(wins) as wins,
avg(losses) as losses
GROUP BY ALL
ORDER BY tournament_group, made_tournament DESC
```

```most_recent_games
SELECT
game_date as date,
vstm as visiting_team,
'@' as " ",
hmtm as home_team,
home_team_score || ' - ' || visiting_team_score as score,
winning_team,
ABS(elo_change) AS elo_change_num1
FROM nba_results_log RL
WHERE RL.type = 'tournament'
ORDER BY game_date desc
```

# NBA In-season Tournament

New for the 2023-2024 season, the NBA has introduced an In-Season Tournament. The tournament consists of Group Play followed by single elimination knock out rounds. You can learn about it [here](https://www.nba.com/news/in-season-tournament-101).

## Standings

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

### Group A Standings

<DataTable data={standings.filter(d => d.group === "east_a")} link=team_link rows=5>
<Column id=team/>
<Column id=record/>
<Column id=proj_record/>
<Column id=won_group_pct1/>
<Column id=won_wildcard_pct1/>
<Column id=made_tournament_pct1/>
</DataTable>

### Group B Standings

<DataTable data={standings.filter(d => d.group === "east_b")} link=team_link rows=5>
<Column id=team/>
<Column id=record/>
<Column id=proj_record/>
<Column id=won_group_pct1/>
<Column id=won_wildcard_pct1/>
<Column id=made_tournament_pct1/>
</DataTable>

### Group C Standings

<DataTable data={standings.filter(d => d.group === "east_c")} link=team_link rows=5>
<Column id=team/>
<Column id=record/>
<Column id=proj_record/>
<Column id=won_group_pct1/>
<Column id=won_wildcard_pct1/>
<Column id=made_tournament_pct1/>
</DataTable>

</Tab>
<Tab label="West">

### Group A Standings

<DataTable data={standings.filter(d => d.group === "west_a")} link=team_link rows=5>
<Column id=team/>
<Column id=record/>
<Column id=proj_record/>
<Column id=won_group_pct1/>
<Column id=won_wildcard_pct1/>
<Column id=made_tournament_pct1/>
</DataTable>

### Group B Standings

<DataTable data={standings.filter(d => d.group === "west_b")} link=team_link rows=5>
<Column id=team/>
<Column id=record/>
<Column id=proj_record/>
<Column id=won_group_pct1/>
<Column id=won_wildcard_pct1/>
<Column id=made_tournament_pct1/>
</DataTable>

### Group C Standings

<DataTable data={standings.filter(d => d.group === "west_c")} link=team_link rows=5>
<Column id=team/>
<Column id=record/>
<Column id=proj_record/>
<Column id=won_group_pct1/>
<Column id=won_wildcard_pct1/>
<Column id=made_tournament_pct1/>
</DataTable>

</Tab>
</Tabs>

## Recent Games

<DataTable
data={most_recent_games}
rows=5
/>

## Upcoming Games

<DataTable
data={future_games}
/>

## Predicted Matchups - Knockout Round

Once I have a good method to predict winnders of each group and break ties, I will add probabilities for each of the 9 games in the tournament, both which teams will play in the games as well as the predicted winners.
2 changes: 1 addition & 1 deletion transform/models/_nba_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ models:
- name: type
tests:
- accepted_values:
values: ['reg_season','playin_r1','playin_r2','playoffs_r1','playoffs_r2','playoffs_r3','playoffs_r4']
values: ['reg_season','playin_r1','playin_r2','playoffs_r1','playoffs_r2','playoffs_r3','playoffs_r4','tournament']
- name: series_id
- name: visiting_conf
- name: visiting_team
Expand Down
9 changes: 4 additions & 5 deletions transform/models/nba/analysis/reg_season_predictions.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
SELECT
game_id,
date,
home_team,
home_team_elo_rating,
visiting_team,
Expand All @@ -8,9 +9,7 @@ SELECT
winning_team,
include_actuals,
COUNT(*) AS occurances,
{{ american_odds( 'home_team_win_probability/10000' ) }} AS american_odds
{{ american_odds( 'home_team_win_probability/10000' ) }} AS american_odds,
type
FROM {{ ref( 'reg_season_simulator' ) }} S
GROUP BY ALL



GROUP BY ALL
86 changes: 86 additions & 0 deletions transform/models/nba/analysis/tournament_end.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
WITH cte_wins AS (
SELECT
S.scenario_id,
S.winning_team,
CASE
WHEN S.winning_team = S.home_team THEN S.home_conf
ELSE S.visiting_conf
END AS conf,
COUNT(*) AS wins
FROM {{ ref( 'reg_season_simulator' ) }} S
WHERE S.type = 'tournament'
GROUP BY ALL
),

cte_losses AS (
SELECT
S.scenario_id,
CASE WHEN S.home_team = S.winning_team
THEN S.visiting_team ELSE S.home_team
END AS losing_team,
CASE
WHEN S.winning_team = S.home_team THEN S.visiting_conf
ELSE S.home_conf
END AS conf,
COUNT(*) AS losses
FROM {{ ref( 'reg_season_simulator' ) }} S
WHERE S.type = 'tournament'
GROUP BY ALL
),

cte_results_with_group AS (
SELECT
scenarios.scenario_id,
T.team as winning_team,
T.conf,
COALESCE(W.wins,0) AS wins,
COALESCE(L.losses,0) as losses,
T.tournament_group
FROM {{ ref( 'nba_teams') }} T
LEFT JOIN (
SELECT I.generate_series AS scenario_id
FROM generate_series(1, {{ var( 'scenarios' ) }} ) AS I) AS scenarios ON 1=1
LEFT JOIN cte_wins W ON T.team = W.winning_team AND scenarios.scenario_id = W.scenario_id
LEFT JOIN cte_losses L ON T.team = L.losing_team AND scenarios.scenario_id = L.scenario_id
),

/* tiebreaking criteria: https://www.nba.com/news/in-season-tournament-101

• Head-to-head record in the Group Stage;
• Point differential in the Group Stage;
• Total points scored in the Group Stage;
• Regular season record from the 2022-23 NBA regular season; and
• Random drawing (in the unlikely scenario that two or more teams are still tied following the previous tiebreakers).

*/

cte_ranked_wins AS (
SELECT
*,
--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

),

cte_made_tournament AS (
SELECT
*,
CASE
WHEN season_rank = 1 THEN 1
ELSE 0
END AS made_tournament,
CASE
WHEN season_rank = 2 THEN 1
ELSE 0
END AS made_wildcard,
tournament_group || '-' || season_rank::text AS seed
FROM cte_ranked_wins
)

SELECT
MP.*,
LE.elo_rating,
{{ var( 'sim_start_game_id' ) }} AS sim_start_game_id
FROM cte_made_tournament MP
LEFT JOIN {{ ref( 'nba_latest_elo' ) }} LE ON LE.team = MP.winning_team
4 changes: 3 additions & 1 deletion transform/models/nba/prep/nba_reg_season_schedule.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
SELECT
S.id AS game_id,
S.date as date,
'reg_season' AS type,
CASE WHEN s.notes = 'In-Season Tournament'
THEN 'tournament' ELSE 'reg_season' END
AS type,
0 as series_id,
V.conf AS visiting_conf,
V.team AS visiting_team,
Expand Down
Loading
Loading