-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
748 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
#project | ||
main.ipynb | ||
.vscode/* | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
3.13 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[project] | ||
name = "space-jam-dashboard" | ||
version = "0.1.0" | ||
description = "Add your description here" | ||
readme = "README.md" | ||
requires-python = ">=3.13" | ||
dependencies = [ | ||
"espn-api>=0.43.0", | ||
"pandas>=2.2.3", | ||
"panel>=1.5.4", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import pandas as pd | ||
|
||
from espn_api.basketball import League | ||
|
||
import constants as const | ||
|
||
|
||
def get_league(league_id: int = const.SPACEJAM_LEAGUE_ID, year: int = const.YEAR): | ||
return League(league_id, year) | ||
|
||
|
||
def get_league_all_raw_stats_df(league: League): | ||
league_stats = [] | ||
for team in league.teams: | ||
temp_dict = team.stats.copy() | ||
temp_dict["Team"] = team.team_name | ||
temp_dict["Standing"] = team.standing | ||
league_stats.append(temp_dict) | ||
|
||
df = pd.DataFrame(league_stats) | ||
|
||
df = df.astype(const.ALL_RAW_DATA_TABLE_DEF) | ||
return df[list(const.ALL_RAW_DATA_TABLE_DEF.keys())] | ||
|
||
|
||
def get_league_all_raw_data_rankings(league: League): | ||
raw_stats_df = get_league_all_raw_stats_df(league) | ||
# Rank only numeric columns | ||
want_big_num_df = raw_stats_df[const.WANT_BIG_NUM] | ||
want_small_num_df = raw_stats_df[const.WANT_SMALL_NUM] | ||
want_big_ranked_df = want_big_num_df.rank(ascending=False).astype(int) | ||
want_small_ranked_df = want_small_num_df.rank(ascending=True).astype(int) | ||
ranked_df = pd.concat([want_big_ranked_df, want_small_ranked_df], axis=1) | ||
ranked_df["Avg. Cat. Rank"] = ranked_df.mean(axis=1) | ||
|
||
# Concatenate with non-numeric columns | ||
ranked_df = pd.concat( | ||
[ | ||
ranked_df, | ||
raw_stats_df.select_dtypes(exclude="number"), | ||
], | ||
axis=1, | ||
) | ||
|
||
return ranked_df[list(const.ALL_DATA_RANKED_TABLE_DEF.keys())] | ||
|
||
|
||
def get_league_cat_raw_stats_df(league: League): | ||
league_stats = [] | ||
for team in league.teams: | ||
temp_dict = team.stats.copy() | ||
temp_dict["Team"] = team.team_name | ||
temp_dict["Standing"] = team.standing | ||
league_stats.append(temp_dict) | ||
|
||
df = pd.DataFrame(league_stats) | ||
|
||
df = df.astype(const.CAT_ONLY_RAW_DATA_TABLE_DEF) | ||
return df[list(const.CAT_ONLY_RAW_DATA_TABLE_DEF.keys())] | ||
|
||
|
||
def get_league_cat_data_rankings(league: League): | ||
raw_stats_df = get_league_all_raw_stats_df(league) | ||
# Rank only numeric columns | ||
want_big_num_df = raw_stats_df[const.WANT_BIG_NUM] | ||
want_small_num_df = raw_stats_df[const.WANT_SMALL_NUM] | ||
want_big_ranked_df = want_big_num_df.rank(ascending=False).astype(int) | ||
want_small_ranked_df = want_small_num_df.rank(ascending=True).astype(int) | ||
ranked_df = pd.concat([want_big_ranked_df, want_small_ranked_df], axis=1) | ||
ranked_df["Avg. Cat. Rank"] = ranked_df.mean(axis=1) | ||
|
||
# Concatenate with non-numeric columns | ||
ranked_df = pd.concat( | ||
[ | ||
ranked_df, | ||
raw_stats_df.select_dtypes(exclude="number"), | ||
], | ||
axis=1, | ||
) | ||
return ranked_df[list(const.CAT_ONLY_DATA_RANKED_TABLE_DEF.keys())] | ||
|
||
|
||
if __name__ == "__main__": | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
SPACEJAM_LEAGUE_ID = 233677 | ||
YEAR = 2025 | ||
|
||
ALL_RAW_DATA_TABLE_DEF = { | ||
"Team": str, | ||
"Standing": int, | ||
"PTS": int, | ||
"BLK": int, | ||
"STL": int, | ||
"AST": int, | ||
"REB": int, | ||
"TO": int, | ||
"FGM": int, | ||
"FGA": int, | ||
"FTM": int, | ||
"FTA": int, | ||
"3PM": int, | ||
"FG%": float, | ||
"FT%": float, | ||
} | ||
|
||
ALL_DATA_RANKED_TABLE_DEF = { | ||
"Team": str, | ||
"Standing": int, | ||
"Avg. Cat. Rank": int, | ||
"PTS": int, | ||
"BLK": int, | ||
"STL": int, | ||
"AST": int, | ||
"REB": int, | ||
"TO": int, | ||
"FGM": int, | ||
"FGA": int, | ||
"FTM": int, | ||
"FTA": int, | ||
"3PM": int, | ||
"FG%": int, | ||
"FT%": int, | ||
} | ||
|
||
CAT_ONLY_RAW_DATA_TABLE_DEF = { | ||
"Team": str, | ||
"Standing": int, | ||
"PTS": int, | ||
"BLK": int, | ||
"STL": int, | ||
"AST": int, | ||
"REB": int, | ||
"TO": int, | ||
"3PM": int, | ||
"FG%": float, | ||
"FT%": float, | ||
} | ||
|
||
CAT_ONLY_DATA_RANKED_TABLE_DEF = { | ||
"Team": str, | ||
"Standing": int, | ||
"Avg. Cat. Rank": int, | ||
"PTS": int, | ||
"BLK": int, | ||
"STL": int, | ||
"AST": int, | ||
"REB": int, | ||
"TO": int, | ||
"3PM": int, | ||
"FG%": int, | ||
"FT%": int, | ||
} | ||
|
||
WANT_BIG_NUM = [ | ||
"PTS", | ||
"BLK", | ||
"STL", | ||
"AST", | ||
"REB", | ||
"FGM", | ||
"FGA", | ||
"FTM", | ||
"FTA", | ||
"3PM", | ||
"FG%", | ||
"FT%", | ||
] | ||
|
||
WANT_SMALL_NUM = ["Standing", "TO"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import panel as pn | ||
import backend as be | ||
|
||
pn.extension("tabulator") | ||
|
||
all_stats = be.get_league_all_raw_stats_df(be.get_league()) | ||
all_rankings = be.get_league_all_raw_data_rankings(be.get_league()) | ||
cat_stats = be.get_league_cat_raw_stats_df(be.get_league()) | ||
cat_rankings = be.get_league_cat_data_rankings(be.get_league()) | ||
|
||
|
||
def get_dataframe(mode: pn.widgets.Select): | ||
if mode == "All Data - Raw Stats": | ||
df = all_stats | ||
elif mode == "All Data - Ranked": | ||
df = all_rankings | ||
elif mode == "Categories - Raw Stats": | ||
df = cat_stats | ||
elif mode == "Categories - Rankings": | ||
df = cat_rankings | ||
return df | ||
|
||
|
||
mode = pn.widgets.Select( | ||
name="Mode", | ||
options=[ | ||
"Categories - Rankings", | ||
"Categories - Raw Stats", | ||
"All Data - Ranked", | ||
"All Data - Raw Stats", | ||
], | ||
) | ||
|
||
interactive_df = pn.bind(get_dataframe, mode) | ||
|
||
interactive_table = pn.widgets.Tabulator(interactive_df, theme="site", show_index=False) | ||
|
||
pn.template.ReactTemplate( | ||
title="Space Jam Dashboard", | ||
sidebar=[mode], | ||
main=[interactive_table], | ||
sidebar_width=150, | ||
).servable() |
Oops, something went wrong.