Update app.py
Browse files
app.py
CHANGED
|
@@ -82,6 +82,9 @@ def generate_mock_historical_data(num_teams, num_conferences, num_inter_games, s
|
|
| 82 |
|
| 83 |
# Team Workload Analysis
|
| 84 |
def team_workload_analysis(schedule_df):
|
|
|
|
|
|
|
|
|
|
| 85 |
"""Generate a bar chart showing the number of matches each team has per week."""
|
| 86 |
schedule_df['Week'] = schedule_df['Date'].dt.isocalendar().week
|
| 87 |
team_counts = schedule_df.groupby(['Week', 'Team 1']).size().unstack().fillna(0)
|
|
@@ -97,6 +100,9 @@ def team_workload_analysis(schedule_df):
|
|
| 97 |
|
| 98 |
# Match Distribution
|
| 99 |
def match_distribution(schedule_df):
|
|
|
|
|
|
|
|
|
|
| 100 |
"""Generate a histogram showing match distribution across months."""
|
| 101 |
schedule_df['Month'] = schedule_df['Date'].dt.month_name()
|
| 102 |
month_order = ['November', 'December', 'January', 'February', 'March']
|
|
@@ -112,6 +118,9 @@ def match_distribution(schedule_df):
|
|
| 112 |
|
| 113 |
# Inter-Conference Match Analysis
|
| 114 |
def inter_conference_analysis(schedule_df):
|
|
|
|
|
|
|
|
|
|
| 115 |
"""Generate a heatmap showing inter-conference match frequencies."""
|
| 116 |
# Extract the conference from the team names
|
| 117 |
schedule_df['Conference 1'] = schedule_df['Team 1'].str[0]
|
|
@@ -143,6 +152,9 @@ def inter_conference_analysis(schedule_df):
|
|
| 143 |
|
| 144 |
# Commissioner Analytics
|
| 145 |
def commissioner_analytics(schedule_df, commissioners):
|
|
|
|
|
|
|
|
|
|
| 146 |
"""Generate a bar chart showing matches overseen by each commissioner."""
|
| 147 |
# Assuming each commissioner oversees a specific conference
|
| 148 |
comm_dict = {f"Conference {chr(65+i)}": comm for i, comm in enumerate(commissioners)}
|
|
@@ -221,6 +233,11 @@ st.header("Analytics & Comparisons")
|
|
| 221 |
analytics_option = st.selectbox("Choose an analysis type:", ["Team Workload Analysis", "Match Distribution", "Inter-Conference Match Analysis", "Commissioner Analytics"])
|
| 222 |
st.session_state.historical_data['Date'] = pd.to_datetime(st.session_state.historical_data['Date'])
|
| 223 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 224 |
if analytics_option == "Team Workload Analysis":
|
| 225 |
st.subheader("Historical Data")
|
| 226 |
st.pyplot(team_workload_analysis(st.session_state.historical_data))
|
|
@@ -244,5 +261,7 @@ elif analytics_option == "Commissioner Analytics":
|
|
| 244 |
st.pyplot(commissioner_analytics(st.session_state.historical_data, commissioners))
|
| 245 |
st.subheader("Current Data")
|
| 246 |
st.pyplot(commissioner_analytics(st.session_state.schedule_df, commissioners))
|
|
|
|
|
|
|
| 247 |
|
| 248 |
# Export functionality can be added later
|
|
|
|
| 82 |
|
| 83 |
# Team Workload Analysis
|
| 84 |
def team_workload_analysis(schedule_df):
|
| 85 |
+
if schedule_df is None:
|
| 86 |
+
return
|
| 87 |
+
else
|
| 88 |
"""Generate a bar chart showing the number of matches each team has per week."""
|
| 89 |
schedule_df['Week'] = schedule_df['Date'].dt.isocalendar().week
|
| 90 |
team_counts = schedule_df.groupby(['Week', 'Team 1']).size().unstack().fillna(0)
|
|
|
|
| 100 |
|
| 101 |
# Match Distribution
|
| 102 |
def match_distribution(schedule_df):
|
| 103 |
+
if schedule_df is None:
|
| 104 |
+
return
|
| 105 |
+
else
|
| 106 |
"""Generate a histogram showing match distribution across months."""
|
| 107 |
schedule_df['Month'] = schedule_df['Date'].dt.month_name()
|
| 108 |
month_order = ['November', 'December', 'January', 'February', 'March']
|
|
|
|
| 118 |
|
| 119 |
# Inter-Conference Match Analysis
|
| 120 |
def inter_conference_analysis(schedule_df):
|
| 121 |
+
if schedule_df is None:
|
| 122 |
+
return
|
| 123 |
+
else
|
| 124 |
"""Generate a heatmap showing inter-conference match frequencies."""
|
| 125 |
# Extract the conference from the team names
|
| 126 |
schedule_df['Conference 1'] = schedule_df['Team 1'].str[0]
|
|
|
|
| 152 |
|
| 153 |
# Commissioner Analytics
|
| 154 |
def commissioner_analytics(schedule_df, commissioners):
|
| 155 |
+
if schedule_df is None:
|
| 156 |
+
return
|
| 157 |
+
else
|
| 158 |
"""Generate a bar chart showing matches overseen by each commissioner."""
|
| 159 |
# Assuming each commissioner oversees a specific conference
|
| 160 |
comm_dict = {f"Conference {chr(65+i)}": comm for i, comm in enumerate(commissioners)}
|
|
|
|
| 233 |
analytics_option = st.selectbox("Choose an analysis type:", ["Team Workload Analysis", "Match Distribution", "Inter-Conference Match Analysis", "Commissioner Analytics"])
|
| 234 |
st.session_state.historical_data['Date'] = pd.to_datetime(st.session_state.historical_data['Date'])
|
| 235 |
|
| 236 |
+
if st.session_state.schedule_df is not None:
|
| 237 |
+
# Call the analytics functions here
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
|
| 241 |
if analytics_option == "Team Workload Analysis":
|
| 242 |
st.subheader("Historical Data")
|
| 243 |
st.pyplot(team_workload_analysis(st.session_state.historical_data))
|
|
|
|
| 261 |
st.pyplot(commissioner_analytics(st.session_state.historical_data, commissioners))
|
| 262 |
st.subheader("Current Data")
|
| 263 |
st.pyplot(commissioner_analytics(st.session_state.schedule_df, commissioners))
|
| 264 |
+
else:
|
| 265 |
+
st.warning("Please generate the schedule first before viewing analytics.")
|
| 266 |
|
| 267 |
# Export functionality can be added later
|