Git Product home page Git Product logo

dfs-helper-nhl's Introduction

Daily Fantasy Helper (NHL)

What is it?

This repository contains a couple of Python scripts that automate the creation of daily fantasy hockey rosters. It currently uses the Yahoo projected scores (which aren't nearly as bad as their NFL ones..), and scrapes https://goaliepost.com/ to determine starting goaltenders.

Installing dependencies

We'll need a handful of dependencies (beautifulsoup, pandas, and PuLP) for these scripts to work. If you don't already have them installed on your machine, you can install them using the provided requirments.txt file:

> pip3 install -r requirements.txt

Another two dependencies that are (optionally) required for the fetch script is geckodriver and Firefox (the browser). These dependencies must be set up manually, and is as simple as downloading the latest release of geckodriver and extracting the file into this project's directory, and just installing the Firefox application. There is a check in fetch_data.py that looks for ./geckodriver, so if you place the driver anywhere else then there will be some edits involved. geckodriver allows us to use Selenium to scrape websites that might otherwise force requests to solve a captcha, or sites that load their information on a delay using JavaScript to avoid bots from scraping all their juicy information.

How to use:

First you need to fetch the data (salary, DFS game information, and projected scores).

> python fetch_data.py (-p | -f)

Supplying the -p will only print the raw data to the console (which can be piped into the solver script), and -f will only write the raw data to a local json file. Supplying neither will default to both.

Next, the data will need to be supplied to the solver. This can be done by:

> python dfs-solver.py <path-to-file>

or all-in-one by:

> python fetch_data.py -p | python dfs-solver.py

At the moment there's no built-in way to manipulate the json data, so if there's a player you want removed from the solutions (either due to being not active, or personal preference) it's easiest to have the data written to file, remove their entry using a text editor, and then feed the file into the solver.

Initial Thoughts (2022)

I'm a bit late to the party here, I decided to take a look into NHL DFS for the second round of the 2022 Stanley Cup playoffs. Despite that, I was able to play my 5 free placement matches and join a couple of free DFS leagues. At the moment, DFS has been placed into the illegal gambling category in Ontario and all major DFS providers won't allow us to play in paid contests (BOO, and not boo-urns). As a result, I'll be able to play the free leagues, but no more quick matches for me .. :(

gold

Placement matches I went 4-1, getting a Gold ranking and placing into the 73rd percentile. So far so good, and I hope to revisit this once Ontario (hopefully) reverses the ban on DFS.

dfs-helper-nhl's People

Contributors

aptmac avatar

Stargazers

 avatar

Watchers

 avatar

dfs-helper-nhl's Issues

Set up simple builds and hosting

It'd be nice to be able to run the application somewhere and view the results from a browser. There are times I'll be doing errands and won't be at my computer for a while, it'd be nice to be able to retrieve a lineup while on the go.

Perhaps this could be accomplished using GH actions. A daily build at some point when the Yahoo endpoint updates, it could create a simple html page (using GH Pages) displaying the json format that gets outputted from the solver.

Another idea would be to have a Heroku app do a similar thing. On demand, it could run the scripts and print the data out to some endpoint or custom URL. The nice thing with Heroku is I think the free tier would be enough for a small amount of users, and could be activated whenever needed.

Add constraint to prevent certain players from being in the lineup

Making my roster for today I came across a DTD player on my generated roster, and a player than I thought maybe shouldn't be selected. It'd be nice to omit players through the command line by adding a constraint (basically the opposite of: #3), instead of having to manually adjust the json file.

Alternatively, maybe there can be a front end that allows for some GUI to remove players from the json (and include them..)..

Look into other DFS formats

It'd be cool to have this work with whatever other formats are out there (FanDuel, DraftKings, etc.)

They're all illegal in Ontario at the moment so this will have to wait until it's unbanned.

Add alternate option to Yahoo projected scores

Not sure yet where to fetch them from, but these projected scores for NHL look to be as rough as their NFL ones..

Alternatively maybe there's a way to fetch historical data and apply some transformation on the scores. Account for recent averages, establish estimated baseline, etc.

Export rosters to csv for easy importing into Yahoo

Yahoo offers the ability to upload a csv with the roster information you want to use. This would make it easier to automate creating contests, because once the roster is generated it can just be slapped into whatever contests you want.

Add formatter script that transforms the data

At the moment, the rawdata is retrieved by the fetch script, and everything else happens in the solver. It would be nice to pull out any data manipulation to an intermediate script to make everything a bit cleaner.

Things like:

  • injury report
  • healthy scratches
  • starting goalies
  • adding/removing players
  • etc.

Setup unit tests

It would be nice to have tests of some sort to verify behaviour.

Most of the functionality is pretty straightforward or leverages an existing package (pulp, pandas, etc.), But it'd be nice to test error handling and improper usage.

It'd also be nice to test the required pip installed dependencies and setting up the application in a vacuum.

Allow for multiple roster generation

It would be nice if the user could supply a number of rosters to generate, and the solver would create that many rosters.

The way I think it works out is that every time the solver runs it adds new columns to the dataframe that indicates which players were selected in the previous roster(s). A constraint gets added that makes sure the new roster doesn't have the same selected player indexes as any of the previous rosters.

Add constraint for requested players

It would be nice if a list of players could be selected that would be included in the lineup.

For example, tonight's multigame lineup doesn't include McDavid, which outside of the solver sounds like a poor idea. This could be implemented with a new column for "requested" and give the player values a 1.0, and the constraint would just make sure that the number of requested players equals the amount in this column. This might need a bit of tweaking, because requesting too many players could result in an unsolvable team.

Something like:
python dfs_solver.py rawdata/<whatever> request="Connor McDavid,Leon Draisaitl"

Fix Geckodriver pathing for non-Linux

In Windows, geckodriver is geckodriver.exe, and additonally, python isn't a fan of the hardcoded relative path to ./geckodriver

Make sure that the fetch script can run properly in Windows, and improve error handling incase something goes wrong.

Create a script to act as a CLI interface with the application

It would be neat to distribute this as a standalone application or package, and having a CLI interface of some kind might be a good idea.

Some ideas:

  • it would let you know what games are included in the rawdata as single games (in addition to the multigame)
    • by default it will only output the multigame; single game can be asked for based on game id
  • fetch script and solver can be turned into libraries
  • once a game is selected, can have options for:
    • including a player
    • removing a player
    • specifying number of rosters to output
  • have option of loading pre-written json file, or fetching a new one for use; only one rawdata loaded at a time
  • options to export to json/csv (default is print to console)
  • will need to figure out how to silence the pulp runs, they generate a lot of noise
  • try to make this as generic as necessary .. the interface could be standardized and used for the NFL solver, along with any future DFS solvers (soccer, golf, etc.)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.