Giter VIP home page Giter VIP logo

uberfastman / fantasy-football-metrics-weekly-report Goto Github PK

View Code? Open in Web Editor NEW
174.0 19.0 43.0 6.67 MB

Command line application to create weekly reports (containing stats, metrics, and rankings) for Fantasy Football leagues on the following platforms: Yahoo, Fleaflicker, Sleeper, ESPN.

License: GNU General Public License v3.0

Python 99.69% Shell 0.07% Dockerfile 0.24%
sleeper yahoo yahoo-fantasy-football fantasy-football fleaflicker fantasy-football-api yahoo-fantasy-api espn espn-fantasy-football espn-fantasy-api

fantasy-football-metrics-weekly-report's Introduction

Fantasy Football Metrics Weekly Report Stars Forks

Build Status License


Release Last Release Date Version Last Commit


Issues Pull Requests

Active Milestones ➡️ Web App Multi-Platform Support Metrics Maintenance

Completed Milestones ➡️ Yahoo FF Report


Fantasy Football Platform Support: Yahoo, ESPN, Sleeper, Fleaflicker, CBS

You can see an example of what a report looks like here!


Do you like the app? Star the repository here on GitHub and please consider donating to help support its development!

donate-paypal

donate-paypal-qr


Interested in contributing to the project? Help Wanted

Table of Contents


Quickstart Guide

+ NEW (AND EASIER) APPLICATION SETUP BELOW!
  1. Open a command-line interface (see the Command-line section for more details) on your computer.

    • macOS: type Cmd + Space (⌘ + Space) to bring up Spotlight, and search for "Terminal" and hit enter).

    • Windows: type Windows + R to open the "Run" box, then type cmd and then click "OK" to open a regular Command Prompt (or type cmd and then press Ctrl + Shift + Enter to open a Command Prompt as administrator.)

    • Linux (Ubuntu): type Ctrl+Alt+T.

  2. Install Git (see Git section for more details).

    • macOS: run git --version for the first time, and when prompted, install the Xcode Command Line Tools.

    • Windows: Download Git for Windows and install it.

    • Linux (Ubuntu): sudo apt install git-all (see above link for different Linux distributions)

  3. Install Docker Desktop for your operating system.

  4. Clone this app from GitHub (see GitHub section for more details) to wherever you would like to store the app code on your computer (I recommend something like your user Documents folder).

    git clone https://github.com/uberfastman/fantasy-football-metrics-weekly-report.git
  5. Navigate into the cloned app directory within the command line by running:

    cd fantasy-football-metrics-weekly-report
  6. Follow the required setup instructions for whichever fantasy football platform you use: Yahoo, ESPN, Sleeper, or Fleaflicker

  7. Update the values in the .env file (see the Settings section for more details).

    • Alternately, the first time you try running the app it will detect that you have no .env file, and will ask you if you wish to create one. Provide values for the remaining prompts (it will ask you for your fantasy football platform, your league ID, the NFL season (year), and the current NFL week, so have those values ready.
  8. Run the Fantasy Football Metrics Weekly Report app using Docker (see the Running the Report Application section for more details). If on Windows, see the Docker on Windows troubleshooting section if you encounter any permissions or access issues.

    • Run:

      docker compose up -d

      If you wish to see the Docker logs, then run docker compose up.

    • Wait for the above command to complete, then run:

      docker exec -it fantasy-football-metrics-weekly-report-app-1 python main.py
    • Follow the prompts to generate a report for your fantasy league!


About

The Fantasy Football Metrics Weekly Report application automatically generates a report in the form of a PDF file that contains a host of metrics and rankings for teams in a given fantasy football league.

Currently supported fantasy football platforms:

  • Yahoo

  • Fleaflicker

  • Sleeper

  • ESPN

  • CBS

Platforms in development:

  • TBD

Planned platforms:

  • MyFantasyLeague

Example Report

You can see an example of what a report looks like here!

Updating

Every time you run the app it will check to see if you are using the latest version (as long as you have an active network connection). If it detects that your app is out of date, you will see prompt asking you if you wish to update the app. Type y and hit enter to confirm.

If you wish to update the app yourself manually, you can just type n to skip automatically updating, and run git pull origin main manually from within the application directory on the command line.


Dependencies

The application is actively developed in macOS, but is cross-platform compatible. The app requires Python 3.9 or later. To check if you have the minimum required version (or later) of Python installed, open up a window in Terminal (macOS), Command Prompt (Windows), or a command line shell of your choice, and run python --version. If the return value is Python 3.x.x where the first x is equal to or greater than the minimum required minor version, you are good to go. If the return is Python 2.x.x, you will need to install the correct Python 3 version. Check out the instructions here for how to install Python 3 on your system.

Project dependencies can be viewed in the requirements.txt file.


Setup*

The Fantasy Football Metrics Weekly Report requires several sets of setup steps, depending on which platform(s) for which you will be running it. To get the application running locally, you will first need to complete the below setup.

* General setup excludes Google Drive and Slack integrations. See Additional Integrations for details on including those add-ons.


Command-line

Open a command-line terminal/prompt:

  • macOS: type Cmd + Space (⌘ + Space) to bring up Spotlight, and search for "Terminal" and hit enter).

  • Windows: type Windows + R to open the "Run" box, then type cmd and then click "OK" to open a regular Command Prompt (or type cmd and then press Ctrl + Shift + Enter to open a Command Prompt as administrator.)

  • Linux (Ubuntu): type Ctrl+Alt+T.

Git

Install git (if you do not already have it installed). You can see detailed instructions for installation on your OS here.

  • macOS: run git --version for the first time, and when prompted, install the Xcode Command Line Tools.

  • Windows: Download Git for Windows and install it.

  • Linux (Ubuntu): sudo apt install git-all (see above link for different Linux distributions)

NOTE: If you are comfortable using the command line, feel free to just install git for the command line. However, if using the command line is not something you have much experience with and would prefer to do less in a command line shell, you can install Git for Desktop.

***If you use the Git for Desktop client, please keep the project name the same *** (fantasy-football-metrics-weekly-report) or else you will run into additional issues when running the app!

Docker

  • NOTE: This application requires you to have administrative (admin) access for the computer on which you are installing it.

Install Docker for your operating system:

GitHub

Clone this project to whichever directory you wish to use for this app:

  • If you do not have an existing account on GitHub and do not wish to create one, then use HTTPS by running:

    git clone https://github.com/uberfastman/fantasy-football-metrics-weekly-report.git
  • If you already have an account on GitHub, then I recommend using SSH to connect with GitHub by running:

    git clone [email protected]:uberfastman/fantasy-football-metrics-weekly-report.git

Platforms

Yahoo Setup

Yahoo Fantasy Sports has a public API documented here. The Fantasy Football Metrics Weekly Report application uses my own YFPY Python wrapper around this API to retrieve the necessary data to generate reports.

  1. Log in to a Yahoo account with access to whatever fantasy football leagues from which you wish to retrieve data.

  2. Retrieve your Yahoo Fantasy football league id, which you can find by going to https://football.fantasysports.yahoo.com, clicking on your league, and looking here:

    yahoo-fantasy-football-league-id-location.png

  3. Change the LEAGUE_ID value in your .env file to the above located league id.

  4. Go to https://developer.yahoo.com/apps/create/ and create an app (you must be logged into your Yahoo account as stated above). For the app, fill out the following options:

    1. Application Name (Required): yahoo fantasy sports metrics (you must fill out this field, but you can name your app whatever you want).

    2. Description (Optional): you may write a description of what the app does.

    3. Home Page URL (Optional): if you have a web address related to your app you may add it here.

    4. Redirect URI(s) (Required): localhost:8080 (you must fill out this field, but you can use whatever value you want as long as it is a valid redirect address).

    5. OAuth Client Type (Required): this radio button should be automatically set to Confidential Client, so leave it as is (or set it to Confidential Client if it is not selected).

    6. API Permissions (Required): you must check the Fantasy Sports checkbox and leave the Read option selected (appears in an accordion expansion underneath the Fantasy Sports checkbox once you select it).

  5. Click the Create App button.

  6. Once the app is created, it should redirect you to a page for your app, which will show both a Client ID and a Client Secret.

  7. Copy the file private.template.json (located in the auth/yahoo/ directory) and rename the file copy private.json by running the below command in your command line shell:

    • macOS/Linux: cp auth/yahoo/private.template.json private.json auth/yahoo/private.json

    • Windows: copy auth\yahoo\private.template.json auth\yahoo\private.json

  8. Open your new private.json file with your preferred text editor (such as TexEdit in macOS or Notepad in Windows), then copy and paste the Client ID and Client Secret values from your above created Yahoo app to their respective fields (make sure the strings are wrapped regular quotes (""), NOT formatted quotes (“”)). The path to this file will be needed to point the YFPY API wrapper responsible for data retrieval to your credentials.

  9. The first time you run the app, it will initialize the OAuth connection between the report generator and your Yahoo account.

