-
Notifications
You must be signed in to change notification settings - Fork 0
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
profile_sector()
now handles case "c"
#282
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,5 @@ prepare_inter_sector_profile <- function(sp_prod, europages_companies, ecoinvent | |
left_join(ecoinvent_activities, by = "activity_uuid_product_uuid") |> | ||
left_join(ecoinvent_europages, by = c("country", "main_activity", "clustered", "activity_uuid_product_uuid")) |> | ||
left_join(isic, by = "isic_4digit") |> | ||
add_avg_matching_certainty("completion") |> | ||
exclude_rows("risk_category") | ||
Comment on lines
-11
to
-12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the main "bug". |
||
add_avg_matching_certainty("completion") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
recode_scenario <- function(x) { | ||
out <- gsub("^ipr|^weo", "", x, ignore.case = TRUE) | ||
out <- gsub("_", " ", out) | ||
tolower(trimws(out)) | ||
} | ||
Comment on lines
+1
to
+5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This helper aims to recode the values of If you keep this function do test it because a test suggest we may want something like "ns 2050" but instead we get "ns 2050 2030". |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,3 +271,37 @@ test_that("outputs `profile_ranking_avg` at company level", { | |
company <- unnest_company(out) | ||
expect_true(hasName(company, "reduction_targets_avg")) | ||
}) | ||
|
||
test_that("given a product in 'ipr', when scenarios has also 'weo', then the product-result includes a 'weo*' `scenario` and maps to `NA` in `sector_profile` (#279, tiltIndicator#739)", { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's the test for the specific case associated to this issue. Meeting this expectation breaks other tests so the job is incomplete. |
||
one_type <- "ipr" | ||
companies <- read_csv(toy_sector_profile_companies()) |> | ||
filter(type == one_type) |> | ||
head(1) | ||
|
||
scenarios <- read_csv(toy_sector_profile_any_scenarios()) | ||
has_two_types <- all(sort(unique(scenarios$type)) %in% c("ipr", "weo")) | ||
stopifnot(has_two_types) | ||
|
||
europages_companies <- read_csv(toy_europages_companies()) | ||
ecoinvent_activities <- read_csv(toy_ecoinvent_activities()) | ||
ecoinvent_europages <- read_csv(toy_ecoinvent_europages()) | ||
isic_name <- read_csv(toy_isic_name()) | ||
|
||
product <- profile_sector( | ||
companies, | ||
scenarios, | ||
europages_companies, | ||
ecoinvent_activities, | ||
ecoinvent_europages, | ||
isic_name | ||
) |> | ||
unnest_product() | ||
|
||
# `product` results include `scanario` coming from both "ipr" and "weo" | ||
expect_true(any(grepl(c(ipr = "1.5"), product$scenario))) | ||
expect_true(any(grepl(c(weo = "nz"), product$scenario))) | ||
|
||
# All rows where `scenario` comes from "weo" map to `NA` in `sector_profile` | ||
weo <- product |> filter(grepl(c(weo = "nz"), scenario)) | ||
expect_true(all(is.na(weo$sector_profile))) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I write a custom helper to recode scenario in a more robust way. It may be wrong but the idea may be useful. I'll discuss in the helper itself.