updated usage and docstring

This commit is contained in:
jake-fawcett 2023-10-28 20:00:02 +01:00
parent db51b113d4
commit c30eab644c
2 changed files with 34 additions and 11 deletions

View File

@ -1,4 +1,9 @@
# football-manager-squad-and-recruitment
Python code to evaluate Squad and Scouted Players in Football Manager. Work in progress.
# Football Manager player role evaluation
Python code to evaluate Player attributes in Football Manager against roles based on role weightings. Work in progress.
Inspired by squirrel_plays_FOF's video [FM24 player recruitment using python](https://www.youtube.com/watch?v=hnAuOakqR90)
## Usage
```
python3 position_score_calculator.py --input-filepath "squad.html" --output-filepath "squad_output.html" --roles goalkeeper fullback
```

View File

@ -2,7 +2,7 @@ import pandas as pd
import argparse
# Define Player attributes
# TODO: Add roles.
goalkeeper = {
"role_name": "goalkeeper",
"primary_multiplier": 5,
@ -13,6 +13,16 @@ goalkeeper = {
"tertiary_attributes": ["Acc", "Aer", "Cmp", "Dec", "Fir", "Han", "Pas", "Thr", "Vis"]
}
fullback = {
"role_name": "fullback",
"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"]
}
def load_html_data_to_dataframe(filepath: str) -> pd.DataFrame:
"""Read HTML file exported by FM into a Dataframe
@ -98,20 +108,28 @@ def calc_role_scores(player_df: pd.DataFrame, role: dict) -> pd.DataFrame:
player_df[f'{role["role_name"]}'] = round((((player_df[f'{role["role_name"]}_primary'] * 5) + (player_df[f'{role["role_name"]}_secondary'] * 3) + (player_df[f'{role["role_name"]}_tertiary'] * 1)) / divisor ), 2)
return player_df
def calc_player_scores(player_df: pd.DataFrame):
# TODO: Create objects for each role that can be used here.
player_df = calc_role_scores(player_df, goalkeeper)
# TODO: Add roles.
def calc_role_scores_for_tactic_roles(player_df: pd.DataFrame, tactic_roles: [dict]):
for role in tactic_roles:
player_df = calc_role_scores(player_df, role)
return player_df
if __name__ == "__main__":
# Parse Input args
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input-filepath", type=str)
parser.add_argument("-o", "--output-filepath", type=str)
parser.add_argument("-i", "--input-filepath", type=str, help="Path to Input Html file")
parser.add_argument("-o", "--output-filepath", type=str, help="Path to Export resultant Html file")
parser.add_argument("-r", "--roles", nargs='+', type=str, help="Space seperated list of roles for Evaluation")
args = parser.parse_args()
input_filepath = args.input_filepath
output_filepath = args.output_filepath
roles = args.roles
# Take Role arg and convert to list of role dictionaries
tactic_roles = []
for role in roles:
tactic_roles.append(globals()[role])
# Inport data, calculate scores for role, export results as html
player_df = load_html_data_to_dataframe(input_filepath)
player_df = calc_player_scores(player_df)
player_df = calc_role_scores_for_tactic_roles(player_df, tactic_roles)
export_html_from_dataframe(player_df, output_filepath)