NOTE:If your Yahoo league uses FAAB (Free Agent Acquisition Budget) for player waivers, you must set the YAHOO_INITIAL_FAAB_BUDGET value in the .env file to reflect your league's starting budget, since this information does not seem to be available in the Yahoo API.

You are now ready to generate a report!

Fleaflicker Setup

Fleaflicker has a public API documented here. The Fantasy Football Metrics Weekly Report application uses this API to retrieve the necessary data to generate reports. Please note, some data required to provide certain information to the report is not currently available in the Fleaflicker API, so for the time being web-scraping is used to supplement the data gathered from the Fleaflicker API.

  1. Retrieve your Fleaflicker league ID. You can find it by looking at the URL of your league in your browser:

    fleaflicker-fantasy-football-league-id-location.png

  2. Change the LEAGUE_ID value in the .env file to the above located league id.

  3. Make sure that you have accurately set the value of SEASON in the .env file to reflect the desired year/season for which you are running the report application. This will ensure that the location of locally saved data is correct and API requests are properly formed.

  4. You can also specify the year/season from the command line by running the report with the -y <chosen_year> flag.

  5. Fleaflicker does not require any authentication to access their API at this time, so no additional steps are necessary.

You are now ready to generate a report!

Sleeper Setup

Sleeper has a public API documented here. The Fantasy Football Metrics Weekly Report application uses this API to retrieve the necessary data to generate reports. Please note, some data required to provide certain information to the report is not currently available in the Sleeper API, so a few small things are excluded in the report until such a time as the data becomes available. That being said, the missing data does not fundamentally limit the capability of the app to generate a complete report.

  1. Retrieve your Sleeper league ID. You can find it by looking at the URL of your league in your browser:

    sleeper-fantasy-football-league-id-location.png

  2. Change the LEAGUE_ID value in the .env file to the above located league id.

  3. (Optional) It is advised that you accurately set the CURRENT_NFL_WEEK value in the .env file to reflect the current/ongoing NFL week at the time of running the report, as the report will default to this value if retrieving the current NFL week from the Sleeper API (which the app uses to fetch the current NFL week) is unsuccessful.

You are now ready to generate a report!

ESPN Setup

ESPN has an undocumented public API which changed from v2 to v3 in 2018 and introduced some variance to its functionality, and as such is subject to unexpected and sudden changes. The Fantasy Football Metrics Weekly Report application uses this API to retrieve the necessary data to generate reports. Please note, some data required to provide certain information to the report is not currently available in the ESPN API, so a few small things are excluded in the report until such a time as the data becomes available. That being said, the missing data does not fundamentally limit the capability of the app to generate a complete report.

  1. Retrieve your ESPN league ID. You can find it by looking at the URL of your league in your browser:

    espn-fantasy-football-league-id-location.png

  2. Change the LEAGUE_ID value in the .env file to the above located league id.

  3. Make sure that you have accurately set the SEASON value in the .env file to reflect the desired year/season for which you are running the report application. This will ensure that the location of locally saved data is correct and API requests are properly formed.

  4. You can also specify the year/season from the command line by running the report with the -y <chosen_year> flag.

  5. Public ESPN leagues do not require any authentication to access their API at this time, so no additional steps are necessary for those leagues. However, certain data will not be available if you are not authenticated, so it is advised for you to still follow the below authentication steps anyway. For private leagues, you must complete one of the following authentication processes.

    1. Allow the app to automatically retrieve your ESPN session cookies for you:

      1. Copy the file private.template.json (located in the auth/espn/ directory), and rename the file copy private.json by running the below command in your command line shell:

        • macOS/Linux: cp auth/espn/private.template.json private.json auth/espn/private.json

        • Windows: copy auth\espn\private.template.json auth\espn\private.json

      2. Open your new private.json file with your preferred text editor (such as TexEdit in macOS or Notepad in Windows), delete the swid and espn_s2 fields, and add your ESPN account username and password to their respective fields. Please note, the FFMWR app does not store any of your credentials, it simply uses them to log in to your account and obtain session cookies. The app uses Selenium to run a headless browser to log in to ESPN on your behalf, so expect to see an email alerting you to a new device login. The Selenium process will retrieve your ESPN session cookies (SWID and espn_s2) and copy them into your private.json file for reuse with future ESPN API authentication.

    2. Manually retrieve your ESPN session cookies:

      1. Steven Morse has done a great deal of fantastic work to help teach people how to use the ESPN fantasy API, and has a useful blog post here detailing how to get your own session cookies. As stated in the aforementioned blog, you can get the cookies following the subsequent steps.

      2. "A lot of the ESPN Fantasy tools are behind a login-wall. Since accounts are free, this is not a huge deal, but becomes slightly annoying for GET requests because now we somehow need to “login” through the request. One way to do this is to send session cookies along with the request. Again this can take us into a gray area, but to my knowledge there is nothing prohibited about using your own cookies for personal use within your own league."

        Specifically, our GET request from the previous post is modified to look like, for example:

        r = requests.get(
            'https://games.espn.com/ffl/api/v2/scoreboard', 
            params={'leagueId': 123456, 'seasonId': 2023, 'matchupPeriodId': 1},
            cookies={'swid': '{SWID-COOKIE-HERE}', 'espn_s2': 'LONG_ESPN_S2_COOKIE_HERE'}
        )

        This should return the info you want even for a private league. I saw that the SWID and the ESPN_S2 cookies were the magic tickets based on the similar coding endeavors here and here and here.

        You can find these cookies in Safari by opening the Storage tab of Developer tools (you can turn on developer tools in preferences), and looking under espn.com in the Cookies folder. In Chrome, you can go to Preferences -> Advanced -> Content Settings -> Cookies -> See all cookies and site data, and looking for ESPN.

      3. Depending on what web browser (Firefox, Chrome, Edge, Brave, etc.) you are using, the process for viewing your session cookies in the web inspector will be different. I recommend Googling "how to inspect element in [browser]" (for your specific browser) to learn how to use that browser's web inspector.

      4. Copy the file private.template.json (located in the auth/espn/ directory), and rename the file copy private.json by running the below command in your command line shell:

        • macOS/Linux: cp auth/espn/private.template.json private.json auth/espn/private.json

        • Windows: copy auth\espn\private.template.json auth\espn\private.json

      5. Open your new private.json file with your preferred text editor (such as TexEdit in macOS or Notepad in Windows), then copy and paste the above cookies into their respective fields. Please note, the swid will be surrounded by curly braces ({...}), which must be included.

NOTE: *Because ESPN made the change to their API between 2018 and 2019, ESPN support in the Fantasy Football Metrics Weekly Report application is currently limited to the 2019 season and later. Support for historical seasons will (hopefully) be implemented at a later time.

You are now ready to generate a report!

CBS Setup

CBS has a public API that was once documented, the last version of which can be viewed using the Wayback machine here. The Fantasy Football Metrics Weekly Report application uses this API to retrieve the necessary data to generate reports. Please note, some data required to provide certain information to the report is not currently available in the CBS API, so a few small things are excluded in the report until such a time as the data becomes available. That being said, the missing data does not fundamentally limit the capability of the app to generate a complete report.

  1. Retrieve your CBS league ID. You can find it by looking at the URL of your league in your browser:

    cbs-fantasy-football-league-id-location.png

  2. Change the LEAGUE_ID value in the .env file to the above located league id.

  3. The CBS API requires authentication to retrieve your league data, so you will need to use your CBS credentials to do so. Copy the file private.template.json (located in the auth/cbs/ directory), and rename the file copy private.json by running the below command in your command line shell:

    • macOS/Linux: cp auth/cbs/private.template.json private.json auth/cbs/private.json

    • Windows: copy auth\cbs\private.template.json auth\cbs\private.json

  4. Open your new private.json file with your preferred text editor (such as TexEdit in macOS or Notepad in Windows), then update the respective fields with your LEAGUE_ID, CBS username, and CBS password. Please note, the FFMWR app does not store any of your credentials, it simply uses them to log in to your account and obtain an API access token. All values added to private.json must be surrounded by regular quotes (""), NOT formatted quotes (“”)).

  5. The first time you run the app, it will retrieve an API access token using your credentials and store it in the auth/cbs/private.json file. All subsequent runs of the report will simply use this access token to authenticate with the CBS API instead of your CBS credentials, so if you prefer you can delete your CBS username and CBS password from the file.

You are now ready to generate a report!

Running the Report Application

  1. Make sure you have updated the default league ID (LEAGUE_ID in the .env file) to your own league id. Please see the respective setup instructions for your chosen platform for directions on how to find your league ID.

  2. From within the application directory (you should already be inside the fantasy-football-metrics-weekly-report directory) , run:

    docker compose up -d
    1. FIRST TIME RUNNING: The first time you run the above command, you must wait for the Docker image to be pulled from the GitHub Container Registry. You will see output containing progress bars as the image layers are downloaded.

      NOTE: If you are running Docker for Windows and you see errors when trying to build the Docker container and/or run docker compose up -d, please go to the Docker on Windows section in Troubleshooting for workarounds!

    2. ALL RUNS: After the initial run of the Docker container, you will not see all the image pull output as you did the first time. However, for all runs you will know when the app is ready when you see the below output:

      fantasy-football-metrics-weekly-report-app-1  | Fantasy Football Metrics Weekly Report app is ready!
    3. The docker image is now running and ready for use!

  3. Run the report:

    docker exec -it fantasy-football-metrics-weekly-report-app-1 python main.py
    1. You should see the following prompts:

      1. Generate report for default league? (y/n) -> .

        Type y and hit enter.

      2. Generate report for default week? (y/n) ->.

        Type y and hit enter.

      3. NOTE FOR YAHOO USERS ONLY: The FIRST time you run the app, you will see an AUTHORIZATION URL (if you followed the instructions in the Yahoo Setup section).

        1. Click the link (or copy and paste it into your web browser).

        2. The browser window should display a message asking for access to Yahoo Fantasy Sports on your account. Click Accept.

        3. You should then see a verifier code (something like w6nwjvz). Copy the verifier code and return to the command line window, where you should now see the following prompt:

          Enter verifier :

          Paste the verifier code there and hit enter.

        4. Assuming the above went as expected, the application should now generate a report for your Yahoo fantasy league for the selected NFL week.

  4. When you are done using the report app, it is recommended that you shut down the Docker container in which it is running. You can do so by running:

    docker compose down

The next time you run the app, you can simply re-run docker compose up -d to restart the container.

NOTE: You can also specify a large number of settings directly in the command line. Please see the usage section for more information.


Settings

The Fantasy Football Metrics Weekly Report application allows certain aspects of the generated report to be set using a .env file, which defines a set of environment variables the app reads when it runs. The first time you run the FFMWR app without a .env file present, it will ask you if you would like to generate one and prompt you for several initial values for the file. It will then create a .env file in the root directory of the app which will be populated by a selection of default values (all of which can be changed as needed).

The app REQUIRES that a .env be present, so it is recommended that you allow the app to generate a default .env file for you and then update the values to reflect the league for which you wish to generate a report, as well as modify any other settings you wish to change from the default values.

Report Features

For those of you who wish for the report to include a custom subset of the available features (for instance, if you want league stats but not team pages, or if you want score rankings but not coaching efficiency), the REPORT SETTINGS section in the .env file allows all features to be turned on or off. You must use a boolean value (True or False) to turn on/off any of the available report features, which are the following:

LEAGUE_STANDINGS_BOOL=True
LEAGUE_PLAYOFF_PROBS_BOOL=True
LEAGUE_MEDIAN_STANDINGS_BOOL=True
LEAGUE_POWER_RANKINGS_BOOL=True
LEAGUE_Z_SCORE_RANKINGS_BOOL=True
LEAGUE_SCORE_RANKINGS_BOOL=True
LEAGUE_COACHING_EFFICIENCY_RANKINGS_BOOL=True
LEAGUE_LUCK_RANKINGS_BOOL=True
LEAGUE_OPTIMAL_SCORE_RANKINGS_BOOL=True
LEAGUE_BAD_BOY_RANKINGS_BOOL=True
LEAGUE_BEEF_RANKINGS_BOOL=True
LEAGUE_WEEKLY_TOP_SCORERS_BOOL=True
LEAGUE_WEEKLY_HIGHEST_CE_BOOL=True
REPORT_TIME_SERIES_CHARTS_BOOL=True
REPORT_TEAM_STATS_BOOL=True
TEAM_POINTS_BY_POSITION_CHARTS_BOOL=True
TEAM_BAD_BOY_STATS_BOOL=True
TEAM_BEEF_STATS_BOOL=True
TEAM_BOOM_OR_BUST_BOOL=True

Report Formatting

The report can also have some of its visual formatting set. The following formatting options are available:

FONT=helvetica
SUPPORTED_FONTS_LIST=helvetica,times,symbola,opensansemoji,sketchcollege,leaguegothic
FONT_SIZE=12
IMAGE_QUALITY=75
MAX_DATA_CHARS=24

The values seen in the SUPPORTED_FONTS_LIST environment variable are the currently supported fonts for the app.

The player headshots retrieved for individual team pages can come in varying resolutions, and when they are extremely high resolution, they can inflate the size of the report PDF. In order to allow the user to reduce the size of the final report PDF if desired, the following option is available:

IMAGE_QUALITY=75

The default value for the image quality is 75%, allowing for a reasonable reduction in image size without sacrificing overall aesthetic quality. However, this value can be set on a scale of 0%-100%, depending on the preferences of the user.

Once the initial images have been retrieved and quality has been adjusted, the report will cache those images and continue to use those indefinitely until you delete the output/data/<YEAR>/<LEAGUE_ID>/week_<WEEK_#>/player_headshots for that week, since otherwise the images would continue to have their quality reduced until the headshots degraded entirely.

Report Settings

In addition to turning on/off the features of the report PDF itself, there are additional setting, which are as follows:

Option Description
PLATFORM Fantasy football platform for which you are generating a report.
SUPPORTED_PLATFORMS_LIST Comma-delimited list (with no spaces between items) of currently supported fantasy football platforms.
LEAGUE_ID The league id of the fantasy football for which you are running the report.
DATA_DIR_LOCAL_PATH Directory where saved data is stored.
OUTPUT_DIR_LOCAL_PATH Directory where generated reports are created.
WEEK_FOR_REPORT Selected NFL season week for which to generate a report.
NUM_PLAYOFF_SIMULATIONS Number of Monte Carlo simulations to run for playoff predictions. The more sims, the longer the report will take to generate.
NUM_REGULAR_SEASON_WEEKS Number of regular season weeks in selected league.
NUM_PLAYOFF_SLOTS Number of playoff slots in selected league.
NUM_PLAYOFF_SLOTS_PER_DIVISION Numbers of teams per division that qualify for the playoffs.
COACHING_EFFICIENCY_DISQUALIFIED_TEAMS_LIST Comma-delimited list (with no spaces between items and surrounded by quotes) of teams manually disqualified from coaching efficiency rankings (if any).
GOOGLE_DRIVE_UPLOAD_BOOL Turn on (True) or off (False) the Google Drive upload functionality.
GOOGLE_DRIVE_AUTH_TOKEN_LOCAL_PATH Google OAuth refresh token.
GOOGLE_DRIVE_FOLDER_PATH Online folder in Google Drive where reports are uploaded.
GOOGLE_DRIVE_REUPLOAD_FILE_LOCAL_PATH File path of selected report that you wish to re-upload to Google Drive by running upload_to_google_drive.py as a standalone script.
SLACK_POST_BOOL Turn on (True) or off (False) the Slack upload functionality.
SLACK_AUTH_TOKEN_LOCAL_PATH Slack authentication token.
SLACK_POST_OR_FILE Choose whether you post a link to the generated report on Slack (set to post), or upload the report PDF itself to Slack (set to file).
SLACK_CHANNEL Selected Slack channel where reports are uploaded.
SLACK_CHANNEL_NOTIFY_BOOL Turn on (True) or off (False) using the @here slack tag to notify chosen Slack channel of a posted report file.
SLACK_REPOST_FILE_LOCAL_PATH File path of selected report that you wish to repost to Slack.

Usage

After completing the above setup and settings steps, you should now be able to simply run docker exec -it fantasy-football-metrics-weekly-report_app_1 python main.py to regenerate a report. The report generator script (main.py) also supports several command line options/arguments that allow you to specify the following:

Flag Description
-h, --help Display command line usage message
-d, --use-default Automatically run the report using the default settings without user input prompts.
-f, --fantasy-platform <platform> Fantasy football platform on which league for report is hosted.
-l, --league-id <league_id> Fantasy Football league ID
-w, --week <week> Chosen week for which to generate report
-g, --game-id <game_id> Chosen fantasy game id for which to generate report. Defaults to "nfl", interpreted as the current season if using Yahoo.
-y, --year <year> Chosen year (season) of the league for which a report is being generated.
-s, --save-data Save all retrieved data locally for faster future report generation
-s, --refresh-web-data Refresh all web data from external APIs (such as bad boy and beef data)
-p, --playoff-prob-sims <int> Number of Monte Carlo playoff probability simulations to run."
-b, --break-ties Break ties in metric rankings
-q, --disqualify-ce Automatically disqualify teams ineligible for coaching efficiency metric
-o, --offline Run OFFLINE (for development). Must have previously run report with -s option.
-t, --test Generate TEST report (for development)

NOTE: all command line arguments OVERRIDE any settings in the local .env file!

Example:
docker exec -it fantasy-football-metrics-weekly-report_app_1 python main.py -l 140941 -f fleaflicker -y 2020 -w 3 -p 1000 -s -r

The above command runs the report with the following settings (which override anything set in the .env file):

  • Platform: fleaflicker

  • League id: 140941

  • NFL season: 2020

  • NFL week: 3

  • Number of Monte Carlo simulations for playoff probabilities: 1000

  • Saves the data locally (-s)

  • Refreshes any previously saved local data (-r)


Additional Integrations

The Fantasy Football Metrics Weekly Report application also supports several additional integrations if you choose to utilize them. Currently, it is capable of uploading your generated reports to Google Drive, and also directly posting your generated reports to the Slack Messenger app.

Google Drive Setup

The Fantasy Football Metrics Weekly Report application includes Google Drive integration, allowing your generated reports to be uploaded and stored in Google Drive, making it easy to share the report with all league members.

The following setup steps are required in order to allow the Google Drive integration to function properly:

  1. Log in to your Google account (or make one if you don't have one).

  2. Create a new project in the Google Developers Console.

  3. Accept the terms & conditions.

  4. Name your project, something like ff-report-drive-uploader, but it can be anything you like.

  5. Click CREATE.

  6. It will take a few moments for the project to be created, but once it is there will be a notification.

  7. Go to the Google Developers Console.

  8. Your new project should automatically load in the dashboard, but in the event it does not, or you have other projects (a different project might load by default), click the project name on the top left of the page (to the right of where it says "Google APIs"), and select your new project.

  9. Either click the + ENABLE APIS AND SERVICES button on the top of the page, or select "Library" from the menu on the left, search for Google Drive API, and click Google Drive API when it comes up.

  10. Click ENABLE.

  11. After a moment it will be enabled. Click Credentials from the left menu and then click CREATE CREDENTIALS.

  12. From the menu that drops down, select OAuth client ID.

  13. Click on Configure Consent Screen.

  14. Select Internal for the User Type then click CREATE.

  15. Put yff-report-drive-uploader in Application name.

  16. Select your email from the dropdown under User support email.

  17. Enter your email again in the Developer contact information field.

  18. Click SAVE AND CONTINUE.

  19. Click ADD OR REMOVE SCOPES, search for google drive in the filter, check the box next to the ../auth/drive scope, and click UPDATE at the bottom.

  20. Click SAVE AND CONTINUE.

  21. Now go click Credentials again from the left menu and click CREATE CREDENTIALS, then select OAuth client ID.

  22. Select Desktop app from the dropdown menu, and put yff-report-drive-uploader-client-id.

  23. Click CREATE.

  24. A popup with your client ID and client secret will appear. Click OK.

  25. On the far right of your new credential, click the little arrow that displays Download OAuth Client when you hover over it, then click DOWNLOAD JSON.

  26. Your credentials JSON file will download. Rename it credentials.json, and put it in the auth/google/ directory where credentials.template.json is located.

  27. Open a terminal window (makes sure you are inside the fantasy-football-metrics-weekly-report directory), and run:

    docker exec -it fantasy-football-metrics-weekly-report_app_1 python resources/google_quickstart.py --noauth_local_webserver
  28. You will see a message that says Go to the following link in your browser:, followed by a link. Copy the URL and paste it into a web browser, and hit enter. The open window will ask you to either select a Google account to log into (if you have multiple) or log in. Select your account/login.

  29. A warning screen will appear saying "This app isn't verified". Click "Advanced" and then "Go to yff-report-drive-uploader (unsafe)" (this screen may vary depending on your web browser, but the point is you need to proceed past the warning).

  30. On the next screen, a popup saying "Grant yff-report-drive-uploader permission" will appear. Click "Allow", then "Allow" again on the following "Confirm your choices" screen.

  31. Next you will see a screen that says only "Please copy this code, switch to your application and paste it there:". Copy the code, and return to your open terminal window (you can close the browser window once you've copied the verification code).

  32. Paste the verification code where it says Enter verification code:, and hit enter.

  33. You should then see the command line output "Authentication successful.", as well as a list of 10 files in your Google Drive to confirm it can access your drive. It will also have automatically generated a token.json file in auth/google/, which you should just leave where it is and do NOT edit or modify in any way!

  34. You can now upload your reports to Google Drive in one of two ways listed below. Please note, if you wish to specify where the app will upload the report to in Google Drive, change the value of GOOGLE_DRIVE_FOLDER_PATH in the .env file to whatever path you wish to store the reports in Google Drive, such as Fantasy_Football/reports. If you do not put a path in this value the report will default to uploading files to a Fantasy_Football directory at the root of your Google Drive.

    1. Change GOOGLE_DRIVE_UPLOAD_BOOL to True in the .env file and generate a new report. You will see a message at the end of the run that indicates the report PDF was successfully uploaded to Google Drive, and provides the direct share link to the file.

      OR

    2. Set the value of GOOGLE_DRIVE_REUPLOAD_FILE_LOCAL_PATH in the .env file to the local filepath of the report you wish to upload, opening a Terminal window, and running python integrations/drive.py*. This only works for preexisting reports that you have already generated, and will then upload that report to Google Drive without generating a new one.


Slack Setup

The Fantasy Football Metrics Weekly Report application includes integration with the popular personal and business chat app Slack, allowing your generated reports (or links to where they are stored on Google Drive) to be uploaded directly to Slack, making it easy to share the report with all league members.

The following setup steps are required in order to allow the Slack integration to function properly:

  1. Sign in to your slack workspace here.

  2. Once logged in, you need to create a new app for your workspace.

  3. After the popup appears, fill in the fields as follows:

    • i. App Name: ff-report (this name can be anything you want)

    • ii. Development Slack Workspace: Select your chosen Slack workspace from the dropdown menu.

  4. Click Create App. You should now be taken to the page for your new app, where you can set things like the app title card color, the icon, the description, as well as a whole host of other features (see here for more information).

  5. Select Basic Information from the menu on the left.

  6. Scroll down to Display Information and set up your Slack app with whatever display settings you want.

  7. Scroll up to Building Apps for Slack and click Bots.

  8. You will be taken to the App Home section of the menu on the left.

  9. Click the Review Scopes to Add button.

  10. You will be taken to the OAuth & Permissions section of the menu on the left.

  11. Scroll down to Scopes.

  12. Under Bot Token Scopes, click the Add an OAuth Scope button.

  13. From the dropdown menu, select the below scopes:

    | OAuth Scope | Description | |:-----------------------|:------------------------------------------------------------------------------------| | channels:read | View basic information about public channels in the workspace | | chat:write | Send messages as @ff-report | | chat:write.customize | Send messages as @ff-report with a customized username and avatar | | chat:write.public | Send messages to channels @ff-report isn't a member of | | files:write | Upload, edit, and delete files as ff-report | | groups:read | View basic information about private channels that ff-report has been added to | | im:read | View basic information about direct messages that ff-report has been added to | | incoming-webhook | Post messages to specific channels in Slack | | mpim:read | View basic information about group direct messages that ff-report has been added to |

  14. Scroll back up to OAuth Tokens & Redirect URLs, and now you should be able to click the Install App to Workspace button, so click it.

  15. You will be redirected to a screen saying your app is asking for permission to access the Slack workspace, and presenting you with a dropdown to select a channel for your app to post to. Select your desired channel, and hit Allow.

  16. You will now be redirected back to the OAuth & Permissions section of your app settings. At the top, you will see a Bot User OAuth Access Token field, which will now have a value populated.

  17. Copy the file token.template.json (located in the auth/slack/ directory), and rename the file copy token.json, then copy and paste the above Bot user OAuth Access Token into the field value of token.json where it says "SLACK_APP_OAUTH_ACCESS_TOKEN_STRING", replacing that string. Make sure you are using double quotes (") on either side of your token string.

  18. If you are posting to a private channel, you will need to invite the bot to the channel before it can make posts there. Just go to the Slack channel and type @ff-report, and then hit enter. Slack will ask if you wish to invite the bot to the channel, so confirm that you wish to add the bot to the channel, and now it should be able to post to the private channel.

  19. You can now upload your reports to Slack, either by updating the following values in the .env file:

    • i. SLACK_POST_BOOL=True

    • ii. SLACK_CHANNEL=channel-name (this can be set to whichever channel you wish to post (as long as the user who created the app has access to that channel)

    Or by setting the value of SLACK_REPOST_FILE_LOCAL_PATH in the .env file to the filepath of the report you wish to upload, opening a Terminal window, and running python integrations/slack.py.


Troubleshooting

Logs

In addition to displaying output from the application to the command line, the Fantasy Football Metrics Weekly Report also logs all the same output to out.log, which you can view at any time to see output from past runs of the application.

Yahoo

Occasionally when you use the Yahoo fantasy football API, there are hangups on the other end that can cause data not to transmit, and you might encounter an error similar to this:

Traceback (most recent call last):
  File "yfpy-app.py", line 114, in <module>
    var = app.run()
  File "/Users/your_username/PATH/T0/LOCAL/PROJECT/yfpy-app.py", line 429, in run
    for team in team_standings:
IndexError: list index out of range

Typically, when the above error (or a similar error) occurs, it simply means that one of the Yahoo Fantasy Football API calls failed and so no data was retrieved. This can be fixed by simply re-running data query.

Docker on Windows

If you are running Docker on Windows, you might encounter errors when trying to build the Docker image and/or run docker compose up -d. Typically, these errors revolve around the way Windows strictly enforces file access permissions. There are two known permissions issues (and workarounds) currently for running the FFMWR app.

  1. If you are running on Windows 10 Enterprise, Pro, or Education (all of which support the Hyper-V feature), then the latest version of Docker for Windows requires you to specifically give Docker permission to access any files and directories you need it to be able to see.

    1. In order to do so, open up Docker for Windows, and go to settings:

      docker-settings.png

    2. Then click the following items in order (stop between 3 and 4):

      docker-file-sharing.png

    3. After clicking the + button to add a directory, select the FFMWR app directory (which will be wherever you cloned it), or any parent directory of the app directory, and add it. Then click Apply & Restart.

    4. Now go back to your command line shell, make sure you are in the FFMWR app directory, and re-run docker compose up -d. This time things should build and startup as expected without any errors, and you can pick up where you left of with Running the Report Application!

  2. If you are running on Windows 10 Home (which does not support the Hyper-V feature), then Docker for Windows does not have the File Sharing option discussed above for Windows 10 Enterprise, Pro, and Education users. However, you might still run into similar permissions issues. The below steps should provide a workaround to just sharing the files in Docker Desktop for Windows:

    1. Type Windows + X. You will see a small pop-up list containing various administrator tasks.

    2. Select Command Prompt (Admin).

    3. Use cd commands to navigate to whichever directory you cloned the FFMWR app into (e.g. cd ~\Documents\fantasy-football-metrics-weekly-report\).

    4. Now from within that command prompt shell (which has privileged admin access), you should be able to re-run docker compose up -d, wait for everything to build and start running, and then pick up where you left of with Running the Report Application. Remember to stay in the admin command prompt shell to give your command the right file access!

Reportlab

On macOS 12+ (Monterey) or on Macs using the M1/M2 ARM architecture, you might encounter the following error (or one like it) during dependency installation:

Symbol not found in flat namespace '_FT_Done_Face' from reportlab with [email protected] on macOS 12

You may need to force pip to reinstall the reportlab library using the following command:

pip install reportlab --force-reinstall --no-cache-dir --global-option=build_exta

fantasy-football-metrics-weekly-report's People

Contributors

markwhat1 avatar ragnarok56 avatar softsign avatar uberfastman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fantasy-football-metrics-weekly-report's Issues

Advanced Luck Metric

As proposed by @ragnarok56 previously, it would be nice to add a column to the luck table with a weighted luck metric that uses the z-scores of both teams in a matchup to weigh those teams' luck scores based on whether or not each team overperformed/underperformed.

See #27 and #30 for reference.

Chanel_Not_Found Slack Integration

Having trouble with Slack integration. Added app following instructions exactly. Edited token and config. When I run the report, I get "integrations.slack_integration - ERROR - Slack client error: The request to the Slack API failed. The server responded with: {'ok': False, 'error': 'channel_not_found'}". It's a private channel, but I chose it from the list when installing app and it shows I added an integration in the channel. Tried googling on my own, I added bot user to channel. I tried formatting the name differently in config, including trying to use channel ID instead of name, with and without quotes, with or without #

No module named integrations.drive_integration

Not sure what's happening as I have changed anything since last week except for pulling the latest, but I know get the following error when running:

Running Fantasy Football Metrics Weekly Report application from within virtual environment...
Traceback (most recent call last):
  File "main.py", line 14, in <module>
    from integrations.drive_integration import GoogleDriveUploader
ImportError: No module named integrations.drive_integration
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

Handle all Flex permutations

Currently the coaching efficiency calculations and player points by position will be messed up by unusual flex positions, or leagues that have multiple "types" of flex positions (WR/RB/TE and WR/RB, for instance). Currently if a league has one "regular" flex and one super flex (WR/RB/TE/QB) everything works, but this will still likely be an issue later, and so handling of flexes should be improved.

Yahoo headshots config option

Currently the Yahoo reports use the high resolution headshots, which make the report PDFs enormous. There should be an option to use the low resolution thumbnails if users desire.

Unless -p is defined at runtime report errors out.

Running latest commit from develop.

Exception has occurred: TypeError
int() argument must be a string, a bytes-like object or a number, not 'NoneType'
File ".\report\pdf\generator.py", line 81, in init
self.playoff_prob_sims = int(playoff_prob_sims)
File ".\report\builder.py", line 305, in create_pdf_report
report_data=report_data
File ".\main.py", line 231, in
report_pdf = report.create_pdf_report()

KeyError: '24' when generating ESPN report

Running a report for an ESPN league and I get "KeyError: '24'"

Here is the output of the report generator:

Running Fantasy Football Metrics Weekly Report application from within virtual environment...
Generate report for default league? (y/n) -> y
Generate report for default week? (y/n) -> y
2020-09-11 00:34:39,595 - report.builder - INFO - 
Generating Espn Fantasy Football report with settings:
    league id: 264523
    game id: nfl
    week: selected/default
    save_data: False
    refresh_web_data: False
    playoff_prob_sims: None
    break_ties: False
    dq_ce: False
    dev_offline: False
    test: False
on Sep 11, 2020...
2020-09-11 00:34:39,601 - report.builder - INFO - Retrieving fantasy football data from Espn API...
The first week of the season is not yet complete. Are you sure you want to generate a report for an incomplete week? (y/n) -> y
Traceback (most recent call last):
  File "main.py", line 253, in <module>
    options.get("test", False))
  File "main.py", line 166, in select_league
    test=test)
  File "/Users/myuser/Documents/fantasy-football/fantasy-football-metrics-weekly-report/report/builder.py", line 116, in __init__
    dev_offline=self.dev_offline
  File "/Users/myuser/Documents/fantasy-football/fantasy-football-metrics-weekly-report/dao/utils.py", line 144, in league_data_factory
    dev_offline
  File "/Users/myuser/Documents/fantasy-football/fantasy-football-metrics-weekly-report/dao/espn.py", line 87, in __init__
    self.matchups_by_week[str(week_for_matchups)] = self.league.box_scores(int(week_for_matchups))
  File "/Users/myuser/Documents/fantasy-football/fantasy-football-metrics-weekly-report/dao/espn.py", line 524, in box_scores
    box_data = [BoxScore(matchup, pro_schedule, positional_rankings, week) for matchup in schedule]
  File "/Users/myuser/Documents/fantasy-football/fantasy-football-metrics-weekly-report/dao/espn.py", line 524, in <listcomp>
    box_data = [BoxScore(matchup, pro_schedule, positional_rankings, week) for matchup in schedule]
  File "/Users/myuser/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.7/site-packages/ff_espn_api/box_score.py", line 9, in __init__
    self.home_lineup = [BoxPlayer(player, pro_schedule, positional_rankings, week) for player in home_roster]
  File "/Users/myuser/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.7/site-packages/ff_espn_api/box_score.py", line 9, in <listcomp>
    self.home_lineup = [BoxPlayer(player, pro_schedule, positional_rankings, week) for player in home_roster]
  File "/Users/myuser/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.7/site-packages/ff_espn_api/box_player.py", line 25, in __init__
    self.pro_pos_rank = positional_rankings[str(player['defaultPositionId'])][str(opp_id)]
KeyError: '24'
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

[Process completed]

Coaching efficiency tie-break for non-first

Currently, if there are coaching efficiency ties for places other than first, it still triggers the tied coaching efficiency report table additional columns. However, the coaching efficiency tie-break only resolves ties for first, since it requires separate REST API calls for each player for each past week. As such, it messes up the columns.

Playoff predictions can't be used retroactively

Currently the Monte Carlo simulations used to create the playoff predictions use the current league standings data as a starting point. However, Yahoo's API seems to only provide the current standings, not the standings from a chosen week, which means if you run the playoff predictions for any week besides the current one they will not necessarily be correct, and can even run into an "index out of bounds" error.

To fix this, a custom Standings object needs to be built for each week using the results of that week's matchups, and then passed to the playoff probability calculator in order to emulate if Yahoo provided the chosen week's league standings.

Coaching efficiency over 100%

Hey Uber,

Just ran a report for a league of mine and coaching efficiency is showing at over 100% for several teams.

League number is 39617, Yahoo.

Thanks!

Week 2 report failing

Trying to run the report for my ESPN league 321902

I dont know if i have a setting in the league that is causing issues or if im missing something in a config but I can not run report for week 2. I can successfully run week 1 report but if I try default week or even week 2 I get the following. Im not sure where the week1 metrics info coming from?

2020-09-23 08:08:02,898 - report.data - INFO -

              SCORE tie(s): 0
COACHING EFFICIENCY tie(s): 0

Traceback (most recent call last):
  File "main.py", line 254, in <module>
    report_pdf = report.create_pdf_report()
  File "C:\FFReport\report\builder.py", line 192, in create_pdf_report
    custom_weekly_matchups = self.league.get_custom_weekly_matchups(str(week_counter))
  File "C:\FFReport\dao\base.py", line 172, in get_custom_weekly_matchups
    winning_team = matchup.winner.team_id
AttributeError: 'NoneType' object has no attribute 'team_id'

error with positions

Hello, my league has an additional flex position that your script doesn't handle. Its a sleeper league and the api is REC_FLEX can be WR or TE. could you add this to the script. In the meantime I'll try to see if I can add it to the if check on the sleeper.py file.

Generify Report Data

As the first step towards supporting additional platforms, the league data needs to use custom object types that can have various platform API data mapped to them.

Support for divisions

Currently there has been no testing at all for support of divisions. Eventually the report should support divisions, although it could require significant work to do so.

SSL validation error for nflarrest.com

Hey - I'm getting the below error when trying to generate a report. I'm getting ESPN data successfully, but can't seem to get past this.... Any help would be appreciated!

  • I'm using pyenv but I don't think that would affect this.
  • Is there a way to easily ignore the hostname miss-match?
  • Can I just disable the part of the report that comes from nflarrest.com?-- in the config.ini I tried league_bad_boy_rankings = False but that didn't seem to help, it still tries to get the data.
fantasy-football-metrics-weekly-report > python main.py   
Generate report for default league? (y/n) -> y
Generate report for default week? (y/n) -> y
2020-09-09 09:49:51,191 - report.builder - INFO - 
Generating Espn Fantasy Football report with settings:
    league id: XXREDACTED
    game id: nfl
    week: selected/default
    save_data: False
    refresh_web_data: False
    playoff_prob_sims: None
    break_ties: False
    dq_ce: False
    dev_offline: False
    test: False
on Sep 09, 2020...
2020-09-09 09:49:51,191 - report.builder - INFO - Retrieving fantasy football data from Espn API...
2020-09-09 09:50:20,014 - report.builder - INFO - ...retrieved all fantasy football data from Espn API in 0:00:28.822987

2020-09-09 09:50:20,015 - report.builder - INFO - Retrieving bad boy data from http://nflarrest.com website...
2020-09-09 09:50:20,146 - urllib3.connection - WARNING - Certificate did not match expected hostname: nflarrest.com. Certificate: {'subject': ((('countryName', 'US'),), (('stateOrProvinceName', 'California'),), (('localityName', 'San Francisco'),), (('organizationName', 'GitHub, Inc.'),), (('commonName', 'www.github.com'),)), 'issuer': ((('countryName', 'US'),), (('organizationName', 'DigiCert Inc'),), (('organizationalUnitName', 'www.digicert.com'),), (('commonName', 'DigiCert SHA2 High Assurance Server CA'),)), 'version': 3, 'serialNumber': '02493E07FA9E375A2DBBC61D94430FCF', 'notBefore': 'May  6 00:00:00 2020 GMT', 'notAfter': 'Apr 14 12:00:00 2022 GMT', 'subjectAltName': (('DNS', 'www.github.com'), ('DNS', '*.github.com'), ('DNS', 'github.com'), ('DNS', '*.github.io'), ('DNS', 'github.io'), ('DNS', '*.githubusercontent.com'), ('DNS', 'githubusercontent.com')), 'OCSP': ('http://ocsp.digicert.com',), 'caIssuers': ('http://cacerts.digicert.com/DigiCertSHA2HighAssuranceServerCA.crt',), 'crlDistributionPoints': ('http://crl3.digicert.com/sha2-ha-server-g6.crl', 'http://crl4.digicert.com/sha2-ha-server-g6.crl')}
Traceback (most recent call last):
  File "/XXREDACTED/userDir/.pyenv/versions/3.7.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
    chunked=chunked,
  File "/XXREDACTED/userDir/.pyenv/versions/3.7.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 381, in _make_request
    self._validate_conn(conn)
  File "/XXREDACTED/userDir/.pyenv/versions/3.7.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 976, in _validate_conn
    conn.connect()
  File "/XXREDACTED/userDir/.pyenv/versions/3.7.7/lib/python3.7/site-packages/urllib3/connection.py", line 396, in connect
    _match_hostname(cert, self.assert_hostname or server_hostname)
  File "/XXREDACTED/userDir/.pyenv/versions/3.7.7/lib/python3.7/site-packages/urllib3/connection.py", line 406, in _match_hostname
    match_hostname(cert, asserted_hostname)
  File "/XXREDACTED/userDir/.pyenv/versions/3.7.7/lib/python3.7/ssl.py", line 334, in match_hostname
    % (hostname, ', '.join(map(repr, dnsnames))))
ssl.SSLCertVerificationError: ("hostname 'nflarrest.com' doesn't match either of 'www.github.com', '*.github.com', 'github.com', '*.github.io', 'github.io', '*.githubusercontent.com', 'githubusercontent.com'",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/XXREDACTED/userDir/.pyenv/versions/3.7.7/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/XXREDACTED/userDir/.pyenv/versions/3.7.7/lib/python3.7/site-packages/urllib3/connectionpool.py", line 725, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/XXREDACTED/userDir/.pyenv/versions/3.7.7/lib/python3.7/site-packages/urllib3/util/retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: MyHTTPSConnectionPool(host='nflarrest.com', port=443): Max retries exceeded with url: /api/v1/team/arrests/ARI (Caused by SSLError(SSLCertVerificationError("hostname 'nflarrest.com' doesn't match either of 'www.github.com', '*.github.com', 'github.com', '*.github.io', 'github.io', '*.githubusercontent.com', 'githubusercontent.com'")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 253, in <module>
    options.get("test", False))
  File "main.py", line 166, in select_league
    test=test)
  File "/XXREDACTED/userDir/dev/fantasy-football-metrics-weekly-report/report/builder.py", line 129, in __init__
    self.bad_boy_stats = self.league.get_bad_boy_stats(self.save_data, self.dev_offline, self.refresh_web_data)
  File "/XXREDACTED/userDir/dev/fantasy-football-metrics-weekly-report/dao/base.py", line 222, in get_bad_boy_stats
    refresh=refresh
  File "/XXREDACTED/userDir/dev/fantasy-football-metrics-weekly-report/calculate/bad_boy_stats.py", line 70, in __init__
    response = requests.get(nfl_arrest_api_team_base_url + team_abbr, headers=headers)
  File "/XXREDACTED/userDir/.pyenv/versions/3.7.7/lib/python3.7/site-packages/requests/api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "/XXREDACTED/userDir/.pyenv/versions/3.7.7/lib/python3.7/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/XXREDACTED/userDir/.pyenv/versions/3.7.7/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/XXREDACTED/userDir/.pyenv/versions/3.7.7/lib/python3.7/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/XXREDACTED/userDir/.pyenv/versions/3.7.7/lib/python3.7/site-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: MyHTTPSConnectionPool(host='nflarrest.com', port=443): Max retries exceeded with url: /api/v1/team/arrests/ARI (Caused by SSLError(SSLCertVerificationError("hostname 'nflarrest.com' doesn't match either of 'www.github.com', '*.github.com', 'github.com', '*.github.io', 'github.io', '*.githubusercontent.com', 'githubusercontent.com'")))

Google Drive folder fetching bug

When using the Drive integration, the app searches for folders named Fantasy_Football, and the year of the report (2019 for instance), and then League_Name, before placing report.pdf into that final directory. However, say if 2019 already exists elsewhere in your Drive, it will stick the reports there instead, which is not desired behavior.

Testing

The app needs comprehensive unit and integration tests, as it currently has next to none.

Failure to generate report

so not sure if it is because i'm trying to run this on an incomplete week or not but i am receiving this error:

Traceback (most recent call last):
File "main.py", line 254, in
report_pdf = report.create_pdf_report()
File "c:\Scripts\Fantasy Football\fantasy-football-metrics-weekly-report\report\builder.py", line 389, in create_pdf_report
file_for_upload = pdf_generator.generate_pdf(filename_with_path, line_chart_data_list)
File "c:\Scripts\Fantasy Football\fantasy-football-metrics-weekly-report\report\pdf\generator.py", line 1182, in generate_pdf
if float(team[prob_ndx].split("%")[0]) == 100.00:
ValueError: could not convert string to float: '0-1-0 (0.000)'

config and log provided:

out.log
config.txt

[Feature Request] Add Potential Points somewhere in the report

First of all if theres a better way to handle this I apologize I look through the closed reports and didn't see any feature requests

Perfect lineups must be calculated while running this to tracking coaching efficiency? Could you look at adding the total potential points over the course of the season to the standings or its own table? Many dynasty leagues will determine non playoff draft order based on it. It would be nice to have that built into the report.

Thanks again!

ModuleNotFoundError

Hi Uberman,

Trying to get this running but I keep running into this error:

image

I've installed the requirements.txt for the report, and I do see some errors building src\rptlab, I'm not sure if they're related, but perhaps the requirements didn't install correctly. If I comment out the line 'from pydrive.auth import GoogleAuth' in drive.py, I see a ModuleNotFoundError in another place. Any idea where I've gone wrong?

Superflex does not work on Yahoo

The coaching efficiency metric does not calculate correctly in my league, which I think is because of the superflex. Here are my roster settings... QB, RB, RB, WR, WR, TE, W/R/T, W/R/T, Q/W/R/T

Additionally, the weekly rankings on the luck rankings are I think double counting, as in my league, the ranks go up by 1,3,5,7,9,11, 11, 14, 16, 18, 20, 22. This might be because of the tie? Not sure....

Fleaflicker API updates for historical leagues

Currently, there are multiple issues with the Fleaflicker implementation revolving around properly getting data for the selected season and week, vs. the current season and week. These needs to be resolved.

Data source for historical player statuses

Currently many of the fantasy platforms (notably Yahoo) only provide CURRENT player statuses (OUT, SUSP, IR, BYE, etc.), so when using player statuses to determine coaching efficiency ineligibility, it is impossible to do so retroactively.

Add Appendix to explain Stats

Some of the metrics are not straightforward. An appendix to explain what they are and how they are calculated would improve the report.

update luck metric

now that the zscore thing is in there, it could be another variable thrown in to the luck calculations. currently, luck is based entirely on how many other teams you would have beaten that week, and whether you actually won. but with zscore, we can throw in your negative luck based on your opponent outperforming themselves and the fact that you faced them during a week when the blew up, as well as that your own team underperformed that week

example:

wrens team weekly scores:
[45, 48, 47, 40, 134]

kevins team weekly scores:
[140, 120, 125, 155, 100]

in this case, wrens zscore is some outrageous number, indicating that he has completely outperformed his normal scores, while my scores were consistently high and i had a much lower score than my average, so negative zscore.

im not sure how to modify the luck metric to include a teams own zscore and their opponents zscore. just adding or multiplying doesnt seem sufficient... but maybe it is? just adding this for now.

Improve Coaching Efficiency

Currently coaching efficiency is calculated by taking your total score and dividing it by your optimal score, giving you a percentage rating for how close to picking the correct players to sit/start you were. However, this metric can be both gamed (picking up backup players who play or suit up but don't play much or at all), and is not robust against later weeks when lots of players are on bye or are injured.

As such, thought has gone into the appropriate way to improve this metric. The current working plan is to use joint probability calculations, such that we calculate n choose k for each starting lineup position (one QB slots w/3 QBs on the roster -> 3c1), and then multiplying that by each other starting lineup probability to get the joint probability of correctly picking an entire perfect lineup.

Additionally, in order to translate these probabilities into a usable ranking, some sort of weighting based on combining how close your selected position player's points were to the best points possible at that position and the probability of correctly selecting that player for that slot could be used to create a cumulative score.

Alternatively, the full joint probability could be combined with your actual points divided by optimal in some way to weight your coaching efficiency percentage by how hard it was to actually get that percentage.

This is an open issue, and will hopefully eventually result in a reliably robust coaching efficiency metric.

League standings are only ever current

Yahoo's API does not appear to provide league standings for any week other than the current one. As such, retrieving league standings for previous weeks does not work. This issue is tied to #39, and should be solved when that issue is.

H2H Record Playoff Tiebreaker

Currently, the playoff simulations only support "points for" as the tiebreaker after overall/division record. However, some league settings use head-to-head record to break ties. This would require a dynamic field containing a dictionary of opposing team ids as keys, and that team's record against each team as values, and then it would need to allow the user to define whether points for or h2h record dictates playoff eligibility tiebreakers.

Pip module version issue

I set up everything according to the docs, but when I try to run a report, I get the following output:

2020-09-10 15:52:35,513 - root - ERROR - Error: (yahoo-oauth 0.1.9 (/home/xxx/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.8/site-packages), Requirement.parse('yahoo-oauth==1.0'), {'yfpy'})
Traceback (most recent call last):
File "main.py", line 49, in main
pkg_resources.require(dependency)
File "/home/xxx/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.8/site-packages/pkg_resources/init.py", line 899, in require
needed = self.resolve(parse_requirements(requirements))
File "/home/xxx/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.8/site-packages/pkg_resources/init.py", line 790, in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.ContextualVersionConflict: (yahoo-oauth 0.1.9 (/home/keith/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.8/site-packages), Requirement.parse('yahoo-oauth==1.0'), {'yfpy'})

2020-09-10 15:52:35,513 - root - ERROR - MISSING DEPENDENCY: yfpy>=3.0.0. Please run pip install yfpy>=3.0.0 and retry the report generation.
2020-09-10 15:52:35,707 - root - ERROR - MISSING 1 DEPENDENCY
...run aborted.

When I run the pip command mentioned in the error, I get the following:

2020-09-10 15:54:30,731 - root - ERROR - Error: (yahoo-oauth 1.0 (/home/xxx/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.8/site-packages), Requirement.parse('yahoo_oauth==0.1.9'))
Traceback (most recent call last):
File "main.py", line 49, in main
pkg_resources.require(dependency)
File "/home/xxx/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.8/site-packages/pkg_resources/init.py", line 899, in require
needed = self.resolve(parse_requirements(requirements))
File "/home/xxx/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.8/site-packages/pkg_resources/init.py", line 790, in resolve
raise VersionConflict(dist, req).with_context(dependent_req)
pkg_resources.VersionConflict: (yahoo-oauth 1.0 (/home/xxx/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.8/site-packages), Requirement.parse('yahoo_oauth==0.1.9'))

2020-09-10 15:54:30,732 - root - ERROR - MISSING DEPENDENCY: yahoo_oauth==0.1.9. Please run pip install yahoo_oauth==0.1.9 and retry the report generation.
2020-09-10 15:54:30,903 - root - ERROR - MISSING 1 DEPENDENCY
...run aborted.

Any thoughts?

SSL Cert Verification Error for nflarrest.com

Running on mac for ESPN league, week 1.

Receive this error (looks like an SSL cert verification issue for nflarrest.com)

Running Fantasy Football Metrics Weekly Report application from within virtual environment...
Generate report for default league? (y/n) -> y
Generate report for default week? (y/n) -> y
2020-09-15 15:53:10,394 - report.builder - INFO - 
Generating Espn Fantasy Football report with settings:
    league id: 264523
    game id: nfl
    week: selected/default
    save_data: False
    refresh_web_data: False
    playoff_prob_sims: None
    break_ties: False
    dq_ce: False
    dev_offline: False
    test: False
on Sep 15, 2020...
2020-09-15 15:53:10,400 - report.builder - INFO - Retrieving fantasy football data from Espn API...
2020-09-15 15:53:25,089 - report.builder - INFO - ...retrieved all fantasy football data from Espn API in 0:00:14.689397

2020-09-15 15:53:25,090 - report.builder - INFO - Retrieving bad boy data from http://nflarrest.com website...
2020-09-15 15:53:25,504 - urllib3.connection - WARNING - Certificate did not match expected hostname: nflarrest.com. Certificate: {'subject': ((('countryName', 'US'),), (('stateOrProvinceName', 'California'),), (('localityName', 'San Francisco'),), (('organizationName', 'GitHub, Inc.'),), (('commonName', 'www.github.com'),)), 'issuer': ((('countryName', 'US'),), (('organizationName', 'DigiCert Inc'),), (('organizationalUnitName', 'www.digicert.com'),), (('commonName', 'DigiCert SHA2 High Assurance Server CA'),)), 'version': 3, 'serialNumber': '02493E07FA9E375A2DBBC61D94430FCF', 'notBefore': 'May  6 00:00:00 2020 GMT', 'notAfter': 'Apr 14 12:00:00 2022 GMT', 'subjectAltName': (('DNS', 'www.github.com'), ('DNS', '*.github.com'), ('DNS', 'github.com'), ('DNS', '*.github.io'), ('DNS', 'github.io'), ('DNS', '*.githubusercontent.com'), ('DNS', 'githubusercontent.com')), 'OCSP': ('http://ocsp.digicert.com',), 'caIssuers': ('http://cacerts.digicert.com/DigiCertSHA2HighAssuranceServerCA.crt',), 'crlDistributionPoints': ('http://crl3.digicert.com/sha2-ha-server-g6.crl', 'http://crl4.digicert.com/sha2-ha-server-g6.crl')}
Traceback (most recent call last):
  File "/Users/myuser/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.7/site-packages/urllib3/connectionpool.py", line 677, in urlopen
    chunked=chunked,
  File "/Users/myuser/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.7/site-packages/urllib3/connectionpool.py", line 381, in _make_request
    self._validate_conn(conn)
  File "/Users/myuser/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.7/site-packages/urllib3/connectionpool.py", line 978, in _validate_conn
    conn.connect()
  File "/Users/myuser/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.7/site-packages/urllib3/connection.py", line 397, in connect
    _match_hostname(cert, self.assert_hostname or server_hostname)
  File "/Users/myuser/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.7/site-packages/urllib3/connection.py", line 407, in _match_hostname
    match_hostname(cert, asserted_hostname)
  File "/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/ssl.py", line 323, in match_hostname
    % (hostname, ', '.join(map(repr, dnsnames))))
ssl.SSLCertVerificationError: ("hostname 'nflarrest.com' doesn't match either of 'www.github.com', '*.github.com', 'github.com', '*.github.io', 'github.io', '*.githubusercontent.com', 'githubusercontent.com'",)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/myuser/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.7/site-packages/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/Users/myuser/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.7/site-packages/urllib3/connectionpool.py", line 727, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/Users/myuser/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.7/site-packages/urllib3/util/retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: MyHTTPSConnectionPool(host='nflarrest.com', port=443): Max retries exceeded with url: /api/v1/team/arrests/ARI (Caused by SSLError(SSLCertVerificationError("hostname 'nflarrest.com' doesn't match either of 'www.github.com', '*.github.com', 'github.com', '*.github.io', 'github.io', '*.githubusercontent.com', 'githubusercontent.com'")))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "main.py", line 253, in <module>
    options.get("test", False))
  File "main.py", line 166, in select_league
    test=test)
  File "/Users/myuser/Documents/fantasy-football/fantasy-football-metrics-weekly-report/report/builder.py", line 131, in __init__
    self.bad_boy_stats = self.league.get_bad_boy_stats(self.save_data, self.dev_offline, self.refresh_web_data)
  File "/Users/myuser/Documents/fantasy-football/fantasy-football-metrics-weekly-report/dao/base.py", line 222, in get_bad_boy_stats
    refresh=refresh
  File "/Users/myuser/Documents/fantasy-football/fantasy-football-metrics-weekly-report/calculate/bad_boy_stats.py", line 70, in __init__
    response = requests.get(nfl_arrest_api_team_base_url + team_abbr, headers=headers)
  File "/Users/myuser/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.7/site-packages/requests/api.py", line 76, in get
    return request('get', url, params=params, **kwargs)
  File "/Users/myuser/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.7/site-packages/requests/api.py", line 61, in request
    return session.request(method=method, url=url, **kwargs)
  File "/Users/myuser/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.7/site-packages/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/Users/myuser/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.7/site-packages/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/Users/myuser/.virtualenvs/fantasy-football-metrics-weekly-report/lib/python3.7/site-packages/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: MyHTTPSConnectionPool(host='nflarrest.com', port=443): Max retries exceeded with url: /api/v1/team/arrests/ARI (Caused by SSLError(SSLCertVerificationError("hostname 'nflarrest.com' doesn't match either of 'www.github.com', '*.github.com', 'github.com', '*.github.io', 'github.io', '*.githubusercontent.com', 'githubusercontent.com'")))
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
Deleting expired sessions...4 completed.

[Process completed]

Unable to successfully authenticate

I have followed the instructions you've included in the readme but have yet to successfully authenticate with Yahoo. I have installed the requirements and then ran the generate_report.py file. I answer 'y' and 'y' before it prompts me to visit an url in the format https://api.login.yahoo.com/oauth/v2/request_auth?oauth_token=xxxxxxxx. The resulting page is an error page titled Yahoo - 400 Bad Request with the following description.

Your browser sent a request that this server could not understand.
Please check the URL for proper spelling and capitalization. If you're having trouble locating a destination on Yahoo, try visiting the Yahoo home page or look through a list of Yahoo's online services. Also, you may find what you're looking for if you try searching below.

I am running this with Python 3.6 on Windows 10. I've tried to open the link in Chrome, Chrome in incognito mode, and Edge browser. Occasionally when I try in incognito it prompts me to login but after entering username and password it returns me to the same 400 Bad Request page. I've attached my python-yql.log if that might be helpful.

I'm super interested in what you've put together and would love to contribute if only I was able to get it off the ground!

python-yql.log

Check for `config.ini` before run

Several users have encountered "NoSectionError" when running the app because the config.ini file was not loaded properly due to not having been renamed. The app should check for the existence of this file before running and stop and warn the user if it does not exist.

Setup.sh broke my bash_profile

Your setup.sh script adds text to .bash_profile without ensuring the new content starts on its own line. It resulted in a mashed up command that I had to go clean up.

Report feature configuration

Currently, if generating reports, you must have all the features/metrics/stats/etc. within the report. This task is to add configuration values to config.ini so that all features can be turned on/off per user preference.

Median Score Metric

Some fantasy platforms support the ability for teams to also play against the league median score each week for an additional win/loss/tie. There should be a metric that ranks teams based on performance against the median.

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.