Closed mvantschip closed 2 years ago
Hi there,
Sorry for the late response!
Will look to address this issue once #104 is resolved.
Thanks
This seems to be an issue with Fotmob data itself that I'm not really sure how to address. match_round
generally reflects the match week, e.g. matches on the last day of the 2020/21 EPL season have match_round=38
.
results <- fotmob_get_matches_by_date(date = "20210523")
match_ids <- results %>%
dplyr::select(primary_id, ccode, league_name = name, matches) %>%
dplyr::filter(league_name == "Premier League", ccode == "ENG") %>%
tidyr::unnest_longer(matches) %>%
dplyr::pull(matches) %>%
dplyr::pull(id)
fotmob_get_match_details(match_ids) %>% dplyr::select(match_id, match_round)
# A tibble: 10 x 2
match_id match_round
<chr> <chr>
1 3411719 38
2 3411720 38
3 3411721 38
4 3411722 38
5 3411723 38
6 3411724 38
7 3411725 38
8 3411726 38
9 3411727 38
10 3411728 38
If you really want a column to indicate match week (i.e. match_round
), you can do something like this to estimate it.
library(dplyr)
side1 <- match_details %>% select(match_id, team_id = home_team_id, opponent_id = away_team_id)
side2 <- match_details %>% select(match_id, team_id = away_team_id, opponent_id = home_team_id)
match_rounds <- bind_rows(
side1,
side2
) %>%
inner_join(match_details %>% select(match_id, match_time_utc), by = "match_id") %>%
mutate(
across(
match_time_utc,
lubridate::mdy_hm
)
) %>%
arrange(match_time_utc, match_id, team_id) %>%
group_by(team_id) %>%
mutate(
match_round1 = row_number(match_time_utc)
) %>%
ungroup() %>%
group_by(opponent_id) %>%
mutate(
match_round2 = row_number(match_time_utc)
) %>%
ungroup() %>%
transmute(
match_id,
match_round = ifelse(match_round1 < match_round2, match_round1, match_round2),
team_id
)
match_details %>%
select(-match_round) %>%
inner_join(match_rounds, by = c("match_id", "home_team_id" = "team_id")) %>%
relocate(match_round, .after = "match_id")
# A tibble: 73 x 15
match_id match_round league_id league_name league_round_name parent_league_id
<chr> <int> <int> <chr> <chr> <int>
1 3787303 1 130 Major League~ Major League Socc~ 130
2 3787426 1 130 Major League~ Major League Socc~ 130
3 3787290 1 10000002 Major League~ Major League Socc~ 130
4 3787425 1 130 Major League~ Major League Socc~ 130
5 3787289 1 130 Major League~ Major League Socc~ 130
6 3787288 1 10000001 Major League~ Major League Socc~ 130
7 3787287 1 10000001 Major League~ Major League Socc~ 130
8 3787286 1 130 Major League~ Major League Socc~ 130
9 3787285 1 130 Major League~ Major League Socc~ 130
10 3787424 1 10000001 Major League~ Major League Socc~ 130
# ... with 63 more rows, and 9 more variables: parent_league_season <chr>,
# match_time_utc <chr>, home_team_id <int>, home_team <chr>,
# home_team_color <chr>, away_team_id <int>, away_team <chr>,
# away_team_color <chr>, shots <list>
Thank you for the reply. I guess if it is not possible in general, this is indeed a very solid workaround.
Thanks for your help @tonyelhabr.
I will mark this closed for now.
Reach out if you need a hand with anything else @mvantschip
I am trying to scrape all the shots from the current MLS season with the following code:
This does return a lot of information, but the
match_round
column is empty and theleague_round_name
column results in "Major League Soccer null" for every row.I am running worldfootballR 0.5.0.
This is my
sessionInfo()
:Thank you for the amazing work! 👍