Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accumulating rate stats? #104

Open
petegriffith opened this issue Apr 14, 2023 · 30 comments
Open

Accumulating rate stats? #104

petegriffith opened this issue Apr 14, 2023 · 30 comments

Comments

@petegriffith
Copy link

petegriffith commented Apr 14, 2023

Is there a way to loop through every day of the season and get your accumulating score for a rate stat?

In order to find my HR score for any given day of the season, I can check all previous days, and then just add them up.

But for things like ERA, I can't do that. I can't average it either. I would like to find my ERA score for any given day of the season, not my pitchers' ERA on that day.

@whatadewitt
Copy link
Owner

I think what you're looking for is the team.stats resource!

https://yahoo-fantasy-node-docs.vercel.app/resource/team/stats

If I use my league ID and the date in the proper format I get

{ "team_key": "422.l.4103.t.1", "team_id": "1", "name": "chicksDigtheLongball", "url": "https://baseball.fantasysports.yahoo.com/b1/4103/1", "team_logos": [ { "size": "large", "url": "https://yahoofantasysports-res.cloudinary.com/image/upload/t_s192sq/fantasy-logos/24925833379_5aa9877084.jpg" } ], "waiver_priority": 11, "faab_balance": "85", "number_of_moves": 9, "number_of_trades": 0, "roster_adds": { "coverage_type": "week", "coverage_value": 3, "value": "0" }, "league_scoring_type": "head", "has_draft_grade": 0, "auction_budget_total": "260", "auction_budget_spent": 260, "managers": [ { "manager_id": "1", "nickname": "--hidden--", "guid": "RYWP7M53IC626MGOX36ZWCM4FA", "is_commissioner": "1", "felo_score": "759", "felo_tier": "gold" } ], "stats": [ { "stat_id": 60, "value": "11/41" }, { "stat_id": 7, "value": "5" }, { "stat_id": 12, "value": "1" }, { "stat_id": 13, "value": "4" }, { "stat_id": 16, "value": "1" }, { "stat_id": 3, "value": ".268" }, { "stat_id": 50, "value": "7.0" }, { "stat_id": 26, "value": "5.14" }, { "stat_id": 27, "value": "1.86" }, { "stat_id": 57, "value": "10.29" }, { "stat_id": 90, "value": 0 }, { "stat_id": 91, "value": -1 } ] }

You'd need to pair it with the league.settings resource (https://yahoo-fantasy-node-docs.vercel.app/resource/league/settings) to find the mapping for those stat_ids... butI think that's what you're looking for?

(Apologies for the delay, I don't get notified of issues!!)

@petegriffith
Copy link
Author

No so that's what I'm using for counting stats; basically I loop through every day of the season and just add up the (mapped) stats so that I can get my total HR or RBI on any given day of the season.

However, that's not helpful for rate stats. Knowing that I had a 3.00 ERA on a given day doesn't tell me how that affects my overall ERA because I don't know how many IP that ERA represents. So there's no way for me to get my "accumulated" ERA by just averaging out all daily ERAs in the same way I might get my accumulated HR by adding up all daily HRs.

What would be helpful would be a way to query Yahoo to ask for my accumulated stats on any given day of the season; i.e. I get the state of my team's (season) stats on a given day.

@whatadewitt
Copy link
Owner

Hmm... but for something like ERA and WHIP, you have the value, but there are additional stats that come through with the team.stats resource that indicate the number of innings pitched

This was from my team last night

 {
      "stat_id": 50,
      "value": "3.2"
    },

and then I have

{
      "stat_id": 26,
      "value": "0.00"
    },
    {
      "stat_id": 27,
      "value": "0.55"
    },
    {
      "stat_id": 57,
      "value": "4.91"
    },

for ERA, WHIP, and K/9, respectively.

So there might be a bit of work to do, but I do think you can do what you're looking to do... or I am just completely misunderstanding.

@petegriffith
Copy link
Author

petegriffith commented Apr 27, 2023

It may be possible to get ERA if I can access earned runs and IP. Can you get everything you need for OBP though?

To be honest I'm a bit surprised Yahoo doesn't allow for this. You can use team.stats to get your current accumulated stats, with accurate rate stats for the day on which you're calling the API. You can also add a date to get that day's single stats. But there's no way to add a date to get that day's accumulated stats; i.e. I want to know how many HR I had accumulated since the start of the season on april 15th.

@whatadewitt
Copy link
Owner

It's likely they have something internally, but don't expose.

I was told by a fella I connect with at Yahoo! from time to time that they don't even really support the public fantasy API anymore. If I could rally enough interest we might be able to get that changed, but I think that for now you'll need to just persist everything to something local

I guess you could write a quick script that would just query team.stats each day for the range you pass in to it? I do a lot of multi-call scripts and you really don't have much of a chance of going over any sort of rate limits

@solewis
Copy link

solewis commented Apr 16, 2024

@whatadewitt somewhat related question - do you know of any way to get accumulated stats at the player level? I am looking for exactly what you can see on the My Team -> Team Log page in the UI.

In theory, the correct URL seems like it should be /team/{team_key}/roster/players/stats;type=season but that is returning the player's overall stats, not what they actually accumulated for my team.

Similar to the OP, I can use the URL /team/{team_key}/roster;week=1/players/stats;type=week;week=1 to return accumulated stats for each player for a specific week, but unfortunately I can't just aggregate the weeks for rate stats like ERA.

@whatadewitt
Copy link
Owner

@solewis my gut is telling me this should work, but it's definitely not documented on the Yahoo! side, and therefore I don't have it documented.

My first thought would be to try the players.teams collection, but that appears to give the players season long stats as well... but I'm only testing from https://yahoo-fantasy-node-docs.vercel.app/collection/players/teams where I can't specify the week and it's coming back with the season total.

Based on what you've tested with with the original URL though, I can't imagine it's not possible, it's just a matter of figuring out where we can add the week handler, which I don't think would be overly difficult based on how it's used, but I've just spent about 40 minutes making cURL calls and getting nowhere... I'll take a peek in another bit as I am just working through some other bugs, but this would be phenomenal to have. Thanks for the info!

@solewis
Copy link

solewis commented Apr 17, 2024

Yeah this comment from your Yahoo contact makes me think this data should be accessible (we know it exists since it is in the UI). I have also been playing with the cURL calls and just haven't found the right combo.

@whatadewitt
Copy link
Owner

Yahoo! Contact??? 👀

https://fantasysports.yahooapis.com/fantasy/v2/team/mlb.l.11970.t.1/roster;week=2/players/stats;type=week;week=2

My league is public, so this should work, but it's not... what do I have wrong here?

@solewis
Copy link

solewis commented Apr 17, 2024

I'm not at a computer now but it looks correct to me. I'll try when I get home. Do you get an error?

@whatadewitt
Copy link
Owner

whatadewitt commented Apr 17, 2024

No error, but no stats for the players...

 roster: [
    {
      player_key: '431.p.12011',
      player_id: '12011',
      name: [Object],
      url: 'https://sports.yahoo.com/mlb/players/12011',
      editorial_player_key: 'mlb.p.12011',
      editorial_team_key: 'mlb.t.3',
      editorial_team_full_name: 'Los Angeles Angels',
      editorial_team_abbr: 'LAA',
      editorial_team_url: 'https://sports.yahoo.com/mlb/teams/la-angels/',
      is_keeper: [Object],
      uniform_number: '14',
      display_position: 'C',
      headshot: [Object],
      image_url: 'https://s.yimg.com/iu/api/res/1.2/LsX3RTUY6xqCWmPe1V0LUg--~C/YXBwaWQ9eXNwb3J0cztjaD0yMzM2O2NyPTE7Y3c9MTc5MDtkeD04NTc7ZHk9MDtmaT11bGNyb3A7aD02MDtxPTEwMDt3PTQ2/https://s.yimg.com/xe/i/us/sp/v/mlb_cutout/players_l/04172023/12011.png',
      is_undroppable: '0',
      position_type: 'B',
      primary_position: 'C',
      eligible_positions: [Array],
      eligible_positions_to_add: [],
      has_player_notes: 1,
      player_notes_last_timestamp: 1712769411,
      selected_position: 'C'
    },

(just running a simple script in console...)

@solewis
Copy link

solewis commented Apr 17, 2024

It works for me just using cURL. I see Logan O'Hoppe 5/17 H/AB for the week as the first player for example.

Yahoo! Contact??? 👀

I just meant in that comment I linked (or actually a few comments above) you mentioned you had a Yahoo contact, and that comment was the response you received from them.

@whatadewitt
Copy link
Owner

Ah poop! Was hoping there was more!

I think I might know the problem... Are you calling that URL directly and seeing the stats?

@whatadewitt
Copy link
Owner

Indeed. My "mapRoster" helper function doesn't have anything to handle the statistics coming back.

This is PHENOMENAL!

I will update this tomorrow or something (it's late here and I am dead tired, but I know what to do now and this will certainly be a fantastic addition to the codebase!!)

@solewis
Copy link

solewis commented Apr 17, 2024

I am calling that URL directly yes. It has all the league specified stats. So for Logan O'Hoppe it has Runs, RBIs, etc as well as H/AB and IP

@solewis
Copy link

solewis commented Apr 17, 2024

The issue is that URL still doesn't return season long accumulations. For runs you could accumulate yourself, but for ERA you can't see for example what Jared Jones specifically has accumulated for that team.

@whatadewitt
Copy link
Owner

but for ERA you can't see for example what Jared Jones specifically has accumulated for that team.

I'm going to attribute the fact that I'm not understanding this to being so tired 😆 I apologize

[
  { stat: { stat_id: '50', value: '4.2' } },
  { stat: { stat_id: '26', value: '9.64' } },
  { stat: { stat_id: '27', value: '1.71' } },
  { stat: { stat_id: '57', value: '11.57' } },
  { stat: { stat_id: '90', value: '2' } },
  { stat: { stat_id: '91', value: '-1' } }
]

I see these stats coming back, where I have the IP and the ERA / WHIP, I could go week by week and accumulate there, no?

@solewis
Copy link

solewis commented Apr 17, 2024

Yeah I suppose you could accumulate with ERA and WHIP since you have IP, that is true. I am in an OBP league, so that is the stat I am specifically thinking of that I can't accumulate just with the stats returned.

@whatadewitt
Copy link
Owner

whatadewitt commented Apr 17, 2024 via email

@whatadewitt
Copy link
Owner

whatadewitt commented Apr 17, 2024

@solewis what's nice is it works for dates as well

 stats: [
    { stat_id: '60', value: '1/4' },
    { stat_id: '7', value: '1' },
    { stat_id: '12', value: '1' },
    { stat_id: '13', value: '1' },
    { stat_id: '16', value: '0' },
    { stat_id: '3', value: '.250' }

edit: although even if they're on the bench, it's giving me full stats :/

@solewis
Copy link

solewis commented Apr 17, 2024

Yeah it just kind of feels like certain endpoints aren't behaving as they should. I see the same issue where passing a date is just giving full stats. That and type=season just seem to not work as expected.

I don't have any section called "display_only", but I get IP and H/AB as the only three non-scoring data points, which unfortunately isn't enough to calculate OBP

@whatadewitt
Copy link
Owner

whatadewitt commented Apr 17, 2024

Can you share what you get?

If you look at the example response here: https://yahoo-fantasy-node-docs.vercel.app/collection/games/fetch you'll see all the base categories for baseball, but it's super frustrating that the "tester" on this page is broken (I will fix that when I am home tonight)

I just want to see what data is coming back with these different settings.

@solewis
Copy link

solewis commented Apr 17, 2024

Well I don't actually use this Node API, I just stumbled upon your repo and it was helpful to use as a reference :). I am just testing with cURL.

Here is a breakdown of what I am seeing, I can post the actual responses too if that is helpful.

team/{team_key}/roster;date=2024-04-16/players/stats;type=date;date=2024-04-16
This returns the 5 scoring stats plus either H/AB (stat 60) or IP (stat 50) depending on the player. Incorrectly though, it shows their actual stats, not what they actually accumulated for your team on that date (e.g. bench players still show Runs)

team/{team_key}/roster;week=2/players/stats;type=week;week=2
This again returns the 5 scoring stats and one display stat. This is the only one that appears to work correctly, only showing the stats your fantasy team actually accumulated during that week.

team/{team_key}/roster;season=2024/players/stats;type=season
Again same stats, but same issue as the first, it is returning full season stats, not what was accumulated by your team specifically. It also only returns players currently on your roster, where I would expect it to return anyone who has been on your roster at any point in the season.

@whatadewitt
Copy link
Owner

team/{team_key}/roster;date=2024-04-16/players/stats;type=date;date=2024-04-16
This returns the 5 scoring stats plus either H/AB (stat 60) or IP (stat 50) depending on the player. Incorrectly though, it shows their actual stats, not what they actually accumulated for your team on that date (e.g. bench players still show Runs)

but you also have their "selected_position", so you can simply omit anyone who is on your BN or IL

team/{team_key}/roster;week=2/players/stats;type=week;week=2
This again returns the 5 scoring stats and one display stat. This is the only one that appears to work correctly, only showing the stats your fantasy team actually accumulated during that week.

I'm not sure you've got this. I just used mlb.l.11970.t.1 with week 2 and Trevor Rogers is coming back with no stats and I purposefully sat him last week because I didn't trust him in the lineup

team/{team_key}/roster;season=2024/players/stats;type=season
Again same stats, but same issue as the first, it is returning full season stats, not what was accumulated by your team specifically. It also only returns players currently on your roster, where I would expect it to return anyone who has been on your roster at any point in the season.

I'm seeing the same thing you're seeing here, it's giving me all of Rogers' innings (not including today). I can't speak as to how they do it on their side. I did see your post on Reddit earlier today about this issue. Unfortunately they don't really "support" this API publicly anymore, so I don't know you'll get an answer from them, but I do think you could go day-by-day to find most of what you want

@solewis
Copy link

solewis commented Apr 18, 2024

but you also have their "selected_position", so you can simply omit anyone who is on your BN or IL

Yep, true. So again, we have the ability to aggregate ourselves manually for season stats going weekly or daily, but only for certain ones (no way to do it for OBP). Like you say, it doesn't seem like they maintain the APIs anymore, so this will probably be the best we get.

I'm not sure you've got this. I just used mlb.l.11970.t.1 with week 2 and Trevor Rogers is coming back with no stats and I purposefully sat him last week because I didn't trust him in the lineup

I think we are saying the same thing on this one. This endpoint works as I expect, trevor rogers coming back with no stats is what I am seeing and what I expect to see.

@whatadewitt
Copy link
Owner

It's unfortunate, but you would have H/AB and OBP, it's not ideal, but it might not be overly tedious to increment each until you get the proper OBP value?

@solewis
Copy link

solewis commented Apr 18, 2024

Hmm, interesting thought. I'll have to play around with that. If I was better at math I could probably find a smart way to figure it out, but maybe I can code something basic up.

@whatadewitt
Copy link
Owner

Easy math in my head tells me they go 1/3 with a .500 OBP you can sort it out pretty quickly. Obviously it gets more confusing as you go up but the nice thing is that there are realistically only so many ABs that can happen if you're looking game to game...

@whatadewitt
Copy link
Owner

Thank you @solewis for the notes and discussion. I have added this ability to the APIs source, just in case you decide you want to start using it. Also, if you have any other endpoints you're using that I don't have built into this, I'd love to know so I can add them!

https://yahoo-fantasy-node-docs.vercel.app/resource/roster/players

@solewis
Copy link

solewis commented Apr 19, 2024

Definitely, will do. Thank you for talking this through with me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants