-
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.
* add lots to team overview page * checkin before restructuring to multipage * total FE overhaul * minor updates * make sure state is there even if they start on sub page
- Loading branch information
Showing
12 changed files
with
503 additions
and
366 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
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
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
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,49 @@ | ||
import matplotlib.pyplot as plt | ||
import streamlit as st | ||
from streamlit_autorefresh import st_autorefresh | ||
|
||
import src.backend as be | ||
|
||
# App configuration | ||
icon_url = "https://spacejam-dashboard.s3.us-east-2.amazonaws.com/assets/the-last-spacejam.jpg" | ||
st.set_page_config(layout="wide", page_title="Spacejam Dashboard", page_icon=icon_url) | ||
st.logo(icon_url, size="large") | ||
refresh_in_sec = 600 | ||
count = st_autorefresh(interval=refresh_in_sec * 1000, limit=100, key="statscounter") | ||
|
||
|
||
# Cached data behind it all | ||
@st.cache_data | ||
def update_league_data(): | ||
return be.get_league() | ||
|
||
|
||
league_data = update_league_data() | ||
if "league_data" not in st.session_state: | ||
st.session_state.league_data = league_data | ||
league_df = be.get_league_cat_data_rankings(league_data) | ||
if "league_df" not in st.session_state: | ||
st.session_state.league_df = league_df | ||
teams = [team.team_name for team in league_data.teams.values()] | ||
if "teams" not in st.session_state: | ||
st.session_state.teams = teams | ||
|
||
# Sidebar for page selection | ||
st.sidebar.success("Welcome to the Spacejam Dashboard, written by the Tatums.") | ||
st.sidebar.subheader("And now, a joke powered by AI 🤖") | ||
st.sidebar.write(be.get_mainpage_joke()) | ||
|
||
# Main Page content | ||
st.title("Spacejam Dashboard") | ||
st.subheader("About") | ||
st.markdown( | ||
"This dashboard serves two purposes: \n 1. Be a fun project for me to work on. \n 2. Provide some more data to everyone who isn't already paying for a fancy schmancy site already." | ||
) | ||
st.subheader("Category Rankings (Green is good)") | ||
st.markdown( | ||
"This was the first bit of data that I wanted to understand when I was left with my head in my hands after a loss to Will saying 'What are the Tatum's good for?'" | ||
) | ||
|
||
gyr = plt.colormaps["RdYlGn"].reversed() | ||
league_df_styled = league_df.style.background_gradient(cmap=gyr) | ||
st.dataframe(league_df_styled, use_container_width=True, hide_index=True, height=460) |
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,29 @@ | ||
import math | ||
|
||
import matplotlib.cm as cm | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
import pandas as pd | ||
|
||
import src.constants as const | ||
|
||
|
||
def create_cat_bar_charts(agg: pd.DataFrame) -> list[plt.Figure]: | ||
"""Create a bar chart for each column in the DataFrame.""" | ||
# Create a figure with subplots | ||
num_columns = len(agg.columns) | ||
root = np.ceil(math.sqrt(num_columns)).astype(int) | ||
fig, axes = plt.subplots(root, root, figsize=(15, 10), constrained_layout=True) | ||
|
||
# Plot each column as a bar chart in its own subplot | ||
colors = cm.viridis(np.linspace(0, 1, 3)) # You can use any colormap | ||
for i in range(3): | ||
for j in range(3): | ||
index = i * 3 + j | ||
column_data = const.NINE_CATS[index] | ||
axes[i, j].bar(agg.index, agg[column_data], color=colors) # Bar chart | ||
axes[i, j].set_title(column_data) # Set title to column name | ||
axes[i, j].set_xticks(range(len(agg.index))) # Position the ticks | ||
axes[i, j].set_xticklabels(agg.index, rotation=45) # Rotate for readability | ||
axes[i, j].set_ylabel("Avg Per Game") # Label for y-axis | ||
return fig |
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,92 @@ | ||
import streamlit as st | ||
from espn_api.basketball import Team | ||
|
||
import src.backend as be | ||
import src.constants as const | ||
import src.frontend.figures as fig | ||
import src.frontend.streamlit_utils as su | ||
|
||
# App configuration | ||
icon_url = "https://spacejam-dashboard.s3.us-east-2.amazonaws.com/assets/the-last-spacejam.jpg" | ||
st.logo(icon_url, size="large") | ||
|
||
|
||
# Cached data behind it all | ||
@st.cache_data | ||
def update_league_data(): | ||
return be.get_league() | ||
|
||
|
||
league_data = update_league_data() | ||
if "league_data" not in st.session_state: | ||
st.session_state.league_data = league_data | ||
league_df = be.get_league_cat_data_rankings(league_data) | ||
if "league_df" not in st.session_state: | ||
st.session_state.league_df = league_df | ||
teams = [team.team_name for team in league_data.teams.values()] | ||
if "teams" not in st.session_state: | ||
st.session_state.teams = teams | ||
|
||
|
||
league_data = st.session_state.league_data | ||
teams = st.session_state.teams | ||
league_df = st.session_state.league_df | ||
|
||
st.sidebar.subheader("And now, a joke powered by AI 🤖") | ||
|
||
st.title(const.TEAM_PAGE_TITLE) | ||
chosen_team = st.selectbox("Team", teams) | ||
st.sidebar.write(be.get_teamviewer_joke(chosen_team)) | ||
team_data = league_data.teams[chosen_team] | ||
seven_day_stats = be.get_average_team_stats(team_data, 7) | ||
fifteen_day_stats = be.get_average_team_stats(team_data, 15) | ||
thirty_day_stats = be.get_average_team_stats(team_data, 30) | ||
agg_stats = be.agg_player_avgs(seven_day_stats, fifteen_day_stats, thirty_day_stats) | ||
team_obj: Team = league_data.teams[chosen_team] | ||
standing_col, record_col, acquisitions_col, div_col = st.columns(4, vertical_alignment="center") | ||
with standing_col: | ||
st.metric("League Wide Standing", f"{team_obj.standing}") | ||
with div_col: | ||
st.metric("Division:", f"{team_obj.division_name}") | ||
with record_col: | ||
st.metric("Current Record:", f"{team_obj.wins}W - {team_obj.losses}L - {team_obj.ties}T") | ||
with acquisitions_col: | ||
st.metric("Total Acquisitions Used:", f"{team_obj.acquisitions} / 70") | ||
|
||
st.header("Category Rankings") | ||
left_col, mid_col, right_col = st.columns(3) | ||
team_data = league_df.loc[league_df["Team"] == chosen_team].to_dict("records")[0] | ||
strengths, weaknesses, punts = be.get_team_breakdown(team_data) | ||
|
||
num_cats_per_row = 3 | ||
with left_col: | ||
st.subheader("Team Strengths") | ||
st.markdown("Team ranks in top 4 of these categories.") | ||
su.create_metric_grid(strengths, num_cats_per_row) | ||
|
||
with mid_col: | ||
st.subheader("Could go either way") | ||
st.markdown("Team ranks in middle 4 of these categories.") | ||
su.create_metric_grid(weaknesses, num_cats_per_row) | ||
|
||
with right_col: | ||
st.subheader("Team Punts") | ||
st.markdown("Team ranks in bottom 4 of league in these categories. (hopefully on purpose)") | ||
su.create_metric_grid(punts, num_cats_per_row) | ||
|
||
with st.expander("🏀 Individual Player Stats"): | ||
timeframe = st.radio("Past:", ["7 Days", "15 Days", "30 Days"], horizontal=True) | ||
show_cols = st.multiselect( | ||
"Column Filter", options=seven_day_stats.columns, default=const.NINE_CATS | ||
) | ||
if timeframe == "7 Days": | ||
st.dataframe(seven_day_stats[show_cols], use_container_width=True) | ||
elif timeframe == "15 Days": | ||
st.dataframe(fifteen_day_stats[show_cols], use_container_width=True) | ||
elif timeframe == "30 Days": | ||
st.dataframe(thirty_day_stats[show_cols], use_container_width=True) | ||
|
||
with st.expander("📊 Team Category Trends"): | ||
st.write("Team Trends - ", chosen_team) | ||
fig = fig.create_cat_bar_charts(agg_stats.T) | ||
st.pyplot(fig) |
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,31 @@ | ||
import streamlit as st | ||
|
||
import src.backend as be | ||
|
||
# App configuration | ||
icon_url = "https://spacejam-dashboard.s3.us-east-2.amazonaws.com/assets/the-last-spacejam.jpg" | ||
st.set_page_config(layout="wide", page_title="Spacejam Dashboard", page_icon=icon_url) | ||
st.logo(icon_url, size="large") | ||
|
||
|
||
# Cached data behind it all | ||
@st.cache_data | ||
def update_league_data(): | ||
return be.get_league() | ||
|
||
|
||
league_data = update_league_data() | ||
if "league_data" not in st.session_state: | ||
st.session_state.league_data = league_data | ||
league_df = be.get_league_cat_data_rankings(league_data) | ||
if "league_df" not in st.session_state: | ||
st.session_state.league_df = league_df | ||
teams = [team.team_name for team in league_data.teams.values()] | ||
if "teams" not in st.session_state: | ||
st.session_state.teams = teams | ||
|
||
|
||
st.title("Coming soon....🚧") | ||
|
||
st.header("And now, a joke powered by AI 🤖") | ||
st.write(be.get_mainpage_joke()) |
Oops, something went wrong.