Update app.py
Browse files
app.py
CHANGED
@@ -136,7 +136,6 @@ def match_distribution(schedule_df, conference_team_df):
|
|
136 |
|
137 |
# Inter-Conference Match Analysis
|
138 |
def inter_conference_analysis(schedule_df, conference_team_df):
|
139 |
-
# Check if the DataFrame is None
|
140 |
if schedule_df is None:
|
141 |
plt.figure(figsize=(10, 6))
|
142 |
plt.text(0.5, 0.5, 'Please generate the schedule first before viewing analytics.',
|
@@ -146,29 +145,29 @@ def inter_conference_analysis(schedule_df, conference_team_df):
|
|
146 |
plt.tight_layout()
|
147 |
plt.show()
|
148 |
return
|
149 |
-
|
150 |
-
#
|
151 |
-
team_to_conference =
|
152 |
schedule_df['Conference 1'] = schedule_df['Team 1'].map(team_to_conference)
|
153 |
schedule_df['Conference 2'] = schedule_df['Team 2'].map(team_to_conference)
|
|
|
|
|
|
|
154 |
|
155 |
-
#
|
156 |
-
inter_conference_df = st.session_state.schedule_df[st.session_state.schedule_df['Conference 1'] != st.session_state.schedule_df['Conference 2']]
|
157 |
-
|
158 |
-
# Create a crosstab for the heatmap
|
159 |
heatmap_data = pd.crosstab(inter_conference_df['Conference 1'], inter_conference_df['Conference 2'])
|
160 |
-
|
161 |
-
#
|
162 |
-
all_conferences =
|
163 |
for conf in all_conferences:
|
164 |
if conf not in heatmap_data.columns:
|
165 |
heatmap_data[conf] = 0
|
166 |
if conf not in heatmap_data.index:
|
167 |
heatmap_data.loc[conf] = 0
|
168 |
-
|
169 |
-
heatmap_data = heatmap_data.
|
170 |
-
|
171 |
-
#
|
172 |
plt.figure(figsize=(8, 6))
|
173 |
sns.heatmap(heatmap_data, annot=True, cmap='Oranges', linewidths=.5, cbar_kws={'label': 'Number of Matches'})
|
174 |
plt.title('Inter-Conference Match Analysis')
|
@@ -176,6 +175,7 @@ def inter_conference_analysis(schedule_df, conference_team_df):
|
|
176 |
plt.xlabel('Conference 2')
|
177 |
plt.show()
|
178 |
|
|
|
179 |
# Commissioner Analytics
|
180 |
def commissioner_analytics(schedule_df, conference_team_df, commissioners):
|
181 |
# Check if the DataFrame is None
|
|
|
136 |
|
137 |
# Inter-Conference Match Analysis
|
138 |
def inter_conference_analysis(schedule_df, conference_team_df):
|
|
|
139 |
if schedule_df is None:
|
140 |
plt.figure(figsize=(10, 6))
|
141 |
plt.text(0.5, 0.5, 'Please generate the schedule first before viewing analytics.',
|
|
|
145 |
plt.tight_layout()
|
146 |
plt.show()
|
147 |
return
|
148 |
+
|
149 |
+
# Mapping teams to their conferences from the conference_team_df
|
150 |
+
team_to_conference = conference_team_df.set_index('Team')['Conference'].to_dict()
|
151 |
schedule_df['Conference 1'] = schedule_df['Team 1'].map(team_to_conference)
|
152 |
schedule_df['Conference 2'] = schedule_df['Team 2'].map(team_to_conference)
|
153 |
+
|
154 |
+
# Filtering out the intra-conference matches
|
155 |
+
inter_conference_df = schedule_df[schedule_df['Conference 1'] != schedule_df['Conference 2']]
|
156 |
|
157 |
+
# Creating a crosstab for the heatmap
|
|
|
|
|
|
|
158 |
heatmap_data = pd.crosstab(inter_conference_df['Conference 1'], inter_conference_df['Conference 2'])
|
159 |
+
|
160 |
+
# Ensuring every conference combination has a value
|
161 |
+
all_conferences = set(conference_team_df['Conference'])
|
162 |
for conf in all_conferences:
|
163 |
if conf not in heatmap_data.columns:
|
164 |
heatmap_data[conf] = 0
|
165 |
if conf not in heatmap_data.index:
|
166 |
heatmap_data.loc[conf] = 0
|
167 |
+
|
168 |
+
heatmap_data = heatmap_data.loc[sorted(all_conferences), sorted(all_conferences)]
|
169 |
+
|
170 |
+
# Plotting the heatmap
|
171 |
plt.figure(figsize=(8, 6))
|
172 |
sns.heatmap(heatmap_data, annot=True, cmap='Oranges', linewidths=.5, cbar_kws={'label': 'Number of Matches'})
|
173 |
plt.title('Inter-Conference Match Analysis')
|
|
|
175 |
plt.xlabel('Conference 2')
|
176 |
plt.show()
|
177 |
|
178 |
+
|
179 |
# Commissioner Analytics
|
180 |
def commissioner_analytics(schedule_df, conference_team_df, commissioners):
|
181 |
# Check if the DataFrame is None
|