James McCool commited on
Commit
f51c772
·
1 Parent(s): 977b318

Refactor predict_dupes function call in app.py to use parsed_frame and salary_max, and add reassess_edge function in reassess_edge.py for recalculating metrics based on differences in salary, median, and ownership.

Browse files
Files changed (2) hide show
  1. app.py +1 -1
  2. global_func/reassess_edge.py +40 -0
app.py CHANGED
@@ -1434,7 +1434,7 @@ with tab2:
1434
  st.session_state['working_frame']['salary'] = st.session_state['working_frame']['salary'].astype('uint16')
1435
 
1436
  print(st.session_state['working_frame'].head(10))
1437
- st.session_state['working_frame'] = predict_dupes(st.session_state['working_frame'], st.session_state['map_dict'], site_var, type_var, Contest_Size, strength_var, sport_var)
1438
  st.session_state['export_merge'] = st.session_state['working_frame'].copy()
1439
  elif exp_submitted:
1440
  st.session_state['settings_base'] = False
 
1434
  st.session_state['working_frame']['salary'] = st.session_state['working_frame']['salary'].astype('uint16')
1435
 
1436
  print(st.session_state['working_frame'].head(10))
1437
+ st.session_state['working_frame'] = predict_dupes(parsed_frame, st.session_state['working_frame'], salary_max)
1438
  st.session_state['export_merge'] = st.session_state['working_frame'].copy()
1439
  elif exp_submitted:
1440
  st.session_state['settings_base'] = False
global_func/reassess_edge.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Rerunning the predict_dupes.py function on a small portfolio after running exposure_spread.py breaks the metrics
2
+ # 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
3
+ # 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
4
+ # Need to find the diff in salary, median, and Own to calculate new Dupes, finish_percentile, Win%, Edge, Weighted Own, and Geomean
5
+ # Then at the end run the Diveristy function to set a new column for Diversity
6
+ # 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
7
+
8
+ import pandas as pd
9
+ import numpy as np
10
+ import math
11
+
12
+ def reassess_dupes(row: pd.Series, salary_max: int) -> float:
13
+ if row['salary'] == salary_max:
14
+ return math.ceil(row['Dupes'] + ((row['salary_diff'] / 100) * (row['own_diff'] / 100))).clip(lower=0)
15
+ elif row['salary'] != salary_max:
16
+ return math.ceil(row['Dupes'] + ((row['salary_diff'] / 100) * (row['own_diff'] / 100))).clip(lower=0)
17
+ else:
18
+ return row['Dupes']
19
+
20
+ 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:
21
+ orig_df = original_frame.copy()
22
+ orig_df = orig_df.reset_index(drop=True)
23
+ refactored_df = refactored_frame.copy()
24
+ refactored_df = refactored_df.reset_index(drop=True)
25
+
26
+ refactored_df['salary_diff'] = refactored_df['salary'] - orig_df['salary']
27
+ refactored_df['median_diff'] = refactored_df['median'] - orig_df['median']
28
+ refactored_df['own_diff'] = refactored_df['Own'] - orig_df['Own']
29
+
30
+ change_mask = refactored_df[refactored_df['salary_diff'] != 0 | refactored_df['median_diff'] != 0 | refactored_df['own_diff'] != 0]
31
+
32
+ for lineups in change_mask.index:
33
+ refactored_df.loc[lineups, 'Dupes'] = reassess_dupes(refactored_df.loc[lineups, :], salary_max)
34
+ refactored_df.loc[lineups, 'Finish_percentile'] = refactored_df.loc[lineups, 'Finish_percentile'] + 1
35
+ refactored_df.loc[lineups, 'Win%'] = refactored_df.loc[lineups, 'Win%'] + 1
36
+ refactored_df.loc[lineups, 'Edge'] = refactored_df.loc[lineups, 'Edge'] + 1
37
+ refactored_df.loc[lineups, 'Weighted Own'] = refactored_df.loc[lineups, 'Weighted Own'] + 1
38
+ refactored_df.loc[lineups, 'Geomean'] = refactored_df.loc[lineups, 'Geomean'] + 1
39
+
40
+ return refactored_df