Giter VIP home page Giter VIP logo

Comments (3)

ochawkeye avatar ochawkeye commented on August 17, 2024 1

As @derek-adair mentioned, calculating fantasy scores falls outside the scope of this project, but the data this library grants access to gives you everything you need to calculate scores yourself.

For a simple scoring system something like this would suffice:

import nflgame

def base_fantasy_points(player):
    """
    Baseline points consist of only passing, rushing, receiving, and extra
    point stat categories.

    All punt returns, kick returns, and field goals are calculated later by
    evaluating all plays and are generated separately.
    """
    points = +1*getattr(player, 'passing_yds')
    points += +60*getattr(player, 'passing_tds')
    points += -45*getattr(player, 'passing_ints')
    points += -2*getattr(player, 'passing_att')
    points += +2*getattr(player, 'passing_cmp')
    points += +2*getattr(player, 'rushing_yds')
    points += +60*getattr(player, 'rushing_tds')
    points += +2*getattr(player, 'receiving_rec')
    points += +2*getattr(player, 'receiving_yds')
    points += +60*getattr(player, 'receiving_tds')
    points += -45*getattr(player, 'fumbles_lost')
    points += +20*getattr(player, 'passing_twoptm')
    points += +20*getattr(player, 'rushing_twoptm')
    points += +20*getattr(player, 'receiving_twoptm')
    points += +10*getattr(player, 'kicking_xpmade')
    points += -20*getattr(player, 'kicking_xpmissed')
    return points

games = nflgame.games(2018, week=1, kind='PRE', home='MIN', away='MIN')
players = nflgame.combine_max_stats(games)

for game in games:
    print game

for player in sorted(players, key=lambda x: base_fantasy_points(x), reverse=True):
    if base_fantasy_points(player):
        print player.player.name, player.team, base_fantasy_points(player)
        print player.formatted_stats()
MIN (42) at DEN (28)
Roc Thomas RB MIN 388
receiving_tds: 2, receiving_yac_yds: 91, receiving_rec: 3, rushing_yds: 29, receiving_yds: 102, rushing_att: 8, receiving_tar: 3, rushing_lngtd: 0, receiving_twopta: 0, receiving_lng: 78, rushing_tds: 0, rushing_twopta: 0, rushing_lng: 9, receiving_lngtd: 78, receiving_twoptm: 0, rushing_twoptm: 0
Chad Kelly QB DEN 314
passing_incmp_air_yds: 42, passing_sk: 1, passing_att: 21, passing_sk_yds: -8, passing_int: 1, passing_yds: 177, passing_incmp: 7, passing_cmp: 14, rushing_yds: 38, rushing_att: 3, passing_tds: 2, passing_cmp_air_yds: 99, rushing_lngtd: 0, passing_twoptm: 0, passing_twopta: 0, rushing_tds: 0, rushing_twopta: 0, rushing_lng: 18, passing_ints: 1, rushing_twoptm: 0
Kyle Sloter QB MIN 243
passing_sk: 1, passing_incmp_air_yds: 10, passing_att: 11, passing_sk_yds: -6, passing_twoptm: 1, passing_twopta: 1, rushing_tds: 1, passing_yds: 69, passing_incmp: 2, passing_cmp: 9, rushing_yds: 19, rushing_att: 2, passing_tds: 1, passing_cmp_air_yds: 49, rushing_lngtd: 14, rushing_twopta: 0, rushing_lng: 14, passing_ints: 0, rushing_twoptm: 0
Trevor Siemian QB MIN 228
passing_incmp_air_yds: 29, passing_sk: 2, passing_att: 17, passing_sk_yds: -11, passing_int: 1, passing_yds: 165, passing_incmp: 6, passing_cmp: 11, passing_tds: 2, passing_cmp_air_yds: 55, passing_twoptm: 0, passing_twopta: 0, passing_ints: 1
Phillip Lindsay RB DEN 160
receiving_tds: 1, receiving_yac_yds: 37, kickret_yds: 34, receiving_rec: 3, rushing_yds: 7, receiving_yds: 40, rushing_att: 2, receiving_tar: 4, kickret_ret: 1, kickret_lngtd: 0, rushing_lngtd: 0, kickret_lng: 34, receiving_twopta: 0, receiving_lng: 19, rushing_tds: 0, kickret_avg: 34, rushing_twopta: 0, rushing_lng: 5, receiving_lngtd: 19, receiving_twoptm: 0, rushing_twoptm: 0, kickret_tds: 0
...
Case Keenum QB DEN -1
passing_incmp_air_yds: 13, passing_att: 4, passing_yds: 5, passing_incmp: 3, passing_cmp: 1, passing_cmp_air_yds: 2, passing_twoptm: 0, passing_twopta: 0, passing_ints: 0, passing_tds: 0
Paxton Lynch QB DEN -25
passing_incmp_air_yds: 33, passing_sk: 1, passing_att: 11, passing_sk_yds: -9, passing_int: 1, passing_yds: 24, passing_incmp: 5, passing_cmp: 6, rushing_yds: 3, rushing_att: 1, passing_cmp_air_yds: 11, rushing_lngtd: 0, passing_twoptm: 0, passing_twopta: 0, rushing_tds: 0, rushing_twopta: 0, rushing_lng: 3, passing_ints: 1, passing_tds: 0, rushing_twoptm: 0

When your scoring gets more complicated (ie. points based on longer field goals, etc), you can utilize the play-by-play data.

    plays = nflgame.combine_plays(games)
    plays40 = plays.filter(kicking_fgm__ge=1, kicking_fgm_yds__ge=40, kicking_fgm_yds__lt=50)
    for player in plays40.players().kicking():
        fantasy_players_dict[player.playerid].medium_fgs += player.kicking_fgm

from nflgame.

derek-adair avatar derek-adair commented on August 17, 2024

Hello there!

I'm taking over the managment of this code, and I am no expert either. I've exclusively used this for games win/loss tracking. So i know how the schedule code works quite well.

Glancing at the player code it looks like there is no effort towards calculating fantasy points. I'm pretty sure thats out of the scope of this particular project anyhow.

Looking at nfldb, a project that puts the data this project pulls into a relational database, there is no mention of points or anything like that either.

However, it is likely trivial to write your own point rules. This project and the other related ones are more like the code to enable and make writing your own fantasy league possible.... not so much a drop in fantasy football app.

from nflgame.

benlindsay avatar benlindsay commented on August 17, 2024

Thanks for the input! I ended up hacking something together like that to match my league's scoring for players and teams (at least I think it does it right). Still a work in progress but found here

from nflgame.

Related Issues (20)

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.