Skip to content

Commit

Permalink
sum of xG & xA is called xGI
Browse files Browse the repository at this point in the history
  • Loading branch information
razn committed Sep 7, 2024
1 parent 514cf13 commit f104f11
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
4 changes: 2 additions & 2 deletions analysis_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
20 changes: 11 additions & 9 deletions custom/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
)
)
Expand All @@ -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"]
Expand All @@ -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"]]
Expand Down
2 changes: 1 addition & 1 deletion tests/test_players.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f104f11

Please sign in to comment.