-
Notifications
You must be signed in to change notification settings - Fork 5
Calculate match success rate #530
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
Draft
cjyetman
wants to merge
8
commits into
main
Choose a base branch
from
calculate_match_success_rate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3bf2dae
add `calculate_match_success_rate()` function
cjyetman 19be6a8
export `calculate_match_success_rate()`
cjyetman adf6e76
minimal documentation
cjyetman 657e216
add to "main functions" family
cjyetman b4a686a
explicitly import %>%
cjyetman 638636b
add minimal test
cjyetman b11afd3
update NEWS
cjyetman 8b00e11
Update R/calculate_match_success_rate.R
cjyetman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #' Calculate the success rate of the matching process | ||
| #' | ||
| #' @param matched A data frame like the validated output of [match_name()]. | ||
| #' | ||
| #' @param loanbook A data frame structured like [r2dii.data::loanbook_demo]. | ||
| #' | ||
| #' @return A data frame. | ||
| #' | ||
| #' @examples | ||
| #' matched <- match_name(r2dii.data::loanbook_demo, r2dii.data::abcd_demo) | ||
| #' calculate_match_success_rate(matched, r2dii.data::loanbook_demo) | ||
| #' | ||
| #' @family main functions | ||
| #' | ||
| #' @importFrom dplyr %>% | ||
| #' | ||
| #' @export | ||
|
|
||
| calculate_match_success_rate <- function(matched, loanbook) { | ||
| merge_by <- | ||
| c( | ||
| sector_classification_system = "code_system", | ||
| sector_classification_direct_loantaker = "code" | ||
| ) | ||
|
|
||
| loanbook_with_sectors <- | ||
| loanbook %>% | ||
| purrr::modify_at(names(merge_by), as.character) %>% | ||
| dplyr::left_join(r2dii.data::sector_classifications, by = merge_by) | ||
|
|
||
| by_cols <- names(matched)[names(matched) %in% names(loanbook_with_sectors)] | ||
|
|
||
| dplyr::left_join(loanbook_with_sectors, matched, by = by_cols) %>% | ||
| dplyr::mutate( | ||
| loan_size_outstanding = as.numeric(.data$loan_size_outstanding), | ||
| loan_size_credit_limit = as.numeric(.data$loan_size_credit_limit), | ||
| matched = dplyr::case_when( | ||
| score == 1 ~ "Matched", | ||
| is.na(score) ~ "Not Matched", | ||
| TRUE ~ "Not Mached" | ||
| ), | ||
| sector = dplyr::case_when( | ||
| borderline == TRUE & matched == "Not Matched" ~ "not in scope", | ||
| TRUE ~ sector | ||
| ) | ||
| ) | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| test_that("returns expected output", { | ||
| loanbook <- fake_lbk( | ||
| name_direct_loantaker = c("Steckel GmbH", "XXX"), | ||
| sector_classification_direct_loantaker = c("C29.1", "C29.1"), | ||
| loan_size_outstanding = c(1e6, 1e6), | ||
| loan_size_credit_limit = c(1e7, 1e7) | ||
| ) | ||
| matched <- match_name(loanbook = loanbook, abcd = r2dii.data::abcd_demo) | ||
| out <- calculate_match_success_rate(matched = matched, loanbook = loanbook) | ||
|
|
||
| expect_s3_class(object = out, class = "data.frame") | ||
| expect_contains(object = names(out), expected = "matched") | ||
| expect_identical(object = out$matched, expected = c("Matched", "Not Matched")) | ||
| }) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.