DimaKudosh / pydfs-lineup-optimizer

Daily Fantasy Sports lineup optimzer for all popular daily fantasy sports sites
MIT License
424 stars 157 forks source link

Error when using optimizer.player_pool.load_players #392

Open mcarroll316 opened 2 years ago

mcarroll316 commented 2 years ago

I'm attempting to use the load_players method (instead of loading from csv), but get the following error:

File "C:\Pypy\lib\site-packages\pydfs_lineup_optimizer\player_pool.py", line 160, in add_player self._players_by_name[player.full_name].append(player) AttributeError: 'dict' object has no attribute 'full_name'

My sample list:

playerList = [
    {
        "\"Position\"": "\"SP\"",
        "\"Name + ID\"": "\"Shane Bieber (669456)\"",
        "\"Name\"": "\"Shane Bieber\"",
        "\"ID\"": "\"669456\"",
        "\"RosterPosition\"": "\"\"",
        "\"Salary\"": "\"9000\"",
        "\"Game Info\"": "\"Cle@Tor\"",
        "\"TeamAbbrev\"": "\"CLE\"",
        "\"AvgPointsPerGame\"\r": "\"17.01\"\r"
    },
    {
        "\"Position\"": "\"1B\"",
        "\"Name + ID\"": "\"Vladimir Guerrero Jr. (665489)\"",
        "\"Name\"": "\"Vladimir Guerrero Jr.\"",
        "\"ID\"": "\"665489\"",
        "\"RosterPosition\"": "\"\"",
        "\"Salary\"": "\"4800\"",
        "\"Game Info\"": "\"Cle@Tor\"",
        "\"TeamAbbrev\"": "\"TOR\"",
        "\"AvgPointsPerGame\"\r": "\"9.38\"\r"
    },
]

Perhaps it's not a bug, but instead I might be missing or misunderstanding something on the usage. No errors are thrown when I use the load_players_from_csv method.

Would welcome any guidance and assistance. Thank you.

mbencho commented 2 years ago

I'm not familiar with load_players, looking at it, it may be that it is missing a first_name and last_name fields in your list?

@property def full_name(self) -> str: return '{} {}'.format(self.first_name, self.last_name)

Just a curiosity but if the file load is working what advantage is there to using this method instead?

mcarroll316 commented 2 years ago

@mbencho - Re: Missing first_name & last_name was what I was thinking initially as well, but I would think the CSV & json elements would need to be the same, especially considering it's supposed to be based off the Draftkings export.

The reason I'm trying this method is because I'm integrating this into my site and want to avoid having a csv file created from the client, saved to the server, then recalled by python. I'm finding some challenges in getting the csv data OR the json passed from the client to the python script. I tried base64 encoding, but that throws an error when including that as an argument. I've tried several ways to achieve what I attempting to do, with little success.

DimaKudosh commented 1 year ago

load_players functions accept list of Player objects, you tried to pass a list of dictionaries and because of it you got this error. You need to build Player objects and pass them.