James McCool
commited on
Commit
·
4f8d205
1
Parent(s):
703a937
Add 'Trim Portfolio' button in app.py and implement trim_portfolio function in new global_func/trim_portfolio.py
Browse files- app.py +3 -0
- global_func/trim_portfolio.py +12 -0
app.py
CHANGED
@@ -15,6 +15,7 @@ from global_func.predict_dupes import predict_dupes
|
|
15 |
from global_func.highlight_rows import highlight_changes, highlight_changes_winners, highlight_changes_losers
|
16 |
from global_func.load_csv import load_csv
|
17 |
from global_func.find_csv_mismatches import find_csv_mismatches
|
|
|
18 |
|
19 |
freq_format = {'Finish_percentile': '{:.2%}', 'Lineup Edge': '{:.2%}', 'Win%': '{:.2%}'}
|
20 |
player_wrong_names_mlb = ['Enrique Hernandez']
|
@@ -779,6 +780,8 @@ with tab3:
|
|
779 |
)
|
780 |
|
781 |
col1, col2 = st.columns([1, 10])
|
|
|
|
|
782 |
with col1:
|
783 |
with st.form(key='filter_form'):
|
784 |
max_dupes = st.number_input("Max acceptable dupes?", value=1000, min_value=1, step=1)
|
|
|
15 |
from global_func.highlight_rows import highlight_changes, highlight_changes_winners, highlight_changes_losers
|
16 |
from global_func.load_csv import load_csv
|
17 |
from global_func.find_csv_mismatches import find_csv_mismatches
|
18 |
+
from global_func.trim_portfolio import trim_portfolio
|
19 |
|
20 |
freq_format = {'Finish_percentile': '{:.2%}', 'Lineup Edge': '{:.2%}', 'Win%': '{:.2%}'}
|
21 |
player_wrong_names_mlb = ['Enrique Hernandez']
|
|
|
780 |
)
|
781 |
|
782 |
col1, col2 = st.columns([1, 10])
|
783 |
+
if st.button('Trim Portfolio'):
|
784 |
+
st.session_state['portfolio'] = trim_portfolio(st.session_state['portfolio'], 'median', 'Own')
|
785 |
with col1:
|
786 |
with st.form(key='filter_form'):
|
787 |
max_dupes = st.number_input("Max acceptable dupes?", value=1000, min_value=1, step=1)
|
global_func/trim_portfolio.py
ADDED
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
def trim_portfolio(portfolio, performance_type, own_type):
|
2 |
+
working_portfolio = portfolio.sort_values(by=performance_type, ascending = False)
|
3 |
+
curr_own_type_max = working_portfolio[own_type].max()
|
4 |
+
|
5 |
+
for row in working_portfolio.iterrows():
|
6 |
+
if row[performance_type] < curr_own_type_max:
|
7 |
+
working_portfolio = working_portfolio.drop(row.name)
|
8 |
+
curr_own_type_max = working_portfolio[own_type].max()
|
9 |
+
elif row[performance_type] >= curr_own_type_max:
|
10 |
+
pass
|
11 |
+
|
12 |
+
return working_portfolio
|