import pandas as pd
import argparse
# Define Player attributes
# TODO: Add roles.
gk = {
"role_name": "gk",
"primary_multiplier": 5,
"primary_attributes": ["Agi", "Ref"],
"secondary_multiplier": 3,
"secondary_attributes": ["1v1", "Ant", "Cmd", "Cnt", "Kic", "Pos"],
"tertiary_multiplier": 1,
"tertiary_attributes": ["Acc", "Aer", "Cmp", "Dec", "Fir", "Han", "Pas", "Thr", "Vis"]
}
fb = {
"role_name": "fb",
"primary_multiplier": 5,
"primary_attributes": ["Wor", "Acc", "Pac", "Sta"],
"secondary_multiplier": 3,
"secondary_attributes": ["Cro", "Dri", "Mar", "OtB", "Tck", "Tea"],
"tertiary_multiplier": 1,
"tertiary_attributes": ["Agi", "Ant", "Cnt", "Dec", "Fir", "Pas", "Pos", "Tec"]
}
cd = {
"role_name": "cd",
"primary_multiplier": 3,
"primary_attributes": ["Cmp", "Hea", "Jum", "Mar", "Pas", "Pos", "Str", "Tck", "Pac"],
"secondary_multiplier": 1,
"secondary_attributes": ["Agg", "Ant", "Bra", "Cnt", "Dec", "Fir", "Tec", "Vis"]
}
dm = {
"role_name": "dm",
"primary_multiplier": 5,
"primary_attributes": ["Wor", "Pac", "Sta", "Pas"],
"secondary_multiplier": 3,
"secondary_attributes": ["Tck", "Ant", "Cnt", "Pos", "Bal", "Agi"],
"tertiary_multiplier": 1,
"tertiary_attributes": ["Tea", "Fir", "Mar", "Agg", "Cmp", "Dec", "Str"]
}
b2b = {
"role_name": "b2b",
"primary_multiplier": 5,
"primary_attributes": ["Pas", "Wor", "Sta"],
"secondary_multiplier": 3,
"secondary_attributes": ["Tck", "OtB", "Tea", "Vis", "Str", "Dec", "Pos", "Pac"],
"tertiary_multiplier": 1,
"tertiary_attributes": ["Agg", "Ant", "Fin", "Lon", "Cmp", "Acc", "Bal", "Fir", "Dri", "Tec"]
}
w = {
"role_name": "w",
"primary_multiplier": 3,
"primary_attributes": ["Acc", "Cro", "Dri", "OtB", "Pac", "Tec"],
"secondary_multiplier": 1,
"secondary_attributes": ["Agi", "Fir", "Pas", "Sta", "Wor"],
}
iw = {
"role_name": "iw",
"primary_multiplier": 5,
"primary_attributes": ["Acc", "Pac", "Wor"],
"secondary_multiplier": 3,
"secondary_attributes": ["Dri", "Pas", "Tec", "OtB"],
"tertiary_multiplier": 1,
"tertiary_attributes": ["Cro", "Fir", "Cmp", "Dec", "Vis", "Agi", "Sta"]
}
def load_html_data_to_dataframe(filepath: str) -> pd.DataFrame:
"""Read HTML file exported by FM into a Dataframe
Keyword arguments:
filepath -- path to fm player html file
"""
player_df = pd.read_html(filepath, header=0, encoding="utf-8", keep_default_na=False)[0]
# Clean Dataframe to get rid of unknown values and ability ranges (takes the lowest value)
# This casts to a string to be able to split, so we have to cast back to an int later.
player_df = player_df.replace("-", 0)
player_df = player_df.map(lambda x: str(x).split("-")[0])
return player_df
def export_html_from_dataframe(player_df: pd.DataFrame, filepath: str) -> str:
"""Export Dataframe as html with jQuery Data Tables
Taken from: https://www.thepythoncode.com/article/convert-pandas-dataframe-to-html-table-python.
Keyword arguments:
filepath -- path to fm player html file
"""
table_html = player_df.to_html(table_id="table", index=False)
html = f"""