Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit85d22a1

Browse files
authored
Merge pull request#257 from jimmyday12/issue-256
Fixing issue with fetch_player_details
2 parents5c252d8 +797faf1 commit85d22a1

File tree

3 files changed

+40
-15
lines changed

3 files changed

+40
-15
lines changed

‎R/fetch-player-details.R‎

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,24 @@ fetch_player_details <- function(team = NULL,
5252
cli::cli_inform("Returning historical player details from source `{source}`")
5353
}
5454

55-
dat<-switch(source,
56-
"AFL"=purrr::map_dfr(
57-
season,
58-
~ fetch_player_details_afl(
59-
season=.x,
60-
team=team,
61-
comp=comp
62-
)
63-
),
64-
"afltables"= fetch_player_details_afltables(team),
65-
"footywire"= fetch_player_details_footywire(team,current=current),
66-
NULL
67-
)
55+
if(source=="AFL"& is.null(season)) {
56+
dat<- fetch_player_details_afl(team=team,
57+
season=season,
58+
comp=comp,
59+
current=current)
60+
}elseif (source=="AFL") {
61+
dat<-purrr::map_dfr(season,
62+
~ fetch_player_details_afl(team=team,
63+
season=.x,
64+
current=current,
65+
comp=comp))
66+
}elseif (source=="afltables") {
67+
dat<- fetch_player_details_afltables(team=team)
68+
}elseif (source=="footywire") {
69+
dat<- fetch_player_details_footywire(team=team,current=current)
70+
}else {
71+
dat<-NULL
72+
}
6873

6974
if (is.null(dat))cli::cli_warn("The source\"{source}\" does not have Player Details data. Please use one of\"afltables\" and\"footywire\"")
7075
return(dat)
@@ -88,12 +93,18 @@ fetch_player_details_afl <- function(season = NULL, team = NULL, current = TRUE,
8893
# get season id
8994
comp_seas_id<- find_season_id(season,comp)
9095

96+
# If it's not current season, check previous season
97+
if (is.null(comp_seas_id)&current) {
98+
comp_seas_id<- find_season_id(season-1,comp)
99+
}
100+
101+
# If still not found, return null
91102
if (is.null(comp_seas_id)) {
92103
cli::cli_warn("No player details data found for season {season} on AFL.com.au for {comp}")
93104
return(NULL)
94105
}
95106

96-
if (!comp%in% c("AFLM","AFLW"))official_teams<-TRUE
107+
if (!comp%in% c("AFLM","AFLW")|official_teams==TRUE)official_teams<-TRUE
97108

98109
# return team abbreviation
99110
if (!is.null(team)) {
@@ -114,6 +125,7 @@ fetch_player_details_afl <- function(season = NULL, team = NULL, current = TRUE,
114125
team_names<-team_dat$name
115126
}
116127

128+
117129
args<-list(
118130
teamId=team_ids,
119131
team=team_names,

‎R/helpers-afl.R‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ fetch_round_results_afl <- function(id, cookie = NULL) {
470470
#' @param compSeasonId comp season id returned by `find_season_id`
471471
#' @keywords internal
472472
#' @noRd
473+
473474
fetch_squad_afl<-function(teamId,team,season,compSeasonId) {
474475
cli::cli_progress_step("Fetching player details for {team}, {season}")
475476
api<-"https://aflapi.afl.com.au//afl/v2/squads"

‎tests/testthat/test-fetch-player-details.R‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1+
test_that("fetch_player_details works for various inputs", {
2+
testthat::skip_if_offline()
3+
testthat::skip_on_cran()
4+
5+
# Overall
6+
expect_gt(nrow(fetch_player_details(team="Adelaide")),0)
7+
8+
})
9+
110
test_that("fetch_player_details_afl works for various inputs", {
211
testthat::skip_if_offline()
312
testthat::skip_on_cran()
13+
14+
# Overall
15+
expect_gt(nrow(fetch_player_details(team="Adelaide")),0)
416

517
# Team
618
expect_s3_class(fetch_player_details_afl(2021,team="Hawthorn") %>% suppressWarnings(),"tbl")
@@ -62,7 +74,7 @@ test_that("fetch_player_details works AFLM", {
6274
as.numeric()
6375

6476
# first check if there is going to be current data
65-
aflm_res<- suppressWarnings(fetch_results_afl(2023,1,"AFLM"))
77+
aflm_res<- suppressWarnings(fetch_results_afl(yr-1,1,"AFLM"))
6678
testthat::skip_if(is.null(aflm_res))
6779

6880
# Test each source works

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp