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

Update NBA data for new season #169

Merged
merged 7 commits into from
Oct 24, 2024
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
1,235 changes: 3 additions & 1,232 deletions data/nba/nba_results.csv

Large diffs are not rendered by default.

2,460 changes: 1,230 additions & 1,230 deletions data/nba/nba_schedule.csv

Large diffs are not rendered by default.

60 changes: 30 additions & 30 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,tournament_group,alt_key
BOS,Boston Celtics,East,1610,54.7,east_c,BOS
MIL,Milwaukee Bucks,East,1602,53.9,east_b,MIL
MIA,Miami Heat,East,1524,45.3,east_b,MIA
BRK,Brooklyn Nets,East,1463,37.3,east_c,BKN
PHO,Phoenix Suns,West,1584,51.5,west_a,PHX
LAC,Los Angeles Clippers,West,1546,46.5,west_b,LAC
PHI,Philadelphia 76ers,East,1552,48.1,east_a,PHI
DEN,Denver Nuggets,West,1594,52.5,west_b,DEN
GSW,Golden State Warriors,West,1561,48.3,west_c,GSW
DAL,Dallas Mavericks,West,1525,44.3,west_b,DAL
MEM,Memphis Grizzlies,West,1538,45.9,west_a,MEM
UTA,Utah Jazz,West,1452,35.5,west_a,UTA
ATL,Atlanta Hawks,East,1503,42.5,east_a,ATL
NOP,New Orleans Pelicans,West,1526,44.5,west_b,NOP
TOR,Toronto Raptors,East,1454,36.5,east_c,TOR
MIN,Minnesota Timberwolves,West,1529,44.7,west_c,MIN
LAL,Los Angeles Lakers,West,1554,47.5,west_a,LAL
POR,Portland Trail Blazers,West,1391,28.5,west_a,POR
CHI,Chicago Bulls,East,1463,37.5,east_c,CHI
CHO,Charlotte Hornets,East,1406,30.9,east_b,CHA
NYK,New York Knicks,East,1531,45.5,east_b,NYK
IND,Indiana Pacers,East,1473,38.7,east_a,IND
CLE,Cleveland Cavaliers,East,1571,50.5,east_a,CLE
SAC,Sacramento Kings,West,1531,44.5,west_c,SAC
SAS,San Antonio Spurs,West,1398,29.1,west_c,SAS
WAS,Washington Wizards,East,1345,24.5,east_b,WAS
ORL,Orlando Magic,East,1455,36.7,east_c,ORL
DET,Detroit Pistons,East,1375,27.5,east_a,DET
OKC,Oklahoma City Thunder,West,1526,44.5,west_c,OKC
HOU,Houston Rockets,West,1416,31.5,west_b,HOU
ATL,Atlanta Hawks,East,1539,35.6,east_c,ATL
BOS,Boston Celtics,East,1764,58.2,east_c,BOS
BRK,Brooklyn Nets,East,1384,20.2,east_a,BKN
CHI,Chicago Bulls,East,1471,28.4,east_c,CHI
CHO,Charlotte Hornets,East,1496,31.1,east_a,CHA
CLE,Cleveland Cavaliers,East,1673,49,east_c,CLE
DET,Detroit Pistons,East,1445,25.9,east_b,DET
IND,Indiana Pacers,East,1643,46.5,east_b,IND
MIA,Miami Heat,East,1623,43.8,east_b,MIA
MIL,Milwaukee Bucks,East,1673,49.2,east_b,MIL
NYK,New York Knicks,East,1711,53.2,east_a,NYK
ORL,Orlando Magic,East,1650,47.3,east_a,ORL
PHI,Philadelphia 76ers,East,1670,48.6,east_a,PHI
TOR,Toronto Raptors,East,1473,28.7,east_b,TOR
WAS,Washington Wizards,East,1372,19.6,east_c,WAS
DAL,Dallas Mavericks,West,1688,49.5,west_c,DAL
DEN,Denver Nuggets,West,1701,50.5,west_c,DEN
GSW,Golden State Warriors,West,1635,43.5,west_c,GSW
HOU,Houston Rockets,West,1631,43,west_a,HOU
LAC,Los Angeles Clippers,West,1558,35.3,west_a,LAC
LAL,Los Angeles Lakers,West,1624,43,west_b,LAL
MEM,Memphis Grizzlies,West,1662,46.5,west_c,MEM
MIN,Minnesota Timberwolves,West,1708,51.2,west_a,MIN
NOP,New Orleans Pelicans,West,1653,45.5,west_c,NOP
OKC,Oklahoma City Thunder,West,1767,57.2,west_b,OKC
PHO,Phoenix Suns,West,1681,48.3,west_b,PHX
POR,Portland Trail Blazers,West,1407,20.9,west_a,POR
SAC,Sacramento Kings,West,1663,47.1,west_a,SAC
SAS,San Antonio Spurs,West,1555,35.3,west_b,SAS
UTA,Utah Jazz,West,1482,27.9,west_b,UTA
2 changes: 1 addition & 1 deletion dlt/nba_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from dlt.sources.helpers import requests

