Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tm_player_transfer_history #343

Merged
merged 3 commits into from
Nov 23, 2023
Merged

Conversation

tonyelhabr
Copy link
Collaborator

@tonyelhabr tonyelhabr commented Nov 23, 2023

The "base" fields that used to be returned by tm_player_transfer_history() are no longer provided via server-side rendered HTML. Instead, the data is loaded client-side after an API call. This PR refactors the logic to replicate the API call that a browser would make to retrieve the "base" fields like team_from, market_value, etc.

The logic for the "extra" columns like country_from, contract_expiry remains the same, although I've refactored it to be a little more elegant (using purrr::map()).

Fixes #342.

@tonyelhabr tonyelhabr marked this pull request as draft November 23, 2023 00:55
@codecov-commenter
Copy link

codecov-commenter commented Nov 23, 2023

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (f40ce4a) 61.15% compared to head (f8c7ab5) 64.76%.

Files Patch % Lines
R/player_transfer_history.R 98.09% 2 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #343      +/-   ##
==========================================
+ Coverage   61.15%   64.76%   +3.61%     
==========================================
  Files          44       44              
  Lines        3586     3565      -21     
==========================================
+ Hits         2193     2309     +116     
+ Misses       1393     1256     -137     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

testthat::skip_on_cran()

## multiple URLs
transfer_data <- tm_player_transfer_history(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

augmented the test a bit while i was at it.

  • explicit testing for multiple URLs
  • explicit testing of get_extra_info
  • checks for exact column names (this should be less frail than what we used to do for fotmob since we explicitly define the column names in the function code)


each_player_df <- rbind(each_player_df, each_row_df)
) %>%
## for backwards compatability
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i.e. return the columns in the same order that they used to be returned

)

# Executed if the user wants to get more info. Contains: Contract Expiring date + Days remaining. From which countries was the transfer.
res <- if (isTRUE(get_extra_info)) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no actual logic changes for get_extra_info retrieval. just better spacing, etc.

@tonyelhabr tonyelhabr marked this pull request as ready for review November 23, 2023 15:44
Copy link
Owner

@JaseZiv JaseZiv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome! Thanks heaps for addressing @tonyelhabr

@JaseZiv JaseZiv merged commit 8053e5f into main Nov 23, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tm_player_transfer_history() failing due to not being available in the HTML of transfermarkt
3 participants