Skip to content

Commit

Permalink
add experimental weighted value for each player
Browse files Browse the repository at this point in the history
  • Loading branch information
razn committed Aug 20, 2024
1 parent 0a5c79f commit 301b449
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions custom/players.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ def builder(self, ownership, tqdm_desc):
"status": status,
"team_short_name": teams[player["team"]]["short_name"],
"pos": pos,
"latest_price": f"£{latest_price}",
"price_change": f"£{price_change}",
"xg": player["expected_goals"],
"xa": player["expected_assists"],
"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"]),
"pts_prev_n_gw": pts_prev_n_gw,
Expand All @@ -133,6 +133,14 @@ def builder(self, ownership, tqdm_desc):
"fdr_avg": round(fdr_sum / total_games, 1),
}

# this is an experimental feature
xg_weightage = 0.3
xa_weightage = 0.25
perf_weightage = 0.2
fda_weightage = 0.15
price_weightage = 0.1
stats[fpl_id]["weighted_value"] = round((stats[fpl_id]["xg"] * xg_weightage) + (stats[fpl_id]["xa"] * xa_weightage) + (stats[fpl_id]["total_pts_prev_n_gw"] * perf_weightage) + (1 / stats[fpl_id]["fdr_avg"] * fda_weightage) + (1 / stats[fpl_id]["latest_price"] * price_weightage), 1)

if ownership is not None:
stats[fpl_id]["ownership"] = f"{ownership[fpl_id]}%"
self.stats = stats
Expand Down Expand Up @@ -183,6 +191,7 @@ def get_table(self, top=None):
+ [f"GW{Gameweek.NEXT_GW} xP"]
+ [f"GW{gw} Fxt" for gw in Gameweek.NEXT_N_GWS]
+ ["FDA"]
+ ["Value"]
)
if "ownership" in list(dict(islice(self.stats.items(), 1)).values())[0]:
header.append("Top 10k Ownership")
Expand All @@ -194,7 +203,7 @@ def get_table(self, top=None):
f'{v["web_name"]} {v["status"]}',
v["team_short_name"],
v["pos"],
v["latest_price"],
f'£{v["latest_price"]}',
v["xg"],
v["xa"],
]
Expand All @@ -205,6 +214,7 @@ def get_table(self, top=None):
for fixture in list(v["fixtures"].values()):
row.append("\n".join(fixture))
row.append(v["fdr_avg"])
row.append(v["weighted_value"])
if "ownership" in list(dict(islice(self.stats.items(), 1)).values())[0]:
row.append(v["ownership"])
table.add_row(row)
Expand Down

0 comments on commit 301b449

Please sign in to comment.