Spaces:
Sleeping
Sleeping
James McCool
commited on
Commit
·
a325276
1
Parent(s):
8816f53
removing some unused code
Browse files
app.py
CHANGED
|
@@ -1482,518 +1482,6 @@ if selected_tab == 'Data Load':
|
|
| 1482 |
|
| 1483 |
del st.session_state['portfolio'], st.session_state['export_portfolio']
|
| 1484 |
|
| 1485 |
-
# with tab2:
|
| 1486 |
-
# if st.button('Clear data', key='reset2'):
|
| 1487 |
-
# st.session_state.clear()
|
| 1488 |
-
|
| 1489 |
-
# if 'portfolio' in st.session_state and 'projections_df' in st.session_state:
|
| 1490 |
-
|
| 1491 |
-
# optimized_df = None
|
| 1492 |
-
|
| 1493 |
-
# map_dict = {
|
| 1494 |
-
# 'pos_map': dict(zip(st.session_state['projections_df']['player_names'],
|
| 1495 |
-
# st.session_state['projections_df']['position'])),
|
| 1496 |
-
# 'salary_map': dict(zip(st.session_state['projections_df']['player_names'],
|
| 1497 |
-
# st.session_state['projections_df']['salary'])),
|
| 1498 |
-
# 'proj_map': dict(zip(st.session_state['projections_df']['player_names'],
|
| 1499 |
-
# st.session_state['projections_df']['median'])),
|
| 1500 |
-
# 'own_map': dict(zip(st.session_state['projections_df']['player_names'],
|
| 1501 |
-
# st.session_state['projections_df']['ownership'])),
|
| 1502 |
-
# 'team_map': dict(zip(st.session_state['projections_df']['player_names'],
|
| 1503 |
-
# st.session_state['projections_df']['team']))
|
| 1504 |
-
# }
|
| 1505 |
-
# # Calculate new stats for optimized lineups
|
| 1506 |
-
# st.session_state['portfolio']['salary'] = st.session_state['portfolio'].apply(
|
| 1507 |
-
# lambda row: sum(map_dict['salary_map'].get(player, 0) for player in row if player in map_dict['salary_map']), axis=1
|
| 1508 |
-
# )
|
| 1509 |
-
# st.session_state['portfolio']['median'] = st.session_state['portfolio'].apply(
|
| 1510 |
-
# lambda row: sum(map_dict['proj_map'].get(player, 0) for player in row if player in map_dict['proj_map']), axis=1
|
| 1511 |
-
# )
|
| 1512 |
-
|
| 1513 |
-
# st.session_state['portfolio']['Own'] = st.session_state['portfolio'].apply(
|
| 1514 |
-
# lambda row: sum(map_dict['own_map'].get(player, 0) for player in row if player in map_dict['own_map']), axis=1
|
| 1515 |
-
# )
|
| 1516 |
-
|
| 1517 |
-
# options_container = st.container()
|
| 1518 |
-
# with options_container:
|
| 1519 |
-
# col1, col2, col3, col4, col5, col6 = st.columns(6)
|
| 1520 |
-
# with col1:
|
| 1521 |
-
# curr_site_var = st.selectbox("Select your current site", options=['DraftKings', 'FanDuel'])
|
| 1522 |
-
# with col2:
|
| 1523 |
-
# curr_sport_var = st.selectbox("Select your current sport", options=['NBA', 'MLB', 'NFL', 'NHL', 'MMA'])
|
| 1524 |
-
# with col3:
|
| 1525 |
-
# swap_var = st.multiselect("Select late swap strategy", options=['Optimize', 'Increase volatility', 'Decrease volatility'])
|
| 1526 |
-
# with col4:
|
| 1527 |
-
# remove_teams_var = st.multiselect("What teams have already played?", options=st.session_state['projections_df']['team'].unique())
|
| 1528 |
-
# with col5:
|
| 1529 |
-
# winners_var = st.multiselect("Are there any players doing exceptionally well?", options=st.session_state['projections_df']['player_names'].unique(), max_selections=3)
|
| 1530 |
-
# with col6:
|
| 1531 |
-
# losers_var = st.multiselect("Are there any players doing exceptionally poorly?", options=st.session_state['projections_df']['player_names'].unique(), max_selections=3)
|
| 1532 |
-
# if st.button('Clear Late Swap'):
|
| 1533 |
-
# if 'optimized_df' in st.session_state:
|
| 1534 |
-
# del st.session_state['optimized_df']
|
| 1535 |
-
|
| 1536 |
-
# map_dict = {
|
| 1537 |
-
# 'pos_map': dict(zip(st.session_state['projections_df']['player_names'],
|
| 1538 |
-
# st.session_state['projections_df']['position'])),
|
| 1539 |
-
# 'salary_map': dict(zip(st.session_state['projections_df']['player_names'],
|
| 1540 |
-
# st.session_state['projections_df']['salary'])),
|
| 1541 |
-
# 'proj_map': dict(zip(st.session_state['projections_df']['player_names'],
|
| 1542 |
-
# st.session_state['projections_df']['median'])),
|
| 1543 |
-
# 'own_map': dict(zip(st.session_state['projections_df']['player_names'],
|
| 1544 |
-
# st.session_state['projections_df']['ownership'])),
|
| 1545 |
-
# 'team_map': dict(zip(st.session_state['projections_df']['player_names'],
|
| 1546 |
-
# st.session_state['projections_df']['team']))
|
| 1547 |
-
# }
|
| 1548 |
-
# # Calculate new stats for optimized lineups
|
| 1549 |
-
# st.session_state['portfolio']['salary'] = st.session_state['portfolio'].apply(
|
| 1550 |
-
# lambda row: sum(map_dict['salary_map'].get(player, 0) for player in row if player in map_dict['salary_map']), axis=1
|
| 1551 |
-
# )
|
| 1552 |
-
# st.session_state['portfolio']['median'] = st.session_state['portfolio'].apply(
|
| 1553 |
-
# lambda row: sum(map_dict['proj_map'].get(player, 0) for player in row if player in map_dict['proj_map']), axis=1
|
| 1554 |
-
# )
|
| 1555 |
-
# st.session_state['portfolio']['Own'] = st.session_state['portfolio'].apply(
|
| 1556 |
-
# lambda row: sum(map_dict['own_map'].get(player, 0) for player in row if player in map_dict['own_map']), axis=1
|
| 1557 |
-
# )
|
| 1558 |
-
|
| 1559 |
-
# if st.button('Run Late Swap'):
|
| 1560 |
-
# st.session_state['portfolio'] = st.session_state['portfolio'].drop(columns=['salary', 'median', 'Own'])
|
| 1561 |
-
# if curr_sport_var == 'NBA':
|
| 1562 |
-
# if curr_site_var == 'DraftKings':
|
| 1563 |
-
# st.session_state['portfolio'] = st.session_state['portfolio'].set_axis(['PG', 'SG', 'SF', 'PF', 'C', 'G', 'F', 'UTIL'], axis=1)
|
| 1564 |
-
# else:
|
| 1565 |
-
# st.session_state['portfolio'] = st.session_state['portfolio'].set_axis(['PG', 'PG', 'SG', 'SG', 'SF', 'SF', 'PF', 'PF', 'C'], axis=1)
|
| 1566 |
-
|
| 1567 |
-
# # Define roster position rules
|
| 1568 |
-
# if curr_site_var == 'DraftKings':
|
| 1569 |
-
# position_rules = {
|
| 1570 |
-
# 'PG': ['PG'],
|
| 1571 |
-
# 'SG': ['SG'],
|
| 1572 |
-
# 'SF': ['SF'],
|
| 1573 |
-
# 'PF': ['PF'],
|
| 1574 |
-
# 'C': ['C'],
|
| 1575 |
-
# 'G': ['PG', 'SG'],
|
| 1576 |
-
# 'F': ['SF', 'PF'],
|
| 1577 |
-
# 'UTIL': ['PG', 'SG', 'SF', 'PF', 'C']
|
| 1578 |
-
# }
|
| 1579 |
-
# else:
|
| 1580 |
-
# position_rules = {
|
| 1581 |
-
# 'PG': ['PG'],
|
| 1582 |
-
# 'SG': ['SG'],
|
| 1583 |
-
# 'SF': ['SF'],
|
| 1584 |
-
# 'PF': ['PF'],
|
| 1585 |
-
# 'C': ['C'],
|
| 1586 |
-
# }
|
| 1587 |
-
# # Create position groups from projections data
|
| 1588 |
-
# position_groups = {}
|
| 1589 |
-
# for _, player in st.session_state['projections_df'].iterrows():
|
| 1590 |
-
# positions = player['position'].split('/')
|
| 1591 |
-
# for pos in positions:
|
| 1592 |
-
# if pos not in position_groups:
|
| 1593 |
-
# position_groups[pos] = []
|
| 1594 |
-
# position_groups[pos].append({
|
| 1595 |
-
# 'player_names': player['player_names'],
|
| 1596 |
-
# 'salary': player['salary'],
|
| 1597 |
-
# 'median': player['median'],
|
| 1598 |
-
# 'ownership': player['ownership'],
|
| 1599 |
-
# 'positions': positions # Store all eligible positions
|
| 1600 |
-
# })
|
| 1601 |
-
|
| 1602 |
-
# def optimize_lineup(row):
|
| 1603 |
-
# current_lineup = []
|
| 1604 |
-
# total_salary = 0
|
| 1605 |
-
# if curr_site_var == 'DraftKings':
|
| 1606 |
-
# salary_cap = 50000
|
| 1607 |
-
# else:
|
| 1608 |
-
# salary_cap = 60000
|
| 1609 |
-
# used_players = set()
|
| 1610 |
-
|
| 1611 |
-
# # Convert row to dictionary with roster positions
|
| 1612 |
-
# roster = {}
|
| 1613 |
-
# for col, player in zip(row.index, row):
|
| 1614 |
-
# if col not in ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Lineup Edge']:
|
| 1615 |
-
# roster[col] = {
|
| 1616 |
-
# 'name': player,
|
| 1617 |
-
# 'position': map_dict['pos_map'].get(player, '').split('/'),
|
| 1618 |
-
# 'team': map_dict['team_map'].get(player, ''),
|
| 1619 |
-
# 'salary': map_dict['salary_map'].get(player, 0),
|
| 1620 |
-
# 'median': map_dict['proj_map'].get(player, 0),
|
| 1621 |
-
# 'ownership': map_dict['own_map'].get(player, 0)
|
| 1622 |
-
# }
|
| 1623 |
-
# total_salary += roster[col]['salary']
|
| 1624 |
-
# used_players.add(player)
|
| 1625 |
-
|
| 1626 |
-
# # Optimize each roster position in random order
|
| 1627 |
-
# roster_positions = list(roster.items())
|
| 1628 |
-
# random.shuffle(roster_positions)
|
| 1629 |
-
|
| 1630 |
-
# for roster_pos, current in roster_positions:
|
| 1631 |
-
# # Skip optimization for players from removed teams
|
| 1632 |
-
# if current['team'] in remove_teams_var:
|
| 1633 |
-
# continue
|
| 1634 |
-
|
| 1635 |
-
# valid_positions = position_rules[roster_pos]
|
| 1636 |
-
# better_options = []
|
| 1637 |
-
|
| 1638 |
-
# # Find valid replacements for this roster position
|
| 1639 |
-
# for pos in valid_positions:
|
| 1640 |
-
# if pos in position_groups:
|
| 1641 |
-
# pos_options = [
|
| 1642 |
-
# p for p in position_groups[pos]
|
| 1643 |
-
# if p['median'] > current['median']
|
| 1644 |
-
# and (total_salary - current['salary'] + p['salary']) <= salary_cap
|
| 1645 |
-
# and p['player_names'] not in used_players
|
| 1646 |
-
# and any(valid_pos in p['positions'] for valid_pos in valid_positions)
|
| 1647 |
-
# and map_dict['team_map'].get(p['player_names']) not in remove_teams_var # Check team restriction
|
| 1648 |
-
# ]
|
| 1649 |
-
# better_options.extend(pos_options)
|
| 1650 |
-
|
| 1651 |
-
# if better_options:
|
| 1652 |
-
# # Remove duplicates
|
| 1653 |
-
# better_options = {opt['player_names']: opt for opt in better_options}.values()
|
| 1654 |
-
|
| 1655 |
-
# # Sort by median projection and take the best one
|
| 1656 |
-
# best_replacement = max(better_options, key=lambda x: x['median'])
|
| 1657 |
-
|
| 1658 |
-
# # Update the lineup and tracking variables
|
| 1659 |
-
# used_players.remove(current['name'])
|
| 1660 |
-
# used_players.add(best_replacement['player_names'])
|
| 1661 |
-
# total_salary = total_salary - current['salary'] + best_replacement['salary']
|
| 1662 |
-
# roster[roster_pos] = {
|
| 1663 |
-
# 'name': best_replacement['player_names'],
|
| 1664 |
-
# 'position': map_dict['pos_map'][best_replacement['player_names']].split('/'),
|
| 1665 |
-
# 'team': map_dict['team_map'][best_replacement['player_names']],
|
| 1666 |
-
# 'salary': best_replacement['salary'],
|
| 1667 |
-
# 'median': best_replacement['median'],
|
| 1668 |
-
# 'ownership': best_replacement['ownership']
|
| 1669 |
-
# }
|
| 1670 |
-
|
| 1671 |
-
# # Return optimized lineup maintaining original column order
|
| 1672 |
-
# return [roster[pos]['name'] for pos in row.index if pos in roster]
|
| 1673 |
-
|
| 1674 |
-
# def optimize_lineup_winners(row):
|
| 1675 |
-
# current_lineup = []
|
| 1676 |
-
# total_salary = 0
|
| 1677 |
-
# if curr_site_var == 'DraftKings':
|
| 1678 |
-
# salary_cap = 50000
|
| 1679 |
-
# else:
|
| 1680 |
-
# salary_cap = 60000
|
| 1681 |
-
# used_players = set()
|
| 1682 |
-
|
| 1683 |
-
# # Check if any winners are in the lineup and count them
|
| 1684 |
-
# winners_in_lineup = sum(1 for player in row if player in winners_var)
|
| 1685 |
-
# changes_needed = min(winners_in_lineup, 3) if winners_in_lineup > 0 else 0
|
| 1686 |
-
# changes_made = 0
|
| 1687 |
-
|
| 1688 |
-
# # Convert row to dictionary with roster positions
|
| 1689 |
-
# roster = {}
|
| 1690 |
-
# for col, player in zip(row.index, row):
|
| 1691 |
-
# if col not in ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Lineup Edge']:
|
| 1692 |
-
# roster[col] = {
|
| 1693 |
-
# 'name': player,
|
| 1694 |
-
# 'position': map_dict['pos_map'].get(player, '').split('/'),
|
| 1695 |
-
# 'team': map_dict['team_map'].get(player, ''),
|
| 1696 |
-
# 'salary': map_dict['salary_map'].get(player, 0),
|
| 1697 |
-
# 'median': map_dict['proj_map'].get(player, 0),
|
| 1698 |
-
# 'ownership': map_dict['own_map'].get(player, 0)
|
| 1699 |
-
# }
|
| 1700 |
-
# total_salary += roster[col]['salary']
|
| 1701 |
-
# used_players.add(player)
|
| 1702 |
-
|
| 1703 |
-
# # Only proceed with ownership-based optimization if we have winners in the lineup
|
| 1704 |
-
# if changes_needed > 0:
|
| 1705 |
-
# # Randomize the order of positions to optimize
|
| 1706 |
-
# roster_positions = list(roster.items())
|
| 1707 |
-
# random.shuffle(roster_positions)
|
| 1708 |
-
|
| 1709 |
-
# for roster_pos, current in roster_positions:
|
| 1710 |
-
# # Stop if we've made enough changes
|
| 1711 |
-
# if changes_made >= changes_needed:
|
| 1712 |
-
# break
|
| 1713 |
-
|
| 1714 |
-
# # Skip optimization for players from removed teams or if the current player is a winner
|
| 1715 |
-
# if current['team'] in remove_teams_var or current['name'] in winners_var:
|
| 1716 |
-
# continue
|
| 1717 |
-
|
| 1718 |
-
# valid_positions = list(position_rules[roster_pos])
|
| 1719 |
-
# random.shuffle(valid_positions)
|
| 1720 |
-
# better_options = []
|
| 1721 |
-
|
| 1722 |
-
# # Find valid replacements with higher ownership
|
| 1723 |
-
# for pos in valid_positions:
|
| 1724 |
-
# if pos in position_groups:
|
| 1725 |
-
# pos_options = [
|
| 1726 |
-
# p for p in position_groups[pos]
|
| 1727 |
-
# if p['ownership'] > current['ownership']
|
| 1728 |
-
# and p['median'] >= current['median'] - 3
|
| 1729 |
-
# and (total_salary - current['salary'] + p['salary']) <= salary_cap
|
| 1730 |
-
# and (total_salary - current['salary'] + p['salary']) >= salary_cap - 1000
|
| 1731 |
-
# and p['player_names'] not in used_players
|
| 1732 |
-
# and any(valid_pos in p['positions'] for valid_pos in valid_positions)
|
| 1733 |
-
# and map_dict['team_map'].get(p['player_names']) not in remove_teams_var
|
| 1734 |
-
# ]
|
| 1735 |
-
# better_options.extend(pos_options)
|
| 1736 |
-
|
| 1737 |
-
# if better_options:
|
| 1738 |
-
# # Remove duplicates
|
| 1739 |
-
# better_options = {opt['player_names']: opt for opt in better_options}.values()
|
| 1740 |
-
|
| 1741 |
-
# # Sort by ownership and take the highest owned option
|
| 1742 |
-
# best_replacement = max(better_options, key=lambda x: x['ownership'])
|
| 1743 |
-
|
| 1744 |
-
# # Update the lineup and tracking variables
|
| 1745 |
-
# used_players.remove(current['name'])
|
| 1746 |
-
# used_players.add(best_replacement['player_names'])
|
| 1747 |
-
# total_salary = total_salary - current['salary'] + best_replacement['salary']
|
| 1748 |
-
# roster[roster_pos] = {
|
| 1749 |
-
# 'name': best_replacement['player_names'],
|
| 1750 |
-
# 'position': map_dict['pos_map'][best_replacement['player_names']].split('/'),
|
| 1751 |
-
# 'team': map_dict['team_map'][best_replacement['player_names']],
|
| 1752 |
-
# 'salary': best_replacement['salary'],
|
| 1753 |
-
# 'median': best_replacement['median'],
|
| 1754 |
-
# 'ownership': best_replacement['ownership']
|
| 1755 |
-
# }
|
| 1756 |
-
# changes_made += 1
|
| 1757 |
-
|
| 1758 |
-
# # Return optimized lineup maintaining original column order
|
| 1759 |
-
# return [roster[pos]['name'] for pos in row.index if pos in roster]
|
| 1760 |
-
|
| 1761 |
-
# def optimize_lineup_losers(row):
|
| 1762 |
-
# current_lineup = []
|
| 1763 |
-
# total_salary = 0
|
| 1764 |
-
# if curr_site_var == 'DraftKings':
|
| 1765 |
-
# salary_cap = 50000
|
| 1766 |
-
# else:
|
| 1767 |
-
# salary_cap = 60000
|
| 1768 |
-
# used_players = set()
|
| 1769 |
-
|
| 1770 |
-
# # Check if any winners are in the lineup and count them
|
| 1771 |
-
# losers_in_lineup = sum(1 for player in row if player in losers_var)
|
| 1772 |
-
# changes_needed = min(losers_in_lineup, 3) if losers_in_lineup > 0 else 0
|
| 1773 |
-
# changes_made = 0
|
| 1774 |
-
|
| 1775 |
-
# # Convert row to dictionary with roster positions
|
| 1776 |
-
# roster = {}
|
| 1777 |
-
# for col, player in zip(row.index, row):
|
| 1778 |
-
# if col not in ['salary', 'median', 'Own', 'Finish_percentile', 'Dupes', 'Lineup Edge']:
|
| 1779 |
-
# roster[col] = {
|
| 1780 |
-
# 'name': player,
|
| 1781 |
-
# 'position': map_dict['pos_map'].get(player, '').split('/'),
|
| 1782 |
-
# 'team': map_dict['team_map'].get(player, ''),
|
| 1783 |
-
# 'salary': map_dict['salary_map'].get(player, 0),
|
| 1784 |
-
# 'median': map_dict['proj_map'].get(player, 0),
|
| 1785 |
-
# 'ownership': map_dict['own_map'].get(player, 0)
|
| 1786 |
-
# }
|
| 1787 |
-
# total_salary += roster[col]['salary']
|
| 1788 |
-
# used_players.add(player)
|
| 1789 |
-
|
| 1790 |
-
# # Only proceed with ownership-based optimization if we have winners in the lineup
|
| 1791 |
-
# if changes_needed > 0:
|
| 1792 |
-
# # Randomize the order of positions to optimize
|
| 1793 |
-
# roster_positions = list(roster.items())
|
| 1794 |
-
# random.shuffle(roster_positions)
|
| 1795 |
-
|
| 1796 |
-
# for roster_pos, current in roster_positions:
|
| 1797 |
-
# # Stop if we've made enough changes
|
| 1798 |
-
# if changes_made >= changes_needed:
|
| 1799 |
-
# break
|
| 1800 |
-
|
| 1801 |
-
# # Skip optimization for players from removed teams or if the current player is a winner
|
| 1802 |
-
# if current['team'] in remove_teams_var or current['name'] in losers_var:
|
| 1803 |
-
# continue
|
| 1804 |
-
|
| 1805 |
-
# valid_positions = list(position_rules[roster_pos])
|
| 1806 |
-
# random.shuffle(valid_positions)
|
| 1807 |
-
# better_options = []
|
| 1808 |
-
|
| 1809 |
-
# # Find valid replacements with higher ownership
|
| 1810 |
-
# for pos in valid_positions:
|
| 1811 |
-
# if pos in position_groups:
|
| 1812 |
-
# pos_options = [
|
| 1813 |
-
# p for p in position_groups[pos]
|
| 1814 |
-
# if p['ownership'] < current['ownership']
|
| 1815 |
-
# and p['median'] >= current['median'] - 3
|
| 1816 |
-
# and (total_salary - current['salary'] + p['salary']) <= salary_cap
|
| 1817 |
-
# and (total_salary - current['salary'] + p['salary']) >= salary_cap - 1000
|
| 1818 |
-
# and p['player_names'] not in used_players
|
| 1819 |
-
# and any(valid_pos in p['positions'] for valid_pos in valid_positions)
|
| 1820 |
-
# and map_dict['team_map'].get(p['player_names']) not in remove_teams_var
|
| 1821 |
-
# ]
|
| 1822 |
-
# better_options.extend(pos_options)
|
| 1823 |
-
|
| 1824 |
-
# if better_options:
|
| 1825 |
-
# # Remove duplicates
|
| 1826 |
-
# better_options = {opt['player_names']: opt for opt in better_options}.values()
|
| 1827 |
-
|
| 1828 |
-
# # Sort by ownership and take the highest owned option
|
| 1829 |
-
# best_replacement = max(better_options, key=lambda x: x['ownership'])
|
| 1830 |
-
|
| 1831 |
-
# # Update the lineup and tracking variables
|
| 1832 |
-
# used_players.remove(current['name'])
|
| 1833 |
-
# used_players.add(best_replacement['player_names'])
|
| 1834 |
-
# total_salary = total_salary - current['salary'] + best_replacement['salary']
|
| 1835 |
-
# roster[roster_pos] = {
|
| 1836 |
-
# 'name': best_replacement['player_names'],
|
| 1837 |
-
# 'position': map_dict['pos_map'][best_replacement['player_names']].split('/'),
|
| 1838 |
-
# 'team': map_dict['team_map'][best_replacement['player_names']],
|
| 1839 |
-
# 'salary': best_replacement['salary'],
|
| 1840 |
-
# 'median': best_replacement['median'],
|
| 1841 |
-
# 'ownership': best_replacement['ownership']
|
| 1842 |
-
# }
|
| 1843 |
-
# changes_made += 1
|
| 1844 |
-
|
| 1845 |
-
# # Return optimized lineup maintaining original column order
|
| 1846 |
-
# return [roster[pos]['name'] for pos in row.index if pos in roster]
|
| 1847 |
-
|
| 1848 |
-
# # Create a progress bar
|
| 1849 |
-
# progress_bar = st.progress(0)
|
| 1850 |
-
# status_text = st.empty()
|
| 1851 |
-
|
| 1852 |
-
# # Process each lineup
|
| 1853 |
-
# optimized_lineups = []
|
| 1854 |
-
# total_lineups = len(st.session_state['portfolio'])
|
| 1855 |
-
|
| 1856 |
-
# for idx, row in st.session_state['portfolio'].iterrows():
|
| 1857 |
-
# # First optimization pass
|
| 1858 |
-
# first_pass = optimize_lineup(row)
|
| 1859 |
-
# first_pass_series = pd.Series(first_pass, index=row.index)
|
| 1860 |
-
|
| 1861 |
-
# second_pass = optimize_lineup(first_pass_series)
|
| 1862 |
-
# second_pass_series = pd.Series(second_pass, index=row.index)
|
| 1863 |
-
|
| 1864 |
-
# third_pass = optimize_lineup(second_pass_series)
|
| 1865 |
-
# third_pass_series = pd.Series(third_pass, index=row.index)
|
| 1866 |
-
|
| 1867 |
-
# fourth_pass = optimize_lineup(third_pass_series)
|
| 1868 |
-
# fourth_pass_series = pd.Series(fourth_pass, index=row.index)
|
| 1869 |
-
|
| 1870 |
-
# fifth_pass = optimize_lineup(fourth_pass_series)
|
| 1871 |
-
# fifth_pass_series = pd.Series(fifth_pass, index=row.index)
|
| 1872 |
-
|
| 1873 |
-
# # Second optimization pass
|
| 1874 |
-
# final_lineup = optimize_lineup(fifth_pass_series)
|
| 1875 |
-
# optimized_lineups.append(final_lineup)
|
| 1876 |
-
|
| 1877 |
-
# if 'Optimize' in swap_var:
|
| 1878 |
-
# progress = (idx + 1) / total_lineups
|
| 1879 |
-
# progress_bar.progress(progress)
|
| 1880 |
-
# status_text.text(f'Optimizing Lineups {idx + 1} of {total_lineups}')
|
| 1881 |
-
# else:
|
| 1882 |
-
# pass
|
| 1883 |
-
|
| 1884 |
-
# # Create new dataframe with optimized lineups
|
| 1885 |
-
# if 'Optimize' in swap_var:
|
| 1886 |
-
# st.session_state['optimized_df_medians'] = pd.DataFrame(optimized_lineups, columns=st.session_state['portfolio'].columns)
|
| 1887 |
-
# else:
|
| 1888 |
-
# st.session_state['optimized_df_medians'] = st.session_state['portfolio']
|
| 1889 |
-
|
| 1890 |
-
# # Create a progress bar
|
| 1891 |
-
# progress_bar_winners = st.progress(0)
|
| 1892 |
-
# status_text_winners = st.empty()
|
| 1893 |
-
|
| 1894 |
-
# # Process each lineup
|
| 1895 |
-
# optimized_lineups_winners = []
|
| 1896 |
-
# total_lineups = len(st.session_state['optimized_df_medians'])
|
| 1897 |
-
|
| 1898 |
-
# for idx, row in st.session_state['optimized_df_medians'].iterrows():
|
| 1899 |
-
|
| 1900 |
-
# final_lineup = optimize_lineup_winners(row)
|
| 1901 |
-
# optimized_lineups_winners.append(final_lineup)
|
| 1902 |
-
|
| 1903 |
-
# if 'Decrease volatility' in swap_var:
|
| 1904 |
-
# progress_winners = (idx + 1) / total_lineups
|
| 1905 |
-
# progress_bar_winners.progress(progress_winners)
|
| 1906 |
-
# status_text_winners.text(f'Lowering Volatility around Winners {idx + 1} of {total_lineups}')
|
| 1907 |
-
# else:
|
| 1908 |
-
# pass
|
| 1909 |
-
|
| 1910 |
-
# # Create new dataframe with optimized lineups
|
| 1911 |
-
# if 'Decrease volatility' in swap_var:
|
| 1912 |
-
# st.session_state['optimized_df_winners'] = pd.DataFrame(optimized_lineups_winners, columns=st.session_state['optimized_df_medians'].columns)
|
| 1913 |
-
# else:
|
| 1914 |
-
# st.session_state['optimized_df_winners'] = st.session_state['optimized_df_medians']
|
| 1915 |
-
|
| 1916 |
-
# # Create a progress bar
|
| 1917 |
-
# progress_bar_losers = st.progress(0)
|
| 1918 |
-
# status_text_losers = st.empty()
|
| 1919 |
-
|
| 1920 |
-
# # Process each lineup
|
| 1921 |
-
# optimized_lineups_losers = []
|
| 1922 |
-
# total_lineups = len(st.session_state['optimized_df_winners'])
|
| 1923 |
-
|
| 1924 |
-
# for idx, row in st.session_state['optimized_df_winners'].iterrows():
|
| 1925 |
-
|
| 1926 |
-
# final_lineup = optimize_lineup_losers(row)
|
| 1927 |
-
# optimized_lineups_losers.append(final_lineup)
|
| 1928 |
-
|
| 1929 |
-
# if 'Increase volatility' in swap_var:
|
| 1930 |
-
# progress_losers = (idx + 1) / total_lineups
|
| 1931 |
-
# progress_bar_losers.progress(progress_losers)
|
| 1932 |
-
# status_text_losers.text(f'Increasing Volatility around Losers {idx + 1} of {total_lineups}')
|
| 1933 |
-
# else:
|
| 1934 |
-
# pass
|
| 1935 |
-
|
| 1936 |
-
# # Create new dataframe with optimized lineups
|
| 1937 |
-
# if 'Increase volatility' in swap_var:
|
| 1938 |
-
# st.session_state['optimized_df'] = pd.DataFrame(optimized_lineups_losers, columns=st.session_state['optimized_df_winners'].columns)
|
| 1939 |
-
# else:
|
| 1940 |
-
# st.session_state['optimized_df'] = st.session_state['optimized_df_winners']
|
| 1941 |
-
|
| 1942 |
-
# # Calculate new stats for optimized lineups
|
| 1943 |
-
# st.session_state['optimized_df']['salary'] = st.session_state['optimized_df'].apply(
|
| 1944 |
-
# lambda row: sum(map_dict['salary_map'].get(player, 0) for player in row if player in map_dict['salary_map']), axis=1
|
| 1945 |
-
# )
|
| 1946 |
-
# st.session_state['optimized_df']['median'] = st.session_state['optimized_df'].apply(
|
| 1947 |
-
# lambda row: sum(map_dict['proj_map'].get(player, 0) for player in row if player in map_dict['proj_map']), axis=1
|
| 1948 |
-
# )
|
| 1949 |
-
# st.session_state['optimized_df']['Own'] = st.session_state['optimized_df'].apply(
|
| 1950 |
-
# lambda row: sum(map_dict['own_map'].get(player, 0) for player in row if player in map_dict['own_map']), axis=1
|
| 1951 |
-
# )
|
| 1952 |
-
|
| 1953 |
-
# # Display results
|
| 1954 |
-
# st.success('Optimization complete!')
|
| 1955 |
-
|
| 1956 |
-
# if 'optimized_df' in st.session_state:
|
| 1957 |
-
# st.write("Increase in median highlighted in yellow, descrease in volatility highlighted in blue, increase in volatility highlighted in red:")
|
| 1958 |
-
# st.dataframe(
|
| 1959 |
-
# st.session_state['optimized_df'].style
|
| 1960 |
-
# .apply(highlight_changes, axis=1)
|
| 1961 |
-
# .apply(highlight_changes_winners, axis=1)
|
| 1962 |
-
# .apply(highlight_changes_losers, axis=1)
|
| 1963 |
-
# .background_gradient(axis=0)
|
| 1964 |
-
# .background_gradient(cmap='RdYlGn')
|
| 1965 |
-
# .format(precision=2),
|
| 1966 |
-
# height=1000,
|
| 1967 |
-
# use_container_width=True
|
| 1968 |
-
# )
|
| 1969 |
-
|
| 1970 |
-
# # Option to download optimized lineups
|
| 1971 |
-
# if st.button('Prepare Late Swap Export'):
|
| 1972 |
-
# export_df = st.session_state['optimized_df'].copy()
|
| 1973 |
-
|
| 1974 |
-
# # Map player names to their export IDs for all player columns
|
| 1975 |
-
# for col in export_df.columns:
|
| 1976 |
-
# if col not in ['salary', 'median', 'Own']:
|
| 1977 |
-
# export_df[col] = export_df[col].map(st.session_state['export_dict'])
|
| 1978 |
-
|
| 1979 |
-
# csv = export_df.to_csv(index=False)
|
| 1980 |
-
# st.download_button(
|
| 1981 |
-
# label="Download CSV",
|
| 1982 |
-
# data=csv,
|
| 1983 |
-
# file_name="optimized_lineups.csv",
|
| 1984 |
-
# mime="text/csv"
|
| 1985 |
-
# )
|
| 1986 |
-
# else:
|
| 1987 |
-
# st.write("Current Portfolio")
|
| 1988 |
-
# st.dataframe(
|
| 1989 |
-
# st.session_state['portfolio'].style
|
| 1990 |
-
# .background_gradient(axis=0)
|
| 1991 |
-
# .background_gradient(cmap='RdYlGn')
|
| 1992 |
-
# .format(precision=2),
|
| 1993 |
-
# height=1000,
|
| 1994 |
-
# use_container_width=True
|
| 1995 |
-
# )
|
| 1996 |
-
|
| 1997 |
if selected_tab == 'Manage Portfolio':
|
| 1998 |
if 'origin_portfolio' in st.session_state and 'projections_df' in st.session_state:
|
| 1999 |
with st.container():
|
|
|
|
| 1482 |
|
| 1483 |
del st.session_state['portfolio'], st.session_state['export_portfolio']
|
| 1484 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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