James McCool
commited on
Commit
·
dce062f
1
Parent(s):
439e0ac
Enhance player filtering logic in 'Manage Portfolio' section of 'app.py' by implementing conditional checks for both alpha and beta players, improving the accuracy of row selection based on user-defined criteria.
Browse files
app.py
CHANGED
|
@@ -1775,48 +1775,98 @@ if selected_tab == 'Manage Portfolio':
|
|
| 1775 |
st.session_state['settings_base'] = False
|
| 1776 |
parsed_frame = st.session_state['export_base'].copy()
|
| 1777 |
|
| 1778 |
-
#
|
| 1779 |
if conditional_side_alpha and conditional_side_beta:
|
|
|
|
| 1780 |
alpha_mask = pd.Series([True] * len(parsed_frame), index=parsed_frame.index)
|
| 1781 |
for player in conditional_side_alpha:
|
| 1782 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1783 |
alpha_mask = alpha_mask & player_present
|
| 1784 |
|
| 1785 |
# Only apply beta logic to rows that match alpha condition
|
| 1786 |
rows_to_process = alpha_mask
|
| 1787 |
|
|
|
|
| 1788 |
if conditional_var == 'Any':
|
|
|
|
| 1789 |
beta_mask = pd.Series([False] * len(parsed_frame), index=parsed_frame.index)
|
| 1790 |
for player in conditional_side_beta:
|
| 1791 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1792 |
beta_mask = beta_mask | player_present
|
| 1793 |
elif conditional_var == 'All':
|
|
|
|
| 1794 |
beta_mask = pd.Series([True] * len(parsed_frame), index=parsed_frame.index)
|
| 1795 |
for player in conditional_side_beta:
|
| 1796 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1797 |
beta_mask = beta_mask & player_present
|
| 1798 |
elif conditional_var == 'None':
|
|
|
|
| 1799 |
beta_mask = pd.Series([True] * len(parsed_frame), index=parsed_frame.index)
|
| 1800 |
for player in conditional_side_beta:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1801 |
player_present = parsed_frame.apply(lambda row: player in row.values, axis=1)
|
| 1802 |
beta_mask = beta_mask & (~player_present)
|
| 1803 |
|
|
|
|
| 1804 |
final_condition = rows_to_process & beta_mask
|
| 1805 |
|
|
|
|
| 1806 |
if keep_remove_var == 'Keep':
|
| 1807 |
parsed_frame = parsed_frame[~rows_to_process | final_condition]
|
| 1808 |
-
else:
|
| 1809 |
parsed_frame = parsed_frame[~final_condition]
|
| 1810 |
|
| 1811 |
elif conditional_side_alpha:
|
|
|
|
| 1812 |
alpha_mask = pd.Series([True] * len(parsed_frame), index=parsed_frame.index)
|
| 1813 |
for player in conditional_side_alpha:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1814 |
player_present = parsed_frame.apply(lambda row: player in row.values, axis=1)
|
| 1815 |
alpha_mask = alpha_mask & player_present
|
| 1816 |
|
| 1817 |
if keep_remove_var == 'Keep':
|
| 1818 |
parsed_frame = parsed_frame[alpha_mask]
|
| 1819 |
-
else:
|
| 1820 |
parsed_frame = parsed_frame[~alpha_mask]
|
| 1821 |
|
| 1822 |
st.session_state['export_base'] = parsed_frame.sort_values(by='median', ascending=False).reset_index(drop=True)
|
|
|
|
| 1775 |
st.session_state['settings_base'] = False
|
| 1776 |
parsed_frame = st.session_state['export_base'].copy()
|
| 1777 |
|
| 1778 |
+
# Check if we have players selected for both alpha and beta sides
|
| 1779 |
if conditional_side_alpha and conditional_side_beta:
|
| 1780 |
+
# Create boolean mask for rows containing ALL players from alpha side
|
| 1781 |
alpha_mask = pd.Series([True] * len(parsed_frame), index=parsed_frame.index)
|
| 1782 |
for player in conditional_side_alpha:
|
| 1783 |
+
if type_var == 'Showdown':
|
| 1784 |
+
if cpt_flex_alpha == 'Overall':
|
| 1785 |
+
player_present = parsed_frame.apply(lambda row: player in row.values, axis=1)
|
| 1786 |
+
elif cpt_flex_alpha == 'CPT':
|
| 1787 |
+
player_present = parsed_frame.iloc[:, 0].apply(lambda row: player in row)
|
| 1788 |
+
elif cpt_flex_alpha == 'FLEX':
|
| 1789 |
+
player_present = parsed_frame.iloc[:, 1:].apply(lambda row: player in row.values, axis=1)
|
| 1790 |
+
else:
|
| 1791 |
+
player_present = parsed_frame.apply(lambda row: player in row.values, axis=1)
|
| 1792 |
alpha_mask = alpha_mask & player_present
|
| 1793 |
|
| 1794 |
# Only apply beta logic to rows that match alpha condition
|
| 1795 |
rows_to_process = alpha_mask
|
| 1796 |
|
| 1797 |
+
# For rows that match alpha condition, check beta condition
|
| 1798 |
if conditional_var == 'Any':
|
| 1799 |
+
# Check if row contains ANY of the beta players
|
| 1800 |
beta_mask = pd.Series([False] * len(parsed_frame), index=parsed_frame.index)
|
| 1801 |
for player in conditional_side_beta:
|
| 1802 |
+
if type_var == 'Showdown':
|
| 1803 |
+
if cpt_flex_beta == 'Overall':
|
| 1804 |
+
player_present = parsed_frame.apply(lambda row: player in row.values, axis=1)
|
| 1805 |
+
elif cpt_flex_beta == 'CPT':
|
| 1806 |
+
player_present = parsed_frame.iloc[:, 0].apply(lambda row: player in row)
|
| 1807 |
+
elif cpt_flex_beta == 'FLEX':
|
| 1808 |
+
player_present = parsed_frame.iloc[:, 1:].apply(lambda row: player in row.values, axis=1)
|
| 1809 |
+
else:
|
| 1810 |
+
player_present = parsed_frame.apply(lambda row: player in row.values, axis=1)
|
| 1811 |
beta_mask = beta_mask | player_present
|
| 1812 |
elif conditional_var == 'All':
|
| 1813 |
+
# Check if row contains ALL of the beta players
|
| 1814 |
beta_mask = pd.Series([True] * len(parsed_frame), index=parsed_frame.index)
|
| 1815 |
for player in conditional_side_beta:
|
| 1816 |
+
if type_var == 'Showdown':
|
| 1817 |
+
if cpt_flex_beta == 'Overall':
|
| 1818 |
+
player_present = parsed_frame.apply(lambda row: player in row.values, axis=1)
|
| 1819 |
+
elif cpt_flex_beta == 'CPT':
|
| 1820 |
+
player_present = parsed_frame.iloc[:, 0].apply(lambda row: player in row)
|
| 1821 |
+
elif cpt_flex_beta == 'FLEX':
|
| 1822 |
+
player_present = parsed_frame.iloc[:, 1:].apply(lambda row: player in row.values, axis=1)
|
| 1823 |
+
else:
|
| 1824 |
+
player_present = parsed_frame.apply(lambda row: player in row.values, axis=1)
|
| 1825 |
beta_mask = beta_mask & player_present
|
| 1826 |
elif conditional_var == 'None':
|
| 1827 |
+
# Check if row contains NONE of the beta players
|
| 1828 |
beta_mask = pd.Series([True] * len(parsed_frame), index=parsed_frame.index)
|
| 1829 |
for player in conditional_side_beta:
|
| 1830 |
+
if type_var == 'Showdown':
|
| 1831 |
+
if cpt_flex_beta == 'Overall':
|
| 1832 |
+
player_present = parsed_frame.apply(lambda row: player in row.values, axis=1)
|
| 1833 |
+
elif cpt_flex_beta == 'CPT':
|
| 1834 |
+
player_present = parsed_frame.iloc[:, 0].apply(lambda row: player in row)
|
| 1835 |
+
elif cpt_flex_beta == 'FLEX':
|
| 1836 |
+
player_present = parsed_frame.iloc[:, 1:].apply(lambda row: player in row.values, axis=1)
|
| 1837 |
+
else:
|
| 1838 |
+
player_present = parsed_frame.apply(lambda row: player in row.values, axis=1)
|
| 1839 |
player_present = parsed_frame.apply(lambda row: player in row.values, axis=1)
|
| 1840 |
beta_mask = beta_mask & (~player_present)
|
| 1841 |
|
| 1842 |
+
# Combine conditions: alpha_mask AND beta_mask
|
| 1843 |
final_condition = rows_to_process & beta_mask
|
| 1844 |
|
| 1845 |
+
# Apply keep or remove logic
|
| 1846 |
if keep_remove_var == 'Keep':
|
| 1847 |
parsed_frame = parsed_frame[~rows_to_process | final_condition]
|
| 1848 |
+
else: # Remove
|
| 1849 |
parsed_frame = parsed_frame[~final_condition]
|
| 1850 |
|
| 1851 |
elif conditional_side_alpha:
|
| 1852 |
+
# Only alpha side specified - filter based on presence of alpha players
|
| 1853 |
alpha_mask = pd.Series([True] * len(parsed_frame), index=parsed_frame.index)
|
| 1854 |
for player in conditional_side_alpha:
|
| 1855 |
+
if type_var == 'Showdown':
|
| 1856 |
+
if cpt_flex_alpha == 'Overall':
|
| 1857 |
+
player_present = parsed_frame.apply(lambda row: player in row.values, axis=1)
|
| 1858 |
+
elif cpt_flex_alpha == 'CPT':
|
| 1859 |
+
player_present = parsed_frame.iloc[:, 0].apply(lambda row: player in row)
|
| 1860 |
+
elif cpt_flex_alpha == 'FLEX':
|
| 1861 |
+
player_present = parsed_frame.iloc[:, 1:].apply(lambda row: player in row.values, axis=1)
|
| 1862 |
+
else:
|
| 1863 |
+
player_present = parsed_frame.apply(lambda row: player in row.values, axis=1)
|
| 1864 |
player_present = parsed_frame.apply(lambda row: player in row.values, axis=1)
|
| 1865 |
alpha_mask = alpha_mask & player_present
|
| 1866 |
|
| 1867 |
if keep_remove_var == 'Keep':
|
| 1868 |
parsed_frame = parsed_frame[alpha_mask]
|
| 1869 |
+
else: # Remove
|
| 1870 |
parsed_frame = parsed_frame[~alpha_mask]
|
| 1871 |
|
| 1872 |
st.session_state['export_base'] = parsed_frame.sort_values(by='median', ascending=False).reset_index(drop=True)
|