Skip to content

Commit

Permalink
Update update_fb_advanced_match_stats.R
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyelhabr committed Sep 13, 2023
1 parent b3888b8 commit 08bdb01
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions R/fb_advanced_match_stats/update_fb_advanced_match_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ seasons <- all_seasons |>
season_end_year
)

scrape_fb_advanced_match_stats <- function(match_url, stat_type, team_or_player) {
message(sprintf('Scraping matches for %s.', match_url))
fb_advanced_match_stats(match_url, stat_type = stat_type, team_or_player = team_or_player)
scrape_fb_advanced_match_stats <- function(url, stat_type, team_or_player) {
message(sprintf('Scraping matches for %s.', url))
fb_advanced_match_stats(
url,
stat_type = stat_type,
team_or_player = team_or_player
)
}

possibly_scrape_fb_advanced_match_stats <- possibly(
Expand Down Expand Up @@ -81,7 +85,7 @@ update_fb_advanced_match_stats <- function(

scrape_time_utc <- as.POSIXlt(Sys.time(), tz = 'UTC')

new_match_summary <- new_match_urls |>
new_data <- new_match_urls |>
set_names() |>
map_dfr(
\(.x) possibly_scrape_fb_advanced_match_stats(
Expand All @@ -92,7 +96,7 @@ update_fb_advanced_match_stats <- function(
.id = 'MatchURL'
) |>
relocate(MatchURL, .before = 1)

match_results <- load_match_results(
country = country,
tier = tier,
Expand All @@ -101,8 +105,8 @@ update_fb_advanced_match_stats <- function(
)

res <- bind_rows(
existing_match_summary,
new_match_summary |>
existing_data,
new_data |>
inner_join(
match_results |>
transmute(
Expand All @@ -112,7 +116,8 @@ update_fb_advanced_match_stats <- function(
Tier = .env$tier,
Season_End_Year,
MatchURL
)
),
by = 'MatchURL'
)
) |>
as_tibble()
Expand All @@ -125,7 +130,7 @@ update_fb_advanced_match_stats <- function(
tag = fb_advanced_match_stats_tag
)

match_summary
res
}

params |>
Expand Down

0 comments on commit 08bdb01

Please sign in to comment.