James McCool commited on
Commit
b2e149b
·
1 Parent(s): dd69dc6

Added the ability to check portfolio for players not present in projections and adjust them accordingly

Browse files
Files changed (1) hide show
  1. app.py +43 -0
app.py CHANGED
@@ -1747,6 +1747,36 @@ if selected_tab == 'Projections Management':
1747
  # Get the current projections dataframe
1748
  projections_editor_df = st.session_state['projections_df'].copy()
1749
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1750
  # Define column configuration for the data editor
1751
  column_config = {
1752
  'player_names': st.column_config.TextColumn(
@@ -1840,9 +1870,22 @@ if selected_tab == 'Projections Management':
1840
  # Find and update the original projections_df
1841
  orig_idx = st.session_state['projections_df'][st.session_state['projections_df']['player_names'] == player_name].index
1842
  if len(orig_idx) > 0:
 
1843
  st.session_state['projections_df'].loc[orig_idx[0], 'median'] = row['median']
1844
  st.session_state['projections_df'].loc[orig_idx[0], 'ownership'] = row['ownership']
1845
  st.session_state['projections_df'].loc[orig_idx[0], 'captain ownership'] = row['captain ownership']
 
 
 
 
 
 
 
 
 
 
 
 
1846
 
1847
  # Update map_dict entries
1848
  if 'map_dict' in st.session_state:
 
1747
  # Get the current projections dataframe
1748
  projections_editor_df = st.session_state['projections_df'].copy()
1749
 
1750
+ # Check for portfolio players not in projections and add them
1751
+ if 'origin_portfolio' in st.session_state and 'map_dict' in st.session_state:
1752
+ # Get all portfolio player names
1753
+ portfolio_df = pd.read_parquet(io.BytesIO(st.session_state['origin_portfolio']))
1754
+ portfolio_players = set(get_portfolio_names(portfolio_df))
1755
+ projection_players = set(projections_editor_df['player_names'].tolist())
1756
+
1757
+ # Find missing players
1758
+ missing_players = portfolio_players - projection_players
1759
+
1760
+ if missing_players:
1761
+ # Create rows for missing players using map_dict data
1762
+ missing_rows = []
1763
+ for player in missing_players:
1764
+ missing_rows.append({
1765
+ 'player_names': player,
1766
+ 'position': st.session_state['map_dict']['pos_map'].get(player, 'FLEX'),
1767
+ 'team': st.session_state['map_dict']['team_map'].get(player, 'Unknown'),
1768
+ 'salary': st.session_state['map_dict']['salary_map'].get(player, 0),
1769
+ 'median': st.session_state['map_dict']['proj_map'].get(player, 0.0),
1770
+ 'ownership': st.session_state['map_dict']['own_map'].get(player, 0.0),
1771
+ 'captain ownership': st.session_state['map_dict'].get('cpt_own_map', {}).get(player, 0.0)
1772
+ })
1773
+
1774
+ # Add missing players to the editor dataframe
1775
+ missing_df = pd.DataFrame(missing_rows)
1776
+ projections_editor_df = pd.concat([projections_editor_df, missing_df], ignore_index=True)
1777
+
1778
+ st.info(f"📌 Found {len(missing_players)} player(s) in portfolio not in projections. They have been added below with default values.")
1779
+
1780
  # Define column configuration for the data editor
1781
  column_config = {
1782
  'player_names': st.column_config.TextColumn(
 
1870
  # Find and update the original projections_df
1871
  orig_idx = st.session_state['projections_df'][st.session_state['projections_df']['player_names'] == player_name].index
1872
  if len(orig_idx) > 0:
1873
+ # Player exists in projections_df - update existing row
1874
  st.session_state['projections_df'].loc[orig_idx[0], 'median'] = row['median']
1875
  st.session_state['projections_df'].loc[orig_idx[0], 'ownership'] = row['ownership']
1876
  st.session_state['projections_df'].loc[orig_idx[0], 'captain ownership'] = row['captain ownership']
1877
+ else:
1878
+ # Player is new (from portfolio but not in projections) - add new row
1879
+ new_row = pd.DataFrame([{
1880
+ 'player_names': player_name,
1881
+ 'position': row['position'],
1882
+ 'team': row['team'],
1883
+ 'salary': row['salary'],
1884
+ 'median': row['median'],
1885
+ 'ownership': row['ownership'],
1886
+ 'captain ownership': row['captain ownership']
1887
+ }])
1888
+ st.session_state['projections_df'] = pd.concat([st.session_state['projections_df'], new_row], ignore_index=True)
1889
 
1890
  # Update map_dict entries
1891
  if 'map_dict' in st.session_state: