0

Players Current Score

Hey guys, for my app, I would like to display, on the same line as the players name, their current score (based on the Fantasy league settings). Here are the steps I've outlined so far:

1. API call to get league settings
2. API call for each player to get their current stats
3. Somehow match the players current score from their stats to the leagues stat_modifier for the specific stat
4. Add each stat after multiplication to get their total
5. Display the result

My problem right now is #3. The player's stats contain only the applicable settings for the player, while the league's settings, contain many, many more stats, so I can't go by simple array positions for each. The only thing I can think to do is to pick a league stat, loop through the player's stats to find the position, call for the value at that position, then multiply. The problem is my league has 31 stats and I have about 15 players, that would be 465 loops every time i wanted to refresh scores, not feasible.

Is anyone else displaying current scores for every player individually, in their app? If so, please help.

Thanks

David B.

by
10 Replies
  • Ok, I found something in the API documentation that might help, but I'm not sure, so I need help understanding.

    Under Player Resources: http://developer.yahoo.com/fantasysports/g...r-resource.html
    The sub-resource "stats" states: Player stats and points (if in a league context)

    What does "if in a league context" mean? How do I put the URL in "league context?

    Thanks

    David B.
    0
  • QUOTE (David B @ Aug 4 2010, 09:23 PM) <{POST_SNAPBACK}>
    Ok, I found something in the API documentation that might help, but I'm not sure, so I need help understanding.

    Under Player Resources: http://developer.yahoo.com/fantasysports/g...r-resource.html
    The sub-resource "stats" states: Player stats and points (if in a league context)

    What does "if in a league context" mean? How do I put the URL in "league context?

    Thanks

    David B.

    Oh. You're right, that might be a bit confusing. Let's give an example:

    Say that you're writing a MLB application. You've gotten the user to authenticate with you, and you grabbed his league ID from the list of MLB leagues that he belongs to.

    CODE
    http://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games;game_keys=mlb/leagues


    Armed with this league key (let's say it's 238.l.627060), you want to let him search for a particular player, like Pujols, and get his stats. You could search for Pujols to find his player key...

    CODE
    http://fantasysports.yahooapis.com/fantasy/v2/league/238.l.627060/players;search=pujols


    And then plug that key (238.p.6619) into a stats call within the context of the league (this is what we mean by that):

    CODE
    http://fantasysports.yahooapis.com/fantasy/v2/league/238.l.627060/players;player_key=238.p.6619/stats


    This is sort of a bad example, because this league is actually a roto league, so it doesn't use points, but trust me, the points would show up if your league were using a scoring type that supported points (head-to-head points and points for NBA, NHL, and MLB; plain head-to-head and points for NFL). If you wanted to avoid the trouble of making that second call, you could actually combine the requests together:

    CODE
    http://fantasysports.yahooapis.com/fantasy/v2/league/238.l.627060/players;search=pujols/stats


    And, hell, you could actually combine all of those requests into one if you wanted to figure out the stats that Pujols earned across all my leagues:

    CODE
    http://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games;game_keys=mlb/leagues/players;search=pujols/stats


    Does that make sense how all this fits together? There's a nesting order for how resources can fit beneath other resources, and you can chain those together to get the information you want. So when we say that we want a player in the context of a league, it just means that the player resources are nested below the league resource in the XML hierarchy. A similar type of request might be, give me the stats for all the players on all the teams that I own, and that would go a little something like:

    CODE
    http://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games;game_keys=mlb/leagues/teams/players/stats


    I think we've said a couple times that we designed these services with flexibility in mind, to let you get the most information you want with the fewest requests, and hopefully this helps explain a little bit what we mean by that.

    (if you're still not seeing how this applies to your situation, just let me know and I'll try to tailor the examples a bit better)

    EDIT: Random note: if you were set on calculating the points yourself, then you'd probably want to make the league settings request, loop through the stat_modifiers element and create a hash mapping stat_id to value, then make the player request, loop through the stats, figure out the stat modifier by indexing into the hash you created earlier (using the stat_id that's part of the stat element), and then multiply the modifier times the value. Then, if your league has 31 stats and 15 players, it would be a small loop of 31 to create the stat_modifier hash, then 465 hash lookups (instead of loops) to pull out the right modifier and multiply it to find the right value. But, yeah, it would be way better to just ask for the stats in the league context.
    0
  • Sean, you last post was immensely helpful. Using your post and going back to read the api docs more, I went from around 7 calls to 1. Here is the super URL I use now:
    CODE
    http://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games;game_keys=nfl/leagues;out=settings/teams;out=standings,stats;type=week;week=current/players/stats;type=week;week=current


    I'm now only missing one thing in my URL. If you look at my URL in the "team" section, you see I'm looking for week stats for my teams. I read in the docs that if you use the "out" parameter that you can't pass any other parameters to it. So my "out" call to team stats will always be for the season (currently the default for stats), until I'm allowed to use the "type=week" parameter with it.

    I need that info, especially since you added projected points, so I'll make an additional call for just weekly stats.

    Thanks!

    David
    0
  • QUOTE (cybler @ Aug 11 2010, 10:09 PM) <{POST_SNAPBACK}>
    I need that info, especially since you added projected points, so I'll make an additional call for just weekly stats.

    Thanks!

    David


    Maybe I missed this, but how can we retrieve projected points?
    0
  • QUOTE (joeyjoejoe61 @ Aug 13 2010, 11:10 AM) <{POST_SNAPBACK}>
    Maybe I missed this, but how can we retrieve projected points?


    In PHP:

    CODE
    $url = 'http://fantasysports.yahooapis.com/fantasy/v2/team/' . $team_key . '/stats;type=week;week=' . $league_current_week;


    David
    0
  • QUOTE (cybler @ Aug 11 2010, 10:09 PM) <{POST_SNAPBACK}>
    I'm now only missing one thing in my URL. If you look at my URL in the "team" section, you see I'm looking for week stats for my teams. I read in the docs that if you use the "out" parameter that you can't pass any other parameters to it. So my "out" call to team stats will always be for the season (currently the default for stats), until I'm allowed to use the "type=week" parameter with it.

    I need that info, especially since you added projected points, so I'll make an additional call for just weekly stats.

    Thanks!

    David

    Ha, well, that's embarrassing.

    So, David, one trick that you can use:

    When making the team stats call, use something like this:

    CODE
    .../teams;out=standings,stats;stats.type=week;stats.week=current/...


    This is a little hack we added in to work around the inability to pass parameters to resources included as out parameters. It's only implemented for stats, and possibly only at the team level (though you can try it at the players level, I just haven't verified if it works there), but it should get you the info you need for now.

    The trick that I'm going to be forced to take away, probably next week, is that projected stats data that's showing up in the service. As far as I'm aware, we weren't supposed to be getting that out there because we don't have the projected stats data under the same contract as the regular stats data. I'll need to check in with our product managers/lawyers, but I'm pretty sure that I'll have to take that part out of the team services. So, heh, enjoy it while you can, I guess. Sorry to anyone who got excited.
    0
  • QUOTE (Sean Montgomery @ Aug 14 2010, 04:12 PM) <{POST_SNAPBACK}>
    Ha, well, that's embarrassing.

    So, David, one trick that you can use:

    When making the team stats call, use something like this:

    CODE
    .../teams;out=standings,stats;stats.type=week;stats.week=current/...


    This is a little hack we added in to work around the inability to pass parameters to resources included as out parameters. It's only implemented for stats, and possibly only at the team level (though you can try it at the players level, I just haven't verified if it works there), but it should get you the info you need for now.

    The trick that I'm going to be forced to take away, probably next week, is that projected stats data that's showing up in the service. As far as I'm aware, we weren't supposed to be getting that out there because we don't have the projected stats data under the same contract as the regular stats data. I'll need to check in with our product managers/lawyers, but I'm pretty sure that I'll have to take that part out of the team services. So, heh, enjoy it while you can, I guess. Sorry to anyone who got excited.


    Well, projected stats would be very nice to have. Can you follow up when you get a confirmation if this feature will or will not be available?
    0
  • QUOTE (Sean Montgomery @ Aug 14 2010, 04:12 PM) <{POST_SNAPBACK}>
    So, David, one trick that you can use:

    When making the team stats call, use something like this:

    CODE
    .../teams;out=standings,stats;stats.type=week;stats.week=current/...


    That worked! Unfortunately I need season total points and week points every time I display a team, so I'm still stuck with two calls. Is there a way to get both season and weekly points in one call, for team stats?

    Thanks!

    David
    0
  • QUOTE (cybler @ Aug 14 2010, 09:44 PM) <{POST_SNAPBACK}>
    That worked! Unfortunately I need season total points and week points every time I display a team, so I'm still stuck with two calls. Is there a way to get both season and weekly points in one call, for team stats?

    Ah, yeah. Unfortunately, that isn't possible at the moment. Still, two calls is better than the around 7 you'd had before! :)Will let you know about projected points as soon as I hear back.
    0
  • QUOTE (Sean Montgomery @ Aug 19 2010, 08:10 PM) <{POST_SNAPBACK}>
    Ah, yeah. Unfortunately, that isn't possible at the moment. Still, two calls is better than the around 7 you'd had before! :)


    What if you just get league standings to get season points for teams, and then tally up all the player points for the week as your weekly point count?

    CODE
    /league/#{league_key};out=settings,standings/players/stats;type=week;week=current


    and then look for the total points:

    CODE
    <player_points>
    <coverage_type>week</coverage_type>
    <week>1</week>
    <total>0</total>
    </player_points>


    And then boom, you should have a count of the weekly points by adding up the player points. I guess I'm assuming you're storing player/team associations somehow.

    What I'm doing is storing all the data in my db, and making requests every X minutes to update the db, so I'm thinking of doing this to update the teams.

    I'm also looking into parsing our current stats' providers live/in-progress box stats and matching them up to do super real time serving of points, as I don't think there's anway to do that with the API today. BTW, it would be cool if you guys set some PubSub solution with just one rss stream of player scores in realtime, and just have one hub broadcast it out to those who subscribe. Then we can easily and scaleably get these stats. It would improve my life about 100x and would probably decrease the amount of API hits to your servers.

    BTW, if that's something you guys are interested in doing, please let me know! I'm personal friends with the founder of Superfeedr. We're working on stats PuSH with lots of live stats providers already to get this working.

    All it would take is to update a rss feed with the scores, which you could also protect if private.
    0

Recent Posts

in Fantasy Sports API