DimaKudosh / pydfs-lineup-optimizer

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

Using SQL to populate DraftKings (Players) -- Doesn't work #50

Closed dexter1964 closed 5 years ago

dexter1964 commented 5 years ago

Hello again, I know this is my fault and my own stupidity, but can you please help. I got your optimizer working by populating the Players through an SQL query using site.FANDUEL (works great!). But I can't seem to get it to work with the DRAFTKINGS Optimizer.

optimizer = get_optimizer(Site.DRAFTKINGS, Sport.BASEBALL)

the DRAFTKINGS optimizer works great using the CSV file Loader.

I believe my data looks good, in my database. Do you think there might be something wrong with my data? (I'm also attaching an Export of my scraped MLB Data.

I've tried to include everything I could think of. Can you please point me in the right direction?

20190326-MLBRosterData.zip

Can you please help? Thank you so much!, Larry

##################################################### Traceback (most recent call last): File "C:\Users\Larry Brown\AppData\Local\Programs\Python\Python37\lib\site-packages\pydfs_lineup_optimizer\lineup_optimizer.py", line 385, in optimize solved_variables = solver.solve() File "C:\Users\Larry Brown\AppData\Local\Programs\Python\Python37\lib\site-packages\pydfs_lineup_optimizer\solvers\pulp_solver.py", line 47, in solve raise SolverException('Unable to solve') pydfs_lineup_optimizer.solvers.exceptions.SolverException: Unable to solve

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File ".\MLBDKTodaysTop3Lineups.py", line 143, in for lineup in lineup_generator: File "C:\Users\Larry Brown\AppData\Local\Programs\Python\Python37\lib\site-packages\pydfs_lineup_optimizer\lineup_optimizer.py", line 397, in optimize raise LineupOptimizerException('Can\'t generate lineups') pydfs_lineup_optimizer.exceptions.LineupOptimizerException: Can't generate lineups ######################################################## `from pydfs_lineup_optimizer import Site, Sport, get_optimizer, Player optimizer = get_optimizer(Site.DRAFTKINGS, Sport.BASEBALL)

players = []

roster = mF.getAllMLBPlayerInfo('DK') for i, player_info in enumerate(roster): name = player_info[0].split(' ')

print('player_info[' + str(i) +'] : ')
print('PlayerName : ' + str(player_info[0]))
print('Name[0]    : ' + str(name[0]))
print('Name[1]    : ' + str(name[1]))
print('TeamShort  : ' + str(player_info[1]))
print('Position   : ' + str(player_info[2].split('/')))
print('Salary     : ' + str(player_info[3]))
print('FanPoints  : ' + str(player_info[4]))

players.append(Player(
    int(i),
    name[0],
    name[1],
    player_info[2].split('/'),    # for Fanduel use '-' for Draftkings use '/'
    player_info[1],
    float(player_info[3]),
    float(player_info[4])
))

optimizer.load_players(players)` ######################################################## OUTPUT from Print Statements above: player_info[280] : PlayerName : Eric Stamets Name[0] : Eric Name[1] : Stamets TeamShort : CLE Position : ['SS'] Salary : 2700.0 FanPoints : 5.36 player_info[281] : PlayerName : Martin Maldonado Name[0] : Martin Name[1] : Maldonado TeamShort : KCR Position : ['C'] Salary : 2700.0 FanPoints : 5.68 player_info[282] : PlayerName : Miguel Cabrera Name[0] : Miguel Name[1] : Cabrera TeamShort : DET Position : ['1B'] Salary : 2400.0 FanPoints : 6.92

##################################################### def getAllMLBPlayerInfo(VENDOR='FD'): conn = mysql.connector.connect(user='xxxx', password='xxxx', host='192.168.1.248', database='MLB_TABLE') cur = conn.cursor()

print('Vendor Variable: ' + VENDOR)

if VENDOR=='FD':
    qPlayerInfo = \
    "Select \
        MLBStartingLineups.PlayerName, \
        MLBStartingLineups.TeamShort, \
        MLBStartingLineups.PlayerFDPosition, \
        MLBStartingLineups.FanDuelSalary, \
        MLBStartingLineups.FanDuelFPoints \
    from MLBStartingLineups \
    where (FanDuelSalary != 0) and (FanDuelFPoints != 0) \
    order by FanDuelSalary Desc;"
if VENDOR=='DK':
    qPlayerInfo = \
    "Select \
        MLBStartingLineups.PlayerName, \
        MLBStartingLineups.TeamShort, \
        MLBStartingLineups.PlayerDKPosition, \
        MLBStartingLineups.DraftKingsSalary, \
        MLBStartingLineups.DraftKingsFPoints \
    from MLBStartingLineups \
    where (DraftKingsSalary != 0) and (DraftKingsFPoints != 0) \
    order by DraftKingsSalary Desc;"

cur.execute(qPlayerInfo)
playerInfo = cur.fetchall()

cur.close()
return(playerInfo) # Return All PlayerInfo

########################################################

DimaKudosh commented 5 years ago

Looks like it's problem with pitchers, DK split pitcher position to 2 positions: SP and RP, so optimizer expect players positions as in DK and it can't find any SP/RP in your roster. You can replace P position with SP/RP when you parsing players.

dexter1964 commented 5 years ago

Thank you so much. you were 100% right!!!, I changed my PlayerPosition from "P" to "SP/RP" and it worked perfectly. Thanks again!!!