Skip to content

Commit 3c6a9ae

Browse files
authored
Merge pull request #346 from ffverse/dev
v1.4.7 to CRAN - minor fixes and new tidyr support
2 parents 56a60bb + e96a26c commit 3c6a9ae

39 files changed

+139
-109
lines changed

DESCRIPTION

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: ffscrapr
33
Title: API Client for Fantasy Football League Platforms
4-
Version: 1.4.6
4+
Version: 1.4.7
55
Authors@R:
66
c(person(given = "Tan",
77
family = "Ho",
@@ -38,7 +38,6 @@ Imports:
3838
httr (>= 1.4.0),
3939
jsonlite (>= 1.6.0),
4040
lifecycle,
41-
lubridate (>= 1.5.0),
4241
magrittr (>= 1.5.0),
4342
nflreadr (>= 1.1.0),
4443
memoise (>= 2.0.0),
@@ -61,5 +60,5 @@ LazyData: true
6160
VignetteBuilder:
6261
knitr
6362
Encoding: UTF-8
64-
RoxygenNote: 7.1.1
63+
RoxygenNote: 7.1.2
6564
Roxygen: list(markdown = TRUE)

NEWS.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
# ffscrapr 1.4.7
2+
3+
The main goal of v1.4.7 is to patch some minor bugs and to pre-emptively correct issues related to upstream dependency `tidyr`.
4+
5+
## Changes
6+
- Fix `ff_scoringhistory.flea_conn()` kicking bug.
7+
- Fix `ff_schedule.mfl_conn()` NA bug.
8+
- Remove lubridate dep
9+
- Update `.espn_stat_map()` to add threshold-based scoring and fix a missing defensive scoring setting
10+
- Update `ff_scoringhistory.espn_conn()` to add threshold calcs. (thank you, @scottfrechette!)
11+
- Fix `espn_potentialpoints()` to move regular flex ahead of superflex
12+
- `ff_scoring()` for MFL gets some tweaks to support changes to tidyr (thanks, @DavisVaughan!)
13+
14+
## Thanks
15+
16+
Grateful to [@davisderodes](https://github.com/davisderodes),[@DavisVaughan](https://github.com/DavisVaughan), [@draftydesert277](https://github.com/draftydesert277),[@scottfrechette](https://github.com/scottfrechette), and [@TheMathNinja](https://github.com/TheMathNinja) for their contributions to this release - feedback, issues, and PRs!
17+
18+
---
19+
120
# ffscrapr 1.4.6
221

322
The main goal of v1.4.6 is to patch some minor bugs, introduce a unified dependency on nflreadr, and add some support for kicker scoring.

R/0_generics.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ ff_connect <- function(platform = "mfl", league_id = NULL, ...) {
2828
"fleaflicker" = ,
2929
"flea" = fleaflicker_connect(league_id = league_id, ...),
3030
"espn" = espn_connect(league_id = league_id, ...),
31-
# 'yahoo' = yahoo_connect(league_id = league_id,...)
3231
"sleeper" = sleeper_connect(league_id = league_id, ...),
3332
"mfl" = mfl_connect(league_id = league_id, ...)
33+
# 'yahoo' = stop("Y YOU YAHOO, YOU YAHOO?")
3434
)
3535

3636
if (is.null(x)) stop("We can't connect to that platform yet!")

R/0_utils.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,16 @@ NULL
1717
#' @export
1818
#' @importFrom magrittr %>%
1919
NULL
20+
21+
#' date utils
22+
#' @keywords internal
23+
.as_datetime <- function(x){
24+
origin <- structure(0, class = c("POSIXct", "POSIXt"), tzone = "UTC")
25+
as.POSIXct(x,origin = origin, tz = "UTC")
26+
}
27+
28+
#' date utils
29+
#' @keywords internal
30+
.as_date <- function(x){
31+
as.Date(x, tz = "UTC")
32+
}

R/espn__helpers.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,18 +188,21 @@
188188
c(
189189
"3" = "passingYards",
190190
"4" = "passingTouchdowns",
191+
"8" = "passing25Yards",
191192
"19" = "passing2PtConversions",
192193
"20" = "passingInterceptions",
193194
"24" = "rushingYards",
194195
"25" = "rushingTouchdowns",
195196
"26" = "rushing2PtConversions",
197+
"28" = "rushing10Yards",
196198
"35" = "rushing40YardTD",
197199
"37" = "rushing100YardGame",
198200
"38" = "rushing200YardGame",
199201
"42" = "receivingYards",
200202
"43" = "receivingTouchdowns",
201203
"44" = "receiving2PtConversions",
202204
"45" = "receiving40YardTD",
205+
"48" = "receiving10Yards",
203206
"53" = "receivingReceptions",
204207
"56" = "receiving100YardGame",
205208
"57" = "receiving200YardGame",
@@ -229,6 +232,7 @@
229232
"104" = "interceptionReturnTouchdown",
230233
"114" = "kickoffReturnYards",
231234
"115" = "puntReturnYards",
235+
"122" = "defensive22To27PointsAllowed",
232236
"123" = "defensive28To34PointsAllowed",
233237
"124" = "defensive35To45PointsAllowed",
234238
"125" = "defensive46+PointsAllowed",

R/espn_draft.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ff_draft.espn_conn <- function(conn, ...) {
3333
tidyr::unnest_wider("picks") %>%
3434
dplyr::mutate_at(
3535
dplyr::vars(dplyr::contains("completeDate")),
36-
~ lubridate::as_datetime(.x / 1000)
36+
~ .as_datetime(.x / 1000)
3737
) %>%
3838
dplyr::rename(
3939
"player_id" = "playerId",

R/espn_potentialpoints.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
#' @examples
1313
#' \donttest{
1414
#' try({ # try only shown here because sometimes CRAN checks are weird
15-
#' conn <- espn_connect(season = 2020, league_id = 899513)
16-
#' espn_potentialpoints(conn, weeks = 1:3)
15+
#' conn <- espn_connect(season = 2021, league_id = 950665)
16+
#' espn_potentialpoints(conn, weeks = 1)
1717
#' }) # end try
1818
#' }
1919
#' @export
@@ -102,7 +102,7 @@ espn_potentialpoints <- function(conn, weeks = 1:17) {
102102
.espn_pp_lineupkeys <- function() {
103103
tibble::tibble(
104104
lineup_id = c("0", "2", "3", "4", "5", "6", "7", "16", "17", "20", "21", "23", "8", "9", "10", "11", "24", "12", "13", "14", "15"),
105-
priority = c(1, 2, 5, 3, 6, 4, 8, 9, 10, 0, 0, 11, 12, 13, 16, 14, 15, 17, 18, 19, 20)
105+
priority = c(1, 2, 5, 3, 6, 4, 9, 10, 11, 0, 0, 8, 12, 13, 16, 14, 15, 17, 18, 19, 20)
106106
) %>%
107107
dplyr::arrange(.data$priority) %>%
108108
dplyr::mutate(lineup_id = as.character(.data$lineup_id))

R/espn_rosters.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ ff_rosters.espn_conn <- function(conn, week = NULL, ...) {
5959
eligible_pos = purrr::map(.data$eligible_pos, ~ .espn_lineupslot_map()[as.character(.x)] %>% unname()),
6060
team = purrr::map_chr(as.character(.data$team), ~ .espn_team_map()[.x]),
6161
player = NULL,
62-
acquisition_date = lubridate::as_datetime(.data$acquisition_date / 1000)
62+
acquisition_date = .as_datetime(.data$acquisition_date / 1000)
6363
) %>%
6464
dplyr::left_join(x = franchises, by = "franchise_id")
6565

R/espn_scoringhistory.R

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@
2020
ff_scoringhistory.espn_conn <- function(conn, season = 1999:2020, ...) {
2121
checkmate::assert_numeric(season, lower = 1999, upper = as.integer(format(Sys.Date(), "%Y")))
2222

23-
# Pull in scoring rules for that league
2423
league_rules <-
2524
ff_scoring(conn) %>%
2625
dplyr::left_join(
2726
ffscrapr::nflfastr_stat_mapping %>% dplyr::filter(.data$platform == "espn"),
2827
by = c("stat_name" = "ff_event")
2928
)
3029

31-
## CHECK IF KICKING IS IN THE RULESET FOR THIS LEAGUE, IF SO, USE KICKER
32-
3330
ros <- .nflfastr_roster(season)
3431

3532
ps <- .nflfastr_offense_long(season)
@@ -40,6 +37,10 @@ ff_scoringhistory.espn_conn <- function(conn, season = 1999:2020, ...) {
4037
.nflfastr_kicking_long(season))
4138
}
4239

40+
if(any(c("passing25Yards","rushing10Yards","receiving10Yards") %in% league_rules$stat_name)){
41+
ps <- .espn_threshold_scoring(ps)
42+
}
43+
4344
ros %>%
4445
dplyr::inner_join(ps, by = c("gsis_id"="player_id","season")) %>%
4546
dplyr::inner_join(league_rules, by = c("metric"="nflfastr_event","pos")) %>%
@@ -56,3 +57,17 @@ ff_scoringhistory.espn_conn <- function(conn, season = 1999:2020, ...) {
5657
)
5758

5859
}
60+
61+
.espn_threshold_scoring <- function(ps){
62+
63+
thresholds <- ps %>%
64+
dplyr::filter(.data$metric %in% c("passing_yards","rushing_yards","receiving_yards")) %>%
65+
dplyr::mutate(
66+
threshold = ifelse(.data$metric == "passing_yards",25,10),
67+
metric = paste(.data$metric,.data$threshold,sep = "_"),
68+
value = .data$value %/% .data$threshold,
69+
threshold = NULL
70+
)
71+
72+
dplyr::bind_rows(ps,thresholds)
73+
}

R/espn_transactions.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ ff_transactions.espn_conn <- function(conn, limit = 1000, ...) {
6464
purrr::set_names("x") %>%
6565
tidyr::hoist("x", "messages", "date") %>%
6666
dplyr::mutate(
67-
timestamp = lubridate::as_datetime(.data$date / 1000),
67+
timestamp = .as_datetime(.data$date / 1000),
6868
x = NULL
6969
) %>%
7070
tidyr::unnest_longer("messages") %>%

0 commit comments

Comments
 (0)