ffverse / ffscrapr

R API Client for Fantasy Football League Platforms
https://ffscrapr.ffverse.com
Other
84 stars 21 forks source link

Missing Rookie League IDs #330

Closed scottfrechette closed 3 years ago

scottfrechette commented 3 years ago

When using dp_playerids() it looks like the 2021 rookies are missing some IDs, particularly ESPN and Yahoo. Is there a way to get those added ahead of kickoff?

tanho63 commented 3 years ago

This technically belongs in https://github.com/dynastyprocess/data, which is the main hub for the IDs

tanho63 commented 3 years ago

As far as "can we add these" - I normally get ESPN/Yahoo IDs from a combination of the MFL, Sleeper, FantasyPros APIs and none of them have ESPN/Yahoo atm. I should have a peek at the ESPN players library to see if there's any nice ID connections

TheMathNinja commented 3 years ago

Hey @tanho63 have you looked at the ffespn package lately? That will fetch you all the ESPN ID's. I was especially hoping to have ESPN IDs in dp_playerids() this year.

TheMathNinja commented 3 years ago

Also should I move this to the dynastyprocess issue list? I have no problem doing so if it gets more attention there.

tanho63 commented 3 years ago

@TheMathNinja This would be better there (dynastyprocess/data) but it’s not likely to reach top of my backlog in the near future.

If you’d like to chip in, a PR that adds MFL ID <-> ESPN ID entries to the missing IDs .csv would be welcomed!

TheMathNinja commented 3 years ago

Ok sooooooo.... I know this isn't exactly a PR but this code creates an updated df, updated_playerids, that includes a working espn_id for all rookies who have ever had an ESPN fantasy projection in 2021. So for most cases, I think this is a nice little patch.

remotes::install_github("dfs-with-r/ffespn")
remotes::install_github("ffverse/ffscrapr", ref = "dev")
remotes::install_github("nflverse/nflreadr")

library(tidyverse)
library(ffespn)
library(ffscrapr)
library(nflreadr)

espn_list <- bind_rows(ffespn_projections(2021, 0, "QB") %>% select(-notes),
                       ffespn_projections(2021, 0, "RB") %>% select(-notes),
                       ffespn_projections(2021, 0, "WR") %>% select(-notes),
                       ffespn_projections(2021, 0, "TE") %>% select(-notes),
                       ffespn_projections(2021, 0, "K") %>% select(-notes),
                       ffespn_projections(2021, 0, "P") %>% select(-notes),
                       ffespn_projections(2021, 0, "DT") %>% select(-notes),
                       ffespn_projections(2021, 0, "DE") %>% select(-notes),
                       ffespn_projections(2021, 0, "LB") %>% select(-notes),
                       ffespn_projections(2021, 0, "CB") %>% select(-notes),
                       ffespn_projections(2021, 0, "S") %>% select(-notes),
                       ffespn_projections(2021, 1, "QB") %>% select(-notes),
                       ffespn_projections(2021, 1, "RB") %>% select(-notes),
                       ffespn_projections(2021, 1, "WR") %>% select(-notes),
                       ffespn_projections(2021, 1, "TE") %>% select(-notes),
                       ffespn_projections(2021, 1, "K") %>% select(-notes),
                       ffespn_projections(2021, 1, "P") %>% select(-notes),
                       ffespn_projections(2021, 1, "DT") %>% select(-notes),
                       ffespn_projections(2021, 1, "DE") %>% select(-notes),
                       ffespn_projections(2021, 1, "LB") %>% select(-notes),
                       ffespn_projections(2021, 1, "CB") %>% select(-notes),
                       ffespn_projections(2021, 1, "S") %>% select(-notes),
                       ffespn_projections(2021, 2, "QB") %>% select(-notes),
                       ffespn_projections(2021, 2, "RB") %>% select(-notes),
                       ffespn_projections(2021, 2, "WR") %>% select(-notes),
                       ffespn_projections(2021, 2, "TE") %>% select(-notes),
                       ffespn_projections(2021, 2, "K") %>% select(-notes),
                       ffespn_projections(2021, 2, "P") %>% select(-notes),
                       ffespn_projections(2021, 2, "DT") %>% select(-notes),
                       ffespn_projections(2021, 2, "DE") %>% select(-notes),
                       ffespn_projections(2021, 2, "LB") %>% select(-notes),
                       ffespn_projections(2021, 2, "CB") %>% select(-notes),
                       ffespn_projections(2021, 2, "S") %>% select(-notes)
) %>%
  select(new_espn_id = id,
         name = player,
         team) %>%
  mutate(name = clean_player_names(name),
         team = clean_team_abbrs(team)) %>%
  distinct(new_espn_id, .keep_all = TRUE)

updated_playerids <- dp_playerids() %>%
  mutate(name = clean_player_names(name),
         team = clean_team_abbrs(team)) %>%
  left_join(.,
            espn_list,
                   by = c("name", "team")
  )

#Just to check if there are any contradictions in IDs; this finds 2.
check <- updated_playerids %>%
  filter(!is.na(espn_id) & !is.na(new_espn_id) & espn_id != new_espn_id)

updated_playerids <- updated_playerids %>%
  mutate(espn_id = if_else(is.na(espn_id) & !is.na(new_espn_id), new_espn_id, espn_id)) %>%
  select(-new_espn_id)
tanho63 commented 3 years ago

Hmm, I'm hesitant to introduce a new package to the player ID pipeline. Can you please drill down only the rookie IDs and make a PR here instead? https://github.com/dynastyprocess/data/blob/master/files/missing_ids.csv

tanho63 commented 3 years ago

I'm going to mark this as "resolved" by dynastyprocess/data#29 - if you find further missings/errors please feel free to open an issue in that repo :)

scottfrechette commented 3 years ago

Thanks for tackling this @TheMathNinja and @tanho63. I also use Yahoo IDs so maybe I’ll try to work on that and submit a PR in that project.