Commit
·
a4a6839
1
Parent(s):
6e72f6a
feat: add biggest upsets
Browse files
app.py
CHANGED
@@ -142,6 +142,12 @@ def get_best_wins(df: pd.DataFrame, top_n: int = 5) -> pd.DataFrame:
|
|
142 |
return df.loc[df.result == 'Won'].sort_values("opponent_rating", ascending=False).head(top_n)
|
143 |
|
144 |
|
|
|
|
|
|
|
|
|
|
|
|
|
145 |
def get_highest_rated_opponent(df: pd.DataFrame) -> pd.DataFrame:
|
146 |
return df.iloc[df.opponent_rating.idxmax()].to_frame().transpose()
|
147 |
|
@@ -194,6 +200,7 @@ def usatt_rating_analyzer(file_obj):
|
|
194 |
competition_name_word_cloud_fig = get_competition_name_word_cloud_fig(df, is_tournament)
|
195 |
most_frequent_opponents = get_most_frequent_opponents(df)
|
196 |
best_wins = get_best_wins(df)
|
|
|
197 |
highest_rated_opponent = get_highest_rated_opponent(df)
|
198 |
rating_over_time_fig = get_rating_over_time_fig(df, is_tournament)
|
199 |
match_with_longest_game = get_match_with_longest_game(df, is_tournament)
|
@@ -207,6 +214,7 @@ def usatt_rating_analyzer(file_obj):
|
|
207 |
competition_name_word_cloud_fig,
|
208 |
most_frequent_opponents,
|
209 |
best_wins,
|
|
|
210 |
highest_rated_opponent,
|
211 |
rating_over_time_fig,
|
212 |
match_with_longest_game,
|
@@ -257,6 +265,8 @@ with gr.Blocks() as demo:
|
|
257 |
most_frequent_opponents_gdf = gr.Dataframe(label="Most frequent opponents", max_rows=5)
|
258 |
best_wins_gdf = gr.Dataframe(label="Best wins (matches won sorted by opponent post-competition rating)",
|
259 |
max_rows=5)
|
|
|
|
|
260 |
highest_rated_opponent_gdf = gr.Dataframe(label="Best opponent", max_rows=1)
|
261 |
|
262 |
match_longest_game_gdf = gr.Dataframe(label="Match with longest game", max_rows=1)
|
@@ -276,6 +286,7 @@ with gr.Blocks() as demo:
|
|
276 |
comp_names_plot,
|
277 |
most_frequent_opponents_gdf,
|
278 |
best_wins_gdf,
|
|
|
279 |
highest_rated_opponent_gdf,
|
280 |
rating_over_time_plot,
|
281 |
match_longest_game_gdf,
|
|
|
142 |
return df.loc[df.result == 'Won'].sort_values("opponent_rating", ascending=False).head(top_n)
|
143 |
|
144 |
|
145 |
+
def get_biggest_upsets(df: pd.DataFrame, top_n: int = 5) -> pd.DataFrame:
|
146 |
+
"""Get the top-n wins sorted by rating difference."""
|
147 |
+
df['rating_difference'] = df['opponent_rating'] - df['rating']
|
148 |
+
return df.loc[df.result == 'Won'].sort_values("rating_difference", ascending=False).head(top_n)
|
149 |
+
|
150 |
+
|
151 |
def get_highest_rated_opponent(df: pd.DataFrame) -> pd.DataFrame:
|
152 |
return df.iloc[df.opponent_rating.idxmax()].to_frame().transpose()
|
153 |
|
|
|
200 |
competition_name_word_cloud_fig = get_competition_name_word_cloud_fig(df, is_tournament)
|
201 |
most_frequent_opponents = get_most_frequent_opponents(df)
|
202 |
best_wins = get_best_wins(df)
|
203 |
+
biggest_upsets = get_biggest_upsets(df)
|
204 |
highest_rated_opponent = get_highest_rated_opponent(df)
|
205 |
rating_over_time_fig = get_rating_over_time_fig(df, is_tournament)
|
206 |
match_with_longest_game = get_match_with_longest_game(df, is_tournament)
|
|
|
214 |
competition_name_word_cloud_fig,
|
215 |
most_frequent_opponents,
|
216 |
best_wins,
|
217 |
+
biggest_upsets,
|
218 |
highest_rated_opponent,
|
219 |
rating_over_time_fig,
|
220 |
match_with_longest_game,
|
|
|
265 |
most_frequent_opponents_gdf = gr.Dataframe(label="Most frequent opponents", max_rows=5)
|
266 |
best_wins_gdf = gr.Dataframe(label="Best wins (matches won sorted by opponent post-competition rating)",
|
267 |
max_rows=5)
|
268 |
+
biggest_upsets_gdf = gr.Dataframe(label="Biggest upsets (matches won sorted by rating - opponent post-competition rating)",
|
269 |
+
max_rows=5)
|
270 |
highest_rated_opponent_gdf = gr.Dataframe(label="Best opponent", max_rows=1)
|
271 |
|
272 |
match_longest_game_gdf = gr.Dataframe(label="Match with longest game", max_rows=1)
|
|
|
286 |
comp_names_plot,
|
287 |
most_frequent_opponents_gdf,
|
288 |
best_wins_gdf,
|
289 |
+
biggest_upsets_gdf,
|
290 |
highest_rated_opponent_gdf,
|
291 |
rating_over_time_plot,
|
292 |
match_longest_game_gdf,
|