Commit
·
6e72f6a
1
Parent(s):
0c6b2bb
feat: add best wins
Browse files
app.py
CHANGED
@@ -137,6 +137,11 @@ def get_most_frequent_opponents(df: pd.DataFrame, top_n: int = 5) -> pd.DataFram
|
|
137 |
["Opponent", "Number of matches", "Win/loss record"]].head(top_n)
|
138 |
|
139 |
|
|
|
|
|
|
|
|
|
|
|
140 |
def get_highest_rated_opponent(df: pd.DataFrame) -> pd.DataFrame:
|
141 |
return df.iloc[df.opponent_rating.idxmax()].to_frame().transpose()
|
142 |
|
@@ -188,6 +193,7 @@ def usatt_rating_analyzer(file_obj):
|
|
188 |
opponent_name_word_cloud_fig = get_opponent_name_word_cloud_fig(df)
|
189 |
competition_name_word_cloud_fig = get_competition_name_word_cloud_fig(df, is_tournament)
|
190 |
most_frequent_opponents = get_most_frequent_opponents(df)
|
|
|
191 |
highest_rated_opponent = get_highest_rated_opponent(df)
|
192 |
rating_over_time_fig = get_rating_over_time_fig(df, is_tournament)
|
193 |
match_with_longest_game = get_match_with_longest_game(df, is_tournament)
|
@@ -200,6 +206,7 @@ def usatt_rating_analyzer(file_obj):
|
|
200 |
opponent_name_word_cloud_fig,
|
201 |
competition_name_word_cloud_fig,
|
202 |
most_frequent_opponents,
|
|
|
203 |
highest_rated_opponent,
|
204 |
rating_over_time_fig,
|
205 |
match_with_longest_game,
|
@@ -248,6 +255,8 @@ with gr.Blocks() as demo:
|
|
248 |
with gr.Row():
|
249 |
with gr.Column():
|
250 |
most_frequent_opponents_gdf = gr.Dataframe(label="Most frequent opponents", max_rows=5)
|
|
|
|
|
251 |
highest_rated_opponent_gdf = gr.Dataframe(label="Best opponent", max_rows=1)
|
252 |
|
253 |
match_longest_game_gdf = gr.Dataframe(label="Match with longest game", max_rows=1)
|
@@ -266,6 +275,7 @@ with gr.Blocks() as demo:
|
|
266 |
opponent_names_plot,
|
267 |
comp_names_plot,
|
268 |
most_frequent_opponents_gdf,
|
|
|
269 |
highest_rated_opponent_gdf,
|
270 |
rating_over_time_plot,
|
271 |
match_longest_game_gdf,
|
|
|
137 |
["Opponent", "Number of matches", "Win/loss record"]].head(top_n)
|
138 |
|
139 |
|
140 |
+
def get_best_wins(df: pd.DataFrame, top_n: int = 5) -> pd.DataFrame:
|
141 |
+
"""Get the top-n wins sorted by opponent rating."""
|
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 |
|
|
|
193 |
opponent_name_word_cloud_fig = get_opponent_name_word_cloud_fig(df)
|
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)
|
|
|
206 |
opponent_name_word_cloud_fig,
|
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,
|
|
|
255 |
with gr.Row():
|
256 |
with gr.Column():
|
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)
|
|
|
275 |
opponent_names_plot,
|
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,
|