enhanced
This commit is contained in:
+19
-14
@@ -1,20 +1,25 @@
|
||||
from constants import PLAYER_NAME_COLUMNS
|
||||
from constants import PLAYER_NAME_COLUMNS, ordinal
|
||||
|
||||
|
||||
def generate_player_table(df):
|
||||
header = [["Name", "Appearances", "Spent"]]
|
||||
header = [["Player", "Appearances", "Avg. Relative Percentile", "Spent"]]
|
||||
|
||||
player_stats = []
|
||||
for name in PLAYER_NAME_COLUMNS:
|
||||
if name in df.columns:
|
||||
attended = df[df[name] == 1]
|
||||
n = len(attended)
|
||||
if n > 0:
|
||||
avg_rel = attended["Relative Position"].mean()
|
||||
player_stats.append((name, n, avg_rel))
|
||||
|
||||
player_stats = [
|
||||
(name, df[name].sum())
|
||||
for name in df.columns
|
||||
if name in PLAYER_NAME_COLUMNS
|
||||
]
|
||||
player_stats.sort(key=lambda x: x[1], reverse=True)
|
||||
total = sum(n for name, n in player_stats)
|
||||
body = [
|
||||
[name, n, f"£{n * 3:.2f}"]
|
||||
for name, n in player_stats
|
||||
]
|
||||
footer = [["Total", total, f"£{total * 3:.2f}"]]
|
||||
total = sum(n for _, n, _ in player_stats)
|
||||
|
||||
return (header + body + footer)
|
||||
body = [
|
||||
[name, n, ordinal(round(avg_rel * 100)), f"£{n * 3:.2f}"]
|
||||
for name, n, avg_rel in player_stats
|
||||
]
|
||||
footer = [["Total", total, "—", f"£{total * 3:.2f}"]]
|
||||
|
||||
return header + body + footer
|
||||
|
||||
Reference in New Issue
Block a user