Commit ·
906d634
1
Parent(s): 148d5c7
Update match_parser.py
Browse files- match_parser.py +13 -0
match_parser.py
CHANGED
|
@@ -219,6 +219,19 @@ def get_biggest_upsets(df: pd.DataFrame, top_n: int = 5) -> pd.DataFrame:
|
|
| 219 |
return df.loc[df.result == 'Won'].sort_values("rating_difference", ascending=False).head(top_n)
|
| 220 |
|
| 221 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
def get_best_competitions(df: pd.DataFrame, is_tournament: bool, top_n: int = 5) -> pd.DataFrame:
|
| 223 |
# First add pre-competition ratings
|
| 224 |
x_key_name = "tournament_end_date" if is_tournament else "event_date"
|
|
|
|
| 219 |
return df.loc[df.result == 'Won'].sort_values("rating_difference", ascending=False).head(top_n)
|
| 220 |
|
| 221 |
|
| 222 |
+
def get_worst_recent_losses(df: pd.DataFrame,
|
| 223 |
+
is_tournament: bool,
|
| 224 |
+
top_k_losses: int = 5,
|
| 225 |
+
top_n_comps: int = 5) -> pd.DataFrame:
|
| 226 |
+
"""Get the top-k most recent worst losses from the top-n most recent competitions."""
|
| 227 |
+
x_key_name = "tournament_end_date" if is_tournament else "event_date"
|
| 228 |
+
most_recent_competition_dates =df.groupby(x_key_name).first().reset_index().nlargest(top_n_comps,
|
| 229 |
+
columns=x_key_name)[x_key_name]
|
| 230 |
+
df_recent = df.loc[df[x_key_name].isin(most_recent_competition_dates)]
|
| 231 |
+
df_recent['rating_difference'] = df_recent['opponent_rating'] - df_recent['rating']
|
| 232 |
+
return df_recent.loc[df_recent.result == 'Lost'].sort_values("rating_difference", ascending=True).head(top_k_losses)
|
| 233 |
+
|
| 234 |
+
|
| 235 |
def get_best_competitions(df: pd.DataFrame, is_tournament: bool, top_n: int = 5) -> pd.DataFrame:
|
| 236 |
# First add pre-competition ratings
|
| 237 |
x_key_name = "tournament_end_date" if is_tournament else "event_date"
|