Coder Social home page Coder Social logo

Comments (13)

cwendt94 avatar cwendt94 commented on May 20, 2024

Hmm that’s a great question. That wouldn’t be a bad idea but holding all players could take up a lot of space.

So if you are looking for players that were picked up we know they belong to a team. We might be able to use the same endpoint as free_agents function but filter on owned players instead of wavier/free agents.

from espn-api.

rysull23 avatar rysull23 commented on May 20, 2024

from espn-api.

cwendt94 avatar cwendt94 commented on May 20, 2024

That’s a good point, I didn’t even think about dropped players. It definitely adds some more complexity. I wonder if ESPN has a endpoint where you could just call for one player’s data or something like that

from espn-api.

joshbis avatar joshbis commented on May 20, 2024

You could get week-by-week box_scores, which would give you points that a player earned while on a team, but it would miss points (not) accrued in free-agency.

from espn-api.

rysull23 avatar rysull23 commented on May 20, 2024

Looks like you can use the free_agent request and slightly change the filters. The Player object that comes back shows the last 2 week's scores. It also shows total season points. However, it's a bit strange to make out.

See below example for Christian McCaffery

params = {
            'scoringPeriodId': 5,
            'view': 'kona_player_info',
            
        }
filters = {"players":{"filterIds":{"value":[3117251]},"sortPercOwned":{"sortPriority":2,"sortAsc":False},"filterStatsForTopScoringPeriodIds":{"value":2,"additionalValue":["002019","102019","002018","1120195","022019"]}}}
headers = {'x-fantasy-filter': json.dumps(filters)}

r = requests.get(ENDPOINT, params=params, cookies=cookies, headers=headers)
  • notice the filter is 'filterIds' for the player's ID
  • Oh, as I'm typing this, I see 'filterStatsForTopScoringPeriods' is set to 2...wonder what happens if I up it? And the 'additional values' might be the answer to my question below..

Screen Shot 2019-10-03 at 2 24 10 PM

  • Season Total = 115
  • Last week = 34.9
  • 2 weeks ago = 30.8
  • ...What is all that other stuff though? and the why the 2018 data?

Screen Shot 2019-10-03 at 2 29 47 PM

Looks like...

  • 002019 = '00' plus year. The 00 = Season Total
  • 20195 = Year + "5" = Season Average points per week

Screen Shot 2019-10-03 at 2 23 09 PM

from espn-api.

cwendt94 avatar cwendt94 commented on May 20, 2024

Nice, I was thinking you could probably pass in just a player id and players specific information. For the 2018 stats ESPN likes to show the previous season stats like points and rank

from espn-api.

rysull23 avatar rysull23 commented on May 20, 2024

Here's what I put together for fetching player_points. Can prob be cleaned up a bit, but it works. I stuck it in Player Object b/c I wasn't sure how else to utilize it inside the Player Object...

    def fetch_player_points(self, playerId: int):
        """Retrieves a player's points"""

        params = {
            'scoringPeriodId': 5,
            'view': 'kona_player_info',

        }
        filters = {"players": {
            "filterIds": {"value": [playerId]},
            "sortPercOwned": {"sortPriority": 2, "sortAsc": False},
            "filterStatsForTopScoringPeriodIds": {"value": 3,
                                                  "additionalValue": ["002019", "102019", "002018", "1120195",
                                                                      "022019"]}}}
        headers = {'x-fantasy-filter': json.dumps(filters)}
        r = requests.get(self.ENDPOINT, params=params, cookies=self.cookies, headers=headers)
        data = r.json()

        stats = data['players'][0]['player']['stats']
        player_points = {}
        for stat in stats:

            if stat['id'] == str('00') + str(self.year):
                player_points['points_season_total'] = stat['appliedTotal']
                player_points['points_season_average'] = stat['appliedAverage']
            if stat['id'] == str('00') + str(self.year-1):
                player_points['points_season_last'] = stat['appliedTotal']
            if stat['scoringPeriodId'] == self.current_week:
                player_points['points_week_current'] = stat['appliedTotal']
            if stat['scoringPeriodId'] == self.current_week - 1:
                player_points['points_week_last'] = stat['appliedTotal']

        return player_points

from espn-api.

rysull23 avatar rysull23 commented on May 20, 2024

So back to the title of the Topic -- I wonder how we can get the Player Object into he Recent Activity?

from espn-api.

cwendt94 avatar cwendt94 commented on May 20, 2024

Does that endpoint return the correct data to create a player object with it? Because if so what we could do is put this function in the League object and pass the function to the activity object to call it with the player ids to create a player

from espn-api.

rysull23 avatar rysull23 commented on May 20, 2024

great question and idea... (I couldn't figure out how to put the function in the league and pass it across :( )

I think most of the attributes in player object should be included in this endpoint. would need to do a little more digging, but certainly seems like it.

I had it run inside the player object when the league was initializing...pretty slow, but cool to have the data.

from espn-api.

cwendt94 avatar cwendt94 commented on May 20, 2024

If you look at recent_activity function and the Activity class I pass get_team_data function so I can add the Team class. I was thinking you could do the same thing with a “get_player_function” pass that in and it will create a player object off of the player id

from espn-api.

cwendt94 avatar cwendt94 commented on May 20, 2024

@rysull23 Thanks for bringing this back up this year and showing your example code in #133! This is now in package version v0.8.0 🎉

from espn-api.

rysull23 avatar rysull23 commented on May 20, 2024

Welcome. Wow. Forgot about this. Lots of detail here. Thanks for incorporating.

The other piece of this which I spent a ton of time on was figuring out how to get more stat info out of that free_agent api. it's a bit cryptic, but I came close.

from espn-api.

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.