James McCool
Remove NASCAR table display from app.py to streamline portfolio presentation and improve user experience. Update name mapping logic in load_dk_fd_file.py to enhance ID handling and ensure cleaner data output.
b6cd6af
import streamlit as st | |
import numpy as np | |
import pandas as pd | |
import time | |
from rapidfuzz import process | |
import re | |
def load_dk_fd_file(lineups, csv_file): | |
df = csv_file.copy() | |
try: | |
name_dict = dict(zip(df['Name + ID'], df['Name'])) | |
except: | |
name_dict = dict(zip(df['Id'], df['Nickname'])) | |
# Now load and process the lineups file | |
try: | |
clean_name = re.sub(r' \(\d+\)', '', lineups.name) | |
print(clean_name) | |
print(lineups.name) | |
if clean_name.endswith('.csv'): | |
lineups_df = pd.read_csv(lineups) | |
elif clean_name.endswith(('.xls', '.xlsx')): | |
lineups_df = pd.read_excel(lineups) | |
else: | |
st.error('Please upload either a CSV or Excel file for lineups') | |
return None, None | |
print(lineups_df) | |
try: | |
lineups_df = lineups_df.drop(columns=['Entry ID', 'Contest Name', 'Contest ID', 'Entry Fee']) | |
except: | |
pass | |
export_df = lineups_df.copy() | |
# Map the IDs to names | |
for col in lineups_df.columns: | |
def map_or_clean(value): | |
# First try to map using the dictionary | |
if value in name_dict: | |
return name_dict[value] | |
else: | |
# If no match found, remove the ID portion | |
match = re.search(r' \(', str(value)) | |
if match: | |
return str(value)[:match.start()] | |
return value | |
lineups_df[col] = lineups_df[col].apply(map_or_clean) | |
return export_df, lineups_df | |
except Exception as e: | |
st.error(f'Error loading lineups file: {str(e)}') | |
return None, None |