# Specify the URL of the API endpoint
url = "https://api.pbpstats.com/get-games/nba?Season=2023-24&SeasonType=Regular%20Season"
url = "https://api.pbpstats.com/get-games/nba?Season=2024-25&SeasonType=Regular%20Season"
# Make a request and check if it was successful
response = requests.get(url)
response.raise_for_status()
Expand Down
Empty file added evidence/archive/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions evidence/pages/nba/historical_matchups.md
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ _If you don't like the current results, you can modify the elo inputs with this
value=score
current=0
title="elo slider"
min=-100
max=100
/>
<br>
The current value is {inputs.elo_slider}.
73 changes: 36 additions & 37 deletions evidence/pages/nba/in-season tournament/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ ORDER BY conf, wins DESC, made_tournament_pct1 DESC, margin DESC

# NBA In-season Tournament

Congrats to the Los Angeles Lakers for winning the 2023-24 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
Expand All @@ -32,9 +30,9 @@ _New for the 2023-2024 season, the NBA has introduced an In-Season Tournament. T
<Column id=record/>
<Column id=pt_diff align=right/>
<Column id=proj_record align=right/>
<Column id=won_group_pct1/>
<Column id=won_wildcard_pct1/>
<Column id=made_tournament_pct1/>
<Column id=won_group_pct1 title="Win Group"/>
<Column id=won_wildcard_pct1 title="Win Wildcard"/>
<Column id=made_tournament_pct1 title="Made Tournament"/>
</DataTable>

### Group B Standings
Expand All @@ -44,9 +42,9 @@ _New for the 2023-2024 season, the NBA has introduced an In-Season Tournament. T
<Column id=record/>
<Column id=pt_diff align=right/>
<Column id=proj_record align=right/>
<Column id=won_group_pct1/>
<Column id=won_wildcard_pct1/>
<Column id=made_tournament_pct1/>
<Column id=won_group_pct1 title="Win Group"/>
<Column id=won_wildcard_pct1 title="Win Wildcard"/>
<Column id=made_tournament_pct1 title="Made Tournament"/>
</DataTable>

### Group C Standings
Expand All @@ -56,9 +54,9 @@ _New for the 2023-2024 season, the NBA has introduced an In-Season Tournament. T
<Column id=record/>
<Column id=pt_diff align=right/>
<Column id=proj_record align=right/>
<Column id=won_group_pct1/>
<Column id=won_wildcard_pct1/>
<Column id=made_tournament_pct1/>
<Column id=won_group_pct1 title="Win Group"/>
<Column id=won_wildcard_pct1 title="Win Wildcard"/>
<Column id=made_tournament_pct1 title="Made Tournament"/>
</DataTable>
</Tab>
<Tab label="West">
Expand All @@ -70,9 +68,9 @@ _New for the 2023-2024 season, the NBA has introduced an In-Season Tournament. T
<Column id=record/>
<Column id=pt_diff align=right/>
<Column id=proj_record align=right/>
<Column id=won_group_pct1/>
<Column id=won_wildcard_pct1/>
<Column id=made_tournament_pct1/>
<Column id=won_group_pct1 title="Win Group"/>
<Column id=won_wildcard_pct1 title="Win Wildcard"/>
<Column id=made_tournament_pct1 title="Made Tournament"/>
</DataTable>

### Group B Standings
Expand All @@ -82,9 +80,9 @@ _New for the 2023-2024 season, the NBA has introduced an In-Season Tournament. T
<Column id=record/>
<Column id=pt_diff align=right/>
<Column id=proj_record align=right/>
<Column id=won_group_pct1/>
<Column id=won_wildcard_pct1/>
<Column id=made_tournament_pct1/>
<Column id=won_group_pct1 title="Win Group"/>
<Column id=won_wildcard_pct1 title="Win Wildcard"/>
<Column id=made_tournament_pct1 title="Made Tournament"/>
</DataTable>

### Group C Standings
Expand All @@ -94,9 +92,9 @@ _New for the 2023-2024 season, the NBA has introduced an In-Season Tournament. T
<Column id=record/>
<Column id=pt_diff align=right/>
<Column id=proj_record align=right/>
<Column id=won_group_pct1/>
<Column id=won_wildcard_pct1/>
<Column id=made_tournament_pct1/>
<Column id=won_group_pct1 title="Win Group"/>
<Column id=won_wildcard_pct1 title="Win Wildcard"/>
<Column id=made_tournament_pct1 title="Made Tournament"/>
</DataTable>
</Tab>
</Tabs>
Expand All @@ -113,20 +111,20 @@ _New for the 2023-2024 season, the NBA has introduced an In-Season Tournament. T
<Column id=record/>
<Column id=pt_diff align=right/>
<Column id=proj_record align=right/>
<Column id=won_group_pct1/>
<Column id=won_wildcard_pct1/>
<Column id=made_tournament_pct1/>
<Column id=won_group_pct1 title="Win Group"/>
<Column id=won_wildcard_pct1 title="Win Wildcard"/>
<Column id=made_tournament_pct1 title="Made Tournament"/>
</DataTable>

### Predicted Seeding - Knockout Round

<DataTable data={tournament_seeding.filter(d => d.conf === "East")} rows=15>
<Column id=team/>
<Column id="1_pct1" contentType=colorscale colorMax=1/>
<Column id="2_pct1" contentType=colorscale colorMax=1/>
<Column id="3_pct1" contentType=colorscale colorMax=1/>
<Column id="4_pct1" contentType=colorscale colorMax=1/>
<Column id="total_pct1" contentType=colorscale colorMax=1/>
<Column id="1_pct1" contentType=colorscale colorMax=1 title="1"/>
<Column id="2_pct1" contentType=colorscale colorMax=1 title="2"/>
<Column id="3_pct1" contentType=colorscale colorMax=1 title="3"/>
<Column id="4_pct1" contentType=colorscale colorMax=1 title="3"/>
<Column id="total_pct1" contentType=colorscale colorMax=1 title="Total"/>
</DataTable>
</Tab>
<Tab label="West">
Expand All @@ -138,25 +136,25 @@ _New for the 2023-2024 season, the NBA has introduced an In-Season Tournament. T
<Column id=record/>
<Column id=pt_diff align=right/>
<Column id=proj_record align=right/>
<Column id=won_group_pct1/>
<Column id=won_wildcard_pct1/>
<Column id=made_tournament_pct1/>
<Column id=won_group_pct1 title="Win Group"/>
<Column id=won_wildcard_pct1 title="Win Wildcard"/>
<Column id=made_tournament_pct1 title="Made Tournament"/>
</DataTable>

### Predicted Seeding - Knockout Round

<DataTable data={tournament_seeding.filter(d => d.conf === "West")} rows=15>
<Column id=team/>
<Column id="1_pct1" contentType=colorscale colorMax=1/>
<Column id="2_pct1" contentType=colorscale colorMax=1/>
<Column id="3_pct1" contentType=colorscale colorMax=1/>
<Column id="4_pct1" contentType=colorscale colorMax=1/>
<Column id="total_pct1" contentType=colorscale colorMax=1/>
<Column id="1_pct1" contentType=colorscale colorMax=1 title="1"/>
<Column id="2_pct1" contentType=colorscale colorMax=1 title="2"/>
<Column id="3_pct1" contentType=colorscale colorMax=1 title="3"/>
<Column id="4_pct1" contentType=colorscale colorMax=1 title="3"/>
<Column id="total_pct1" contentType=colorscale colorMax=1 title="Total"/>
</DataTable>
</Tab>
</Tabs>


