Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using optimizer.player_pool.load_players #392

Open
mcarroll316 opened this issue Nov 22, 2022 · 3 comments
Open

Error when using optimizer.player_pool.load_players #392

mcarroll316 opened this issue Nov 22, 2022 · 3 comments

Comments

@mcarroll316
Copy link

mcarroll316 commented Nov 22, 2022

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
Copy link

mbencho commented Nov 22, 2022

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
Copy link
Author

mcarroll316 commented Nov 22, 2022

@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
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants