# Rerunning the predict_dupes.py function on a small portfolio after running exposure_spread.py breaks the metrics # This is because the preeict_dupes.py function is exclusive of the lineups it takes it, and is meant to give edge around the median expectation of those lineups # So what we need to do instead is find the differences across the original set and the post-exposure_spread.py set and calculate new metrics around the diff # Need to find the diff in salary, median, and Own to calculate new Dupes, finish_percentile, Win%, Edge, Weighted Own, and Geomean # Then at the end run the Diveristy function to set a new column for Diversity # This way we only make the changes to the metrics where we have a difference in salary, median, and Own and leave the rest of the lineups alone import pandas as pd import numpy as np import math def reassess_dupes(row: pd.Series, salary_max: int) -> float: return math.ceil(row['Dupes'] + ((row['salary_diff'] / 100) + ((salary_max + (salary_max - row['salary'])) / 100)) * (1 - (row['own_diff'] / 100))).clip(lower=0) def reassess_edge(refactored_frame: pd.DataFrame, original_frame: pd.DataFrame, maps_dict: dict, site_var: str, type_var: str, Contest_Size: int, strength_var: str, sport_var: str, salary_max: int) -> pd.DataFrame: orig_df = original_frame.copy() orig_df = orig_df.reset_index(drop=True) refactored_df = refactored_frame.copy() refactored_df = refactored_df.reset_index(drop=True) refactored_df['salary_diff'] = refactored_df['salary'] - orig_df['salary'] refactored_df['median_diff'] = refactored_df['median'] - orig_df['median'] refactored_df['own_diff'] = refactored_df['Own'] - orig_df['Own'] change_mask = refactored_df[refactored_df['salary_diff'] != 0 | refactored_df['median_diff'] != 0 | refactored_df['own_diff'] != 0] for lineups in change_mask.index: refactored_df.loc[lineups, 'Dupes'] = reassess_dupes(refactored_df.loc[lineups, :], salary_max) refactored_df.loc[lineups, 'Finish_percentile'] = refactored_df.loc[lineups, 'Finish_percentile'] + 1 refactored_df.loc[lineups, 'Win%'] = refactored_df.loc[lineups, 'Win%'] + 1 refactored_df.loc[lineups, 'Edge'] = refactored_df.loc[lineups, 'Edge'] + 1 refactored_df.loc[lineups, 'Weighted Own'] = refactored_df.loc[lineups, 'Weighted Own'] + 1 refactored_df.loc[lineups, 'Geomean'] = refactored_df.loc[lineups, 'Geomean'] + 1 return refactored_df