Commit
·
7c475e4
1
Parent(s):
c56ec13
Update match_parser.py
Browse files- match_parser.py +21 -1
match_parser.py
CHANGED
|
@@ -10,7 +10,7 @@ import seaborn as sns
|
|
| 10 |
from bs4 import BeautifulSoup
|
| 11 |
from wordcloud import WordCloud
|
| 12 |
|
| 13 |
-
from util import get_max_abs_int, snake_case_to_human_readable
|
| 14 |
|
| 15 |
|
| 16 |
def _rename_columns(df: pd.DataFrame, is_tournament: bool) -> pd.DataFrame:
|
|
@@ -308,6 +308,26 @@ def get_opponent_rating_dist_over_time_fig(df: pd.DataFrame, is_tournament: bool
|
|
| 308 |
return fig
|
| 309 |
|
| 310 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 311 |
def load_match_df(file_path: Path) -> Tuple[pd.DataFrame, bool]:
|
| 312 |
match_type = _check_match_type(file_path.name.split('_')[0])
|
| 313 |
is_tournament = match_type == "tournament"
|
|
|
|
| 10 |
from bs4 import BeautifulSoup
|
| 11 |
from wordcloud import WordCloud
|
| 12 |
|
| 13 |
+
from util import get_max_abs_int, snake_case_to_human_readable, int_csv_to_list
|
| 14 |
|
| 15 |
|
| 16 |
def _rename_columns(df: pd.DataFrame, is_tournament: bool) -> pd.DataFrame:
|
|
|
|
| 308 |
return fig
|
| 309 |
|
| 310 |
|
| 311 |
+
def get_total_match_points(score_str: str) -> int:
|
| 312 |
+
single_game_scores = int_csv_to_list(score_str)
|
| 313 |
+
total_points = 0
|
| 314 |
+
for single_game_score in single_game_scores:
|
| 315 |
+
abs_gscore = abs(single_game_score)
|
| 316 |
+
if abs_gscore < 10:
|
| 317 |
+
total_points += abs_gscore + 11
|
| 318 |
+
else:
|
| 319 |
+
total_points += 2 * abs_gscore + 2
|
| 320 |
+
return total_points
|
| 321 |
+
|
| 322 |
+
def get_longest_match(df: pd.DataFrame, is_tournament: bool) -> Optional[pd.DataFrame]:
|
| 323 |
+
"""Get the longest match, where longest is defined as the most number of points played."""
|
| 324 |
+
if not is_tournament:
|
| 325 |
+
return None
|
| 326 |
+
df_non_null = df.loc[~df.scores.isna()]
|
| 327 |
+
df_non_null["total_points"] = df_non_null.scores.apply(get_total_match_points)
|
| 328 |
+
return df_non_null.iloc[[df_non_null["total_points"].argmax()]]
|
| 329 |
+
|
| 330 |
+
|
| 331 |
def load_match_df(file_path: Path) -> Tuple[pd.DataFrame, bool]:
|
| 332 |
match_type = _check_match_type(file_path.name.split('_')[0])
|
| 333 |
is_tournament = match_type == "tournament"
|