{#if most_recent_games.filter(d => d.type === "tournament" || d.type === 'knockout') > 0}
## Recent Games

<DataTable data={most_recent_games.filter(d => d.type === "tournament" || d.type === 'knockout')} rows=5>
Expand All @@ -167,3 +165,4 @@ _New for the 2023-2024 season, the NBA has introduced an In-Season Tournament. T
<Column id=winning_team/>
<Column id=score/>
</DataTable>
{/if}
7 changes: 0 additions & 7 deletions evidence/pages/nba/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ This data was last updated as of <Value data={thru_date} column=end_date/>.

## [Upcoming Games](/nba/predictions)

{#if filtered_future_games.length > 0}
<Dropdown
data={teams}
name=team_dd
Expand All @@ -50,12 +49,6 @@ This data was last updated as of <Value data={thru_date} column=end_date/>.
<Column id=predicted_score title="Score"/>
</DataTable>

{:else}

_The regular season is over. Check back next year!_

{/if}

## [Team Standings](/nba/teams)

<DataTable data={summary_by_team} link=team_link rows=5 search=true>
Expand Down
4 changes: 1 addition & 3 deletions evidence/pages/nba/predictions/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ order by team
</Accordion>


{#if filtered_future_games.length > 0}
## Future Predictions

_Historically, NBA teams win 62% of their games at home, which explains why teams with lower elo ratings can be predicted to win._
Expand All @@ -70,5 +69,4 @@ _Historically, NBA teams win 62% of their games at home, which explains why team
<Column id=american_odds align=right title="Odds (Home)"/>
<Column id=implied_line_num1 title="Line (Home)"/>
<Column id=predicted_score title="Score"/>
</DataTable>
{/if}
</DataTable>
23 changes: 15 additions & 8 deletions evidence/pages/nba/teams/[nba_teams].md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ queries:
<BigValue
data={filtered_season_summary}
value='predicted_wins'
comparison='vs_vegas_num1'
comparison='vs_vegas_num1'
comparisonTitle='vs. Vegas'
/>

<BigValue
Expand Down Expand Up @@ -69,10 +70,13 @@ queries:

### Matchup Summary

<DataTable
data={records_table.filter(d => d.team === params.nba_teams.toUpperCase())}
rows=7
/>
<DataTable data={records_table.filter(d => d.team === params.nba_teams.toUpperCase())} rows=7>
<Column id=team/>
<Column id=type/>
<Column id=wins/>
<Column id=losses/>
<Column id=win_pct_num3 title="Win %"/>
</DataTable>

{#if future_games.length > 0}
### Upcoming Schedule
Expand All @@ -92,17 +96,20 @@ queries:

<BigValue
data={playoff_odds.filter(d => d.team === params.nba_teams.toUpperCase())}
value='top_six_pct1'
value='top_six_pct1'
title='Top 6 Seed (%)'
/>

<BigValue
data={playoff_odds.filter(d => d.team === params.nba_teams.toUpperCase())}
value='play_in_pct1'
value='play_in_pct1'
title='Play-in (%)'
/>

<BigValue
data={playoff_odds.filter(d => d.team === params.nba_teams.toUpperCase())}
value='missed_playoffs_pct1'
value='missed_playoffs_pct1'
title='Miss Playoffs (%)'
/>

<AreaChart
Expand Down
6 changes: 3 additions & 3 deletions evidence/pages/nba/teams/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ queries:
<Column id=record/>
<Column id=elo_rating/>
<Column id=avg_wins/>
<Column id=elo_vs_vegas_num1 contentType=delta/>
<Column id=make_playoffs_pct1/>
<Column id=win_finals_pct1/>
<Column id=elo_vs_vegas_num1 contentType=delta title="Elo vs. Vegas"/>
<Column id=make_playoffs_pct1 title="Make Playoffs (%)"/>
<Column id=win_finals_pct1 title = "Win Finals (%)" />
</DataTable>

{:else }
Expand Down
Binary file removed transform/datadata_catalogmdsbox.duckdb
Binary file not shown.
2 changes: 1 addition & 1 deletion transform/dbt_project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ vars:
nba_elo_offset: 100 # nba offset to ELO to get to ~12% home advantage
nfl_elo_offset: 52 # nfl offset to ELO to get to 7.5% home advantage
ncaaf_elo_offset: 52 # ncaaf offset to ELO to get to 7.5% home advantage
nba_start_date: '2024-04-15' # set as of date for start of season
nba_start_date: '2025-04-15' # set as of date for start of season

# external files are only registered as DuckDB views when they are created, not when they are referenced.
on-run-start:
Expand Down
5 changes: 3 additions & 2 deletions transform/models/nba/analysis/reg_season_predictions.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
with
cte_team_scores as (
from {{ ref("nba_results_by_team") }}
select team, avg(score) as pts
select t.team, coalesce(avg(r.score),115) as pts --add 115 to account for missing data
from {{ ref( "nba_teams")}} t
left join {{ ref("nba_results_by_team") }} r on r.team = t.team
group by all
),
cte_interim_calcs as (
Expand Down
4 changes: 2 additions & 2 deletions transform/models/nba/analysis/reg_season_summary.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ with
select
winning_team as team,
e.conf,
round(avg(wins), 1) as avg_wins,
round(avg(wins)/80.0*82.0, 1) as avg_wins, -- gross up for 82 games
v.win_total as vegas_wins,
round(avg(v.win_total) - avg(wins), 1) as elo_vs_vegas,
round(avg(v.win_total) - (avg(wins)/80.0*82.0), 1) as elo_vs_vegas, -- gross up for 82 games
round(
percentile_cont(0.05) within group (order by wins asc), 1
) as wins_5th,
Expand Down
1 change: 1 addition & 0 deletions transform/models/nba/raw/nba_raw_schedule.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ select
notes,
series_id
from {{ source("nba", "nba_schedule") }}
where arena <> 'Placeholder' -- removing IST games w/o teams & arena
Loading