From 345f722b27c3933b0e8bced25c6f70d8398239fd Mon Sep 17 00:00:00 2001 From: Kiernan Nicholls Date: Wed, 6 Oct 2021 13:46:57 -0400 Subject: [PATCH] Improve abbreviation coverage Close #29 --- DESCRIPTION | 2 +- NEWS.md | 1 + R/abbrev.R | 49 ++++++++++++++++++++++++++++++++++ R/roster.R | 2 +- R/sysdata.rda | Bin 356 -> 550 bytes R/utils.R | 32 ---------------------- data-raw/position_ids.R | 57 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 109 insertions(+), 34 deletions(-) create mode 100644 R/abbrev.R create mode 100644 data-raw/position_ids.R diff --git a/DESCRIPTION b/DESCRIPTION index 72685021..059538eb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: fflr Title: Retrieve ESPN Fantasy Football Data -Version: 1.9.2.9001 +Version: 1.9.2.9002 Authors@R: person(given = "Kiernan", family = "Nicholls", diff --git a/NEWS.md b/NEWS.md index 7b937eff..780849f1 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # fflr (development version) +* Improve abbreviation techniques, add all roster slot and position IDs (#29). * Fix error checking in `ffl_api()`. Returns proper error message when there is a failure (e.g., non-public league) (#36). diff --git a/R/abbrev.R b/R/abbrev.R new file mode 100644 index 00000000..d816c633 --- /dev/null +++ b/R/abbrev.R @@ -0,0 +1,49 @@ +# position abbrev slot pos +# Quarterback QB 0 1 +# Team Quarterback TQB 1 +# Running Back RB 2 2 +# Running Back/Wide Receiver RB/WR 3 +# Wide Receiver WR 4 3 +# Wide Receiver/Tight End WR/TE 5 +# Tight End TE 6 4 +# Flex FLEX 23 +# Offensive Player Utility OP 7 +# Defensive Tackle DT 8 9 +# Defensive End DE 9 10 +# Linebacker LB 10 11 +# Defensive Line DL 11 +# Cornerback CB 12 12 +# Safety S 13 13 +# Defensive Back DB 14 +# Defensive Player Utility DP 15 +# Team Defense/Special Teams D/ST 16 16 +# Place Kicker K 17 5 +# Punter P 18 7 +# Head Coach HC 19 14 +# Bench BE 20 +# Injured Reserve IR 21 + +slot_abbrev <- function(slot) { + stopifnot(is.numeric(slot)) + factor(slot, levels = pos_ids$slot, labels = pos_ids$abbrev) +} + +slot_unabbrev <- function(abbrev) { + stopifnot(is.character(abbrev)) + pos_ids$slot[match(abbrev, pos_ids$abbrev)] +} + +pos_abbrev <- function(pos) { + pos_abbrev <- pos_ids$abbrev[!is.na(pos_ids$position)] + stopifnot(is.numeric(pos)) + factor(pos, levels = pos_ids$position, labels = pos_abbrev) +} + +pos_unabbrev <- function(abbrev) { + stopifnot(is.character(abbrev)) + pos_ids$position[match(abbrev, pos_ids$abbrev)] +} + +pro_abbrev <- function(proTeamId) { + fflr::nfl_teams$abbrev[match(proTeamId, fflr::nfl_teams$proTeamId)] +} diff --git a/R/roster.R b/R/roster.R index e42fc6f5..2e9159f8 100644 --- a/R/roster.R +++ b/R/roster.R @@ -63,7 +63,7 @@ out_roster <- function(entry, t = NULL) { id = player$id, firstName = player$firstName, lastName = player$lastName, - proTeam = nfl_abb$abbrev[match(player$proTeamId, nfl_abb$id)], + proTeam = pro_abbrev(player$proTeamId), position = pos_abbrev(player$defaultPositionId), injuryStatus = injury_status, projectedScore = proj_dbl, diff --git a/R/sysdata.rda b/R/sysdata.rda index 02a38086be3fa15bc13f2889255120098feab7a2..66a3a86209bbc76ce7f9313fbe1dffa53cc72230 100644 GIT binary patch literal 550 zcmV+>0@?jST4*^jL0KkKS^Knnr2qk>f5HF%{?I@HkN_WS{=mQg-{3$103ZMXzyaO1 zBw89FF)6(wdXG_~CXdw_F%MCvsl8Lw*+yi50Mu$3N2#HvnJ|C=00000XgJA}CL& zRG}5Hsv^ggfHHHmL$i0_TrDt!cS$04rk4#r1CX*IKuLrqR7C&=0_l*q^#nkOVlYHh zPnS1s5h!n&Rn zomdhp-)|fQ6%=_1&No2zty59&ImS!t7QyKT@DW&Zt@mzmD7{(cL0QE|{>BXZG;DxNeRY|g}( zD8jxeznSTc|AU|E$yqEnDFn{9iNT&)CA9jzFp!W{>Z~y=R literal 356 zcmV-q0h|6pT4*^jL0KkKS&H27rT_uP|A7Dh|Nrm-5CA{_-Qd4xpTGbCumL)&U}Tja zsiEqgDd{~l(@C;2jRBwl28{;P(ETQ$)jv|6rhqg6XaE2KhyVaI07WE7$bP5*XlMWc z7=Qo)qamo!V?z|VGMvz;-^m83R%Bo>;IV|wl2&ln%QV1l6;_axfZZ_|P2(Ak_>kZ` zX9<+daU5cCbWs#b9&@?9e=?Jdu0+inPy9Zh9hHQRd*N}Y)>*JoM