dfs-with-r / ffespn

Get ESPN fantasy football data
Other
2 stars 3 forks source link

DT, DE, LB, CB, S. #1

Closed TheMathNinja closed 4 years ago

TheMathNinja commented 4 years ago

Could you please add functionality for IDP positions? Would love to get the projection scrapes for these positions.

zamorarr commented 4 years ago

I can try! I can't seem to find the IDP projections on ESPN though. Do you have a link to the place on the website that has them? I can't seem to find them myself on https://fantasy.espn.com/football/players/projections (they only have full team defense). When I try querying for the defensive positions the only entry that is returned is for Patrick Ricard, who is a two way player who also plays fullback.

zamorarr commented 4 years ago

FWIW, I added the ability to query by those positions but for the most part they return empty results. The only exception is Patrick Ricard, as I said earlier. Example:

library(ffespn)
ffespn_projections(2020, 0, pos = "DT")
TheMathNinja commented 4 years ago

You can use this: https://fantasy.espn.com/football/players/projections?leagueId=61760077

Any league which starts IDPs can see them. This should be public.

zamorarr commented 4 years ago

Thanks for the url. I think I was able to do it. Could you try installing the new version from the IDP branch and letting me know if it works? If so, I'll merge it into the main branch.

remotes::install_github("dfs-with-r/ffespn", "idp")
library(ffespn)
ffespn_projections(2020, 0, pos = "DT")
TheMathNinja commented 4 years ago

It's perfect!! Well done!

TheMathNinja commented 4 years ago

Also...if this is going to be complete, I think it could make sense to include the full range of positions ESPN offers. Could you maybe revisit the link and also add the other positions?

P HC DL OP DP EDR etc.

zamorarr commented 4 years ago

alright they should all be mapped now! give it try with the edge rushers:

remotes::install_github("dfs-with-r/ffespn", "idp")
library(ffespn)
ffespn_projections(2020, 0, pos = "EDR")
TheMathNinja commented 4 years ago

Are you able to see how they are generating Punter Projections? When I look here the position is listed as "unknown_7" and I don't see any usable fields for stat projections. yet I see a points projection listed at ESPN. Are there variables they're possibly pulling from elsewhere?

zamorarr commented 4 years ago

Ah I think I know what is happening. ESPN uses position numbers instead of names (1 = QB, 2 = RB, etc...). If I don't know what the number maps to I just prefix it with "unknown". So I guess 7 should map to P. As for the stats, they also use number IDs to refer to stats (0 = pass attempt, 1 = pass completion, etc...). However in this case if I don't know what the number maps to I don't return the stat. I'll try and figure out what they map too.

For reference, you can look here to see my current list:

https://github.com/dfs-with-r/ffespn/blob/71377f5361f8ca2f4d57b11c44110f1491a9e447/R/utils.r#L28

On Thu, Sep 10, 2020, 7:15 PM Mike Filicicchia notifications@github.com wrote:

Are you able to see how they are generating Punter Projections? When I look here the position is listed as "unknown_7" and I don't see any usable fields for stat projections. yet I see a points projection listed at ESPN. Are there variables they're possibly pulling from elsewhere?

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/dfs-with-r/ffespn/issues/1#issuecomment-690780470, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6A3V63NBONVMG2CHGHNALSFFM25ANCNFSM4RAORMPA .

zamorarr commented 4 years ago

Ok I've made some changes. By default now if I don't know how to map a stat id to stat name I just return it anyway and prefix it with stat_. For example, stat_138 is something related to punters but I don't know what yet. (Any thoughts would be appreciated. Estimated number of punts maybe?). I am also including the total fantasy point projection using the default ESPN system. This is now the column fpts_proj. Feel free to retry the code again. You should see something like this (I've omitted some columns)

remotes::install_github("dfs-with-r/ffespn")
library(ffespn)
ffespn_projections(2020, 1, pos = "P")

#> # A tibble: 32 x 17
#>    id    player team  position slots fpts_proj stat_138 stat_139 stat_140
#>    <chr> <chr>  <chr> <chr>    <lis>     <dbl>    <dbl>    <dbl>    <dbl>
#>  1 15928 Sam M… DEN   P        <chr…      4.78     4.82     221.    0.554
#>  2 3915… Tommy… KC    P        <chr…      4.31     3.53     160.    0.413
#>  3 16166 Tress… WAS   P        <chr…      4.93     5.17     240.    0.616
#>  4 3051… Camer… PHI   P        <chr…      4.60     4.24     195.    0.470
#>  5 3936… Jamie… CLE   P        <chr…      4.81     4.61     210.    0.465
#>  6 2977… Bradl… TB    P        <chr…      4.52     4.39     194.    0.390
#>  7 3043… Matt … MIA   P        <chr…      4.88     5.15     231.    0.603
#>  8 3686… AJ Co… OAK   P        <chr…      4.70     4.17     190.    0.472
#>  9 8513  Dusti… PIT   P        <chr…      4.82     4.26     192.    0.596
#> 10 3924… Josep… CAR   P        <chr…      4.74     4.69     213.    0.549
#> # … with 22 more rows, and 8 more variables: stat_141 <dbl>, stat_142 <dbl>,
#> #   stat_143 <dbl>, stat_144 <dbl>, stat_145 <dbl>, stat_146 <dbl>,
#> #   stat_148 <dbl>, stat_210 <dbl>

The bad part is you'll now have a lot more columns to deal with. The good part is if you (or anyone) figures out what they are I can name them appropriately.

TheMathNinja commented 4 years ago

I gotchu on all the stat names here as well as their ESPN abbreviations:

stat_138 = Punts (PT) (ESPN calls this "Net Punts" but I'm not sure why. I think Punts is good, haha). stat_139 = Punt Yards (PTY) stat_140 = Punts inside the 10 (PT10) stat_141 = Punts inside the 20 (PT20) stat_142 = Blocked Punts (PTB) stat_143 = Punts Returned (PTR) stat_144 = Punt Return Yards (PTRY) stat_145 = Punt Touchbacks (PTTB) stat_146 = Punt Fair Catches (PTFC) stat_210 = Games Played

I have two theories on stats_148-152. The most likely: stat_148 = Punt Average 44.0+ (PTA44) (this means number of games in which the punter averaged 44+ yards per punt) stat_149 = Punt Average 42.0-43.9 (PTA42) stat_150 = Punt Average 40.0-41.9 (PTA40) stat_151 = Punt Average 38.0-39.9 (PTA38) stat_152 = Punt Average 36.0-37.9 (PTA36)

I do know ESPN also has/uses a PTA34 and PTA33 stat. But I think they will generally project these as 0 for all Punters. Did you see these stats in there anywhere? I would imagine they are stat_153 and stat_154?

There's also some non-zero probability that stat_147 (which is missing from Punter data and I don't know why) is actually PT44 and stat_148 is PT42, and on down the line (and that all the above are off by one).

So any insight you have on stat_147 and stats_153-155 would be very helpful in deciding what is what here.

TheMathNinja commented 4 years ago

Also, here's a few more stat keys for you: stat_10 = Sacked (SK) stat_2 = Incomplete Passes (INC) stat_79 = fg_miss_40_49 stat_82 = fg_miss_1_39 stat_85 = fg_miss_tot stat_88 = fg_miss_xp stat_76 = stat_200 = fg_miss_50

I'm noticing stat_76 + stat_198 = stat_199. These appear to be repeats of fg_cmp_50, fg_miss_50, fg_att_50. I'm not sure why they are their own categories here. I do know that ESPN has settings for FG60 (FG Made 60+ yards), FGM60, and FGA60. They don't actually have a 50+ category, it's a 50-59 category and a 60+ category. I was wondering if these different stats are duplicates because ESPN just copies and pastes the 50-59 projections into 60+, but that doesn't explain why the Totals don't include the 60+ category. So I'm not quite sure what to make of it. I'm not sure the name of the stat numbers before you converted them to FG names, but it might make sense to just add the stat categories for misses which are consistent with the prior categories and leave the others (I'm thinking probably categories 198-200 still unnamed.

TheMathNinja commented 4 years ago

stat_94 = total return TDs (i.e. sum of FR and INT return TDs) stat_108 = def_tackles_solo (TKS) stat_100 = def_stuffs (ST)

zamorarr commented 4 years ago

Hey these are great! Thank you. I just added them in. I went with your first theory on the punters stats.

The only one I'm not sure about is stat_10 which you said was sacked. For one, I had marked stat_64 as sacked already (but I could be wrong). But also whenever I get the week1 projections for the QBs, stat_10 is either NA or or 2.

# install again
remotes::install_github("dfs-with-r/ffespn")

# get QB week1 and count pass_sacked
library(dplyr)
library(ffespn)
x <- ffespn_projections(2020, 1, "QB")
count(x, stat_10)
# A tibble: 2 x 2
  stat_10     n
        <dbl> <int>
1           2    32
2          NA    32
TheMathNinja commented 4 years ago

Oh my bad on stat_10. I didn't see you had already accounted for "sacked". Yeah, I'm not sure what that one is then. Best to stay agnostic on it I guess.

TheMathNinja commented 4 years ago

I think I'm getting a new error now. When I'm running ffespn_projections(2020, 0, "QB") I believe I'm seeing 2019 projections. Eli Manning is here and projected for more attempts than Daniel Jones. Plus the numbers aren't syncing up with what I see on ESPN. Is this a bug that came in with the start of the season?

TheMathNinja commented 4 years ago

Also, I'm noticing stat_68 == fumbles (and stat_65 + stat_66 == stat_68). The variable you labeled "fumbles" should actually be "fumbles_lost". I'm really still not sure what stats 65 and 66 are about.

TheMathNinja commented 4 years ago

stat_15 = 40+ Yd TD passes stat_16 = 50+ Yd TD passes stat_17 = 300-399 Yd Passing Game stat_18 = 400+ Yd Passing Game stat_35 = 40+ Yd TD Rush stat_36 = 50+ Yd TD Rush stat_37 = 100-199 Yd Rushing Game stat_38 = 200+ Yd Rushing Game

zamorarr commented 4 years ago

yup I knew I was going to break something. When I fixed the weekly projections I accidentally changed how the code was doing the season long projections. That should be fixed now. Also I added in more of your stat names. Really appreciate you figuring these out!

Should be able to re-install the package and see the fixes.