From f104f11772adf2b9447db4fa83ac17c84042f457 Mon Sep 17 00:00:00 2001 From: razn Date: Sat, 7 Sep 2024 17:29:55 +0800 Subject: [PATCH] sum of xG & xA is called xGI --- analysis_team.py | 4 ++-- custom/players.py | 20 +++++++++++--------- tests/test_players.py | 2 +- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/analysis_team.py b/analysis_team.py index 0625616..39b2547 100644 --- a/analysis_team.py +++ b/analysis_team.py @@ -34,8 +34,8 @@ f.write("\n\nWatchlist (Fixture):\n") f.write(fda.get_table(top=10)) - not_user_players.sort_by_sum_xg_xa() - f.write("\n\nWatchlist (xG + xA):\n") + not_user_players.sort_by_xgi() + f.write("\n\nWatchlist (xGI):\n") f.write(not_user_players.get_table(top=10)) not_user_players.sort_by_xpts() diff --git a/custom/players.py b/custom/players.py index 70946e6..841e568 100644 --- a/custom/players.py +++ b/custom/players.py @@ -66,6 +66,10 @@ def builder(self, ownership, tqdm_desc): except IndexError: pass + xg = float(player["expected_goals"]) + xa = float(player["expected_assists"]) + xgi = round(xg + xa, 2) + history = player["history"] rounds = [i["round"] for i in history] pts_prev_n_gw = {} @@ -126,10 +130,9 @@ def builder(self, ownership, tqdm_desc): "pos": pos, "latest_price": latest_price, "price_change": price_change, - "xg": float(player["expected_goals"]), - "xa": float(player["expected_assists"]), - "sum_xg_xa": float(player["expected_goals"]) - + float(player["expected_assists"]), + "xg": xg, + "xa": xa, + "xgi": xgi, "pts_prev_n_gw": pts_prev_n_gw, "total_pts_prev_n_gw": total_pts_prev_n_gw, "ep_this": ep_this, @@ -178,11 +181,11 @@ def sort_by_fda(self): self.sort_by_total_pts_prev_n_gw() self.stats = {k: v for k, v in self.stats.items() if v["fdr_avg"] <= 2.8} - def sort_by_sum_xg_xa(self): + def sort_by_xgi(self): self.stats = OrderedDict( sorted( self.stats.items(), - key=lambda x: getitem(x[1], "sum_xg_xa"), + key=lambda x: getitem(x[1], "xgi"), reverse=True, ) ) @@ -197,7 +200,7 @@ def sort_by_xpts(self): def get_table(self, top=None): table = PrettyTable() header = ( - ["Name", "Team", "Pos", "Price", "xG", "xA"] + ["Name", "Team", "Pos", "Price", "xGI"] + [f"GW{gw} Pts" for gw in Gameweek.PREV_N_GWS] + ["Σ Pts"] + [f"GW{Gameweek.NEXT_GW} xP"] @@ -216,8 +219,7 @@ def get_table(self, top=None): v["team_short_name"], v["pos"], f'£{v["latest_price"]}', - v["xg"], - v["xa"], + v["xgi"], ] + list(v["pts_prev_n_gw"].values()) + [v["total_pts_prev_n_gw"], v["ep_next"]] diff --git a/tests/test_players.py b/tests/test_players.py index 1f0a1e2..aace416 100644 --- a/tests/test_players.py +++ b/tests/test_players.py @@ -85,7 +85,7 @@ async def mock_get_players(self): "price_change": 0.0, "xg": 0.52, "xa": 0.76, - "sum_xg_xa": 1.28, + "xgi": 1.28, "pts_prev_n_gw": {5: 3, 6: 2}, "total_pts_prev_n_gw": 5, "ep_this": 2.7,