Skip to content

Commit

Permalink
updates code and tests so that "theme" is presented in the custom sce…
Browse files Browse the repository at this point in the history
…nario table instead of domain
  • Loading branch information
Fox Sebastian (BNSSG CCG) authored and Fox Sebastian (BNSSG CCG) committed Jul 22, 2024
1 parent 1e0d389 commit 9faaed1
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
20 changes: 10 additions & 10 deletions R/fct_scenario_inputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ scenario_inputs <- function(ics_code, horizon, scenario,
domain_type = c("Demand", "Capacity")
) |>
select(
"domain", "metric", "year", "value"
"theme", "metric", "year", "value"
)

end_year_range <- historic_data |>
Expand All @@ -64,7 +64,7 @@ scenario_inputs <- function(ics_code, horizon, scenario,
tidyr::complete(
tidyr::nesting(
!!sym("metric"),
!!sym("domain")
!!sym("theme")
),
year = seq(
from = earliest_end_year,
Expand All @@ -74,7 +74,7 @@ scenario_inputs <- function(ics_code, horizon, scenario,
) |>
dplyr::group_by(
!!sym("metric"),
!!sym("domain")) |>
!!sym("theme")) |>
tidyr::fill(
!!sym("value"),
.direction = "down"
Expand All @@ -91,7 +91,7 @@ scenario_inputs <- function(ics_code, horizon, scenario,
tidyr::complete(
tidyr::nesting(
!!sym("metric"),
!!sym("domain")
!!sym("theme")
),
year = seq(
from = earliest_end_year,
Expand All @@ -101,7 +101,7 @@ scenario_inputs <- function(ics_code, horizon, scenario,
) |>
dplyr::group_by(
!!sym("metric"),
!!sym("domain")) |>
!!sym("theme")) |>
mutate(
index = cumsum(is.na(!!sym("value")))
) |>
Expand All @@ -121,12 +121,12 @@ scenario_inputs <- function(ics_code, horizon, scenario,
!!sym("year") >= max(!!sym("year")) - (linear_years - 1),
.by = c(
!!sym("metric"),
!!sym("domain")
!!sym("theme")
)
) |>
group_by(
!!sym("metric"),
!!sym("domain")
!!sym("theme")
) |>
tidyr::complete(
year = seq(
Expand Down Expand Up @@ -173,7 +173,7 @@ scenario_inputs <- function(ics_code, horizon, scenario,
wide_metric_data <- long_metric_data |>
ungroup() |>
arrange(
!!sym("domain"),
!!sym("theme"),
!!sym("metric"),
!!sym("year")
) |>
Expand Down Expand Up @@ -387,7 +387,7 @@ update_observed_time_period_predictions <- function(model_outputs, r) {
ics_code = r$ics_cd
) |>
dplyr::select(
!c("domain", "numerator", "denominator", "value_type")
!c("domain", "theme", "numerator", "denominator", "value_type")
)

# make wide and create lag versions
Expand Down Expand Up @@ -560,7 +560,7 @@ check_scenario_inputs <- function(inputs, historic_data) {
.by = !!sym("metric")
)

reference_metrics <- c("metric", "domain", "min_val", "max_val")
reference_metrics <- c("metric", "theme", "min_val", "max_val")

inputs <- inputs |>
left_join(
Expand Down
2 changes: 1 addition & 1 deletion R/fct_scenario_modelling.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ model_scenario_data <- function(scenario_data, ics_code, model) {
mutate(
org = ics_code
) |>
select(!c("domain")) |>
select(!c("theme")) |>
tidyr::pivot_longer(
cols = !c("metric", "org"),
names_to = "year",
Expand Down
6 changes: 3 additions & 3 deletions R/mod_02_scenario_planner.R
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ mod_02_scenario_planner_server <- function(id, r){

numeric_cols <- setdiff(
names(r$scenario_data$custom),
c("metric", "domain")
c("metric", "domain", "theme")
)

DT::datatable(
Expand All @@ -454,14 +454,14 @@ mod_02_scenario_planner_server <- function(id, r){
names(r$scenario_data$custom)
) - 2
)
), # disable editing metric and domain fields and previous year values
), # disable editing metric and theme fields and previous year values
numeric = "all" # allow only numeric values
),
extensions = "Buttons",
selection = "none", # don't need to be able to select rows
colnames = c(
"Metric" = "metric",
"Domain" = "domain"
"Theme" = "theme"
),
options = list(
paging = TRUE,
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-fct_data_loading.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ test_that("dimensions of ics_data function", {
)
expect_equal(
names(bnssg_data),
c("year", "org", "domain", "metric", "numerator",
c("year", "org", "domain", "theme", "metric", "numerator",
"denominator", "value", "value_type"),
label = "all field names are as expected"
)
Expand Down
20 changes: 10 additions & 10 deletions tests/testthat/test-fct_scenario_inputs.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ test_that("data dimensions last_known_year ", {
)
expect_equal(
names(df)[1:2],
c("metric", "domain"),
info = "metric and domain are first 2 column names for scenario_inputs() 'last_known_year'"
c("metric", "theme"),
info = "metric and theme are first 2 column names for scenario_inputs() 'last_known_year'"
)
expect_equal(
df |> dplyr::count(metric) |> filter(n > 1) |> nrow(),
Expand All @@ -56,8 +56,8 @@ test_that("data dimensions percent_change ", {
)
expect_equal(
names(df)[1:2],
c("metric", "domain"),
info = "metric and domain are first 2 column names for scenario_inputs() 'percent_change'"
c("metric", "theme"),
info = "metric and theme are first 2 column names for scenario_inputs() 'percent_change'"
)
expect_equal(
df |> dplyr::count(metric) |> filter(n > 1) |> nrow(),
Expand All @@ -80,8 +80,8 @@ test_that("data dimensions linear ", {
)
expect_equal(
names(df)[1:2],
c("metric", "domain"),
info = "metric and domain are first 2 column names for scenario_inputs() 'linear'"
c("metric", "theme"),
info = "metric and theme are first 2 column names for scenario_inputs() 'linear'"
)
expect_equal(
df |> dplyr::count(metric) |> filter(n > 1) |> nrow(),
Expand Down Expand Up @@ -139,8 +139,8 @@ test_that("reset_scenarios works as expected", {
) |>
unlist() |>
unique(),
c("metric", "domain"),
info = "metric and domain are the character fields in the reset_scenarios function"
c("metric", "theme"),
info = "metric and theme are the character fields in the reset_scenarios function"
)

})
Expand Down Expand Up @@ -197,7 +197,7 @@ test_that("the scenario data checker function ensures all values that are not re

inputs <- tibble(
metric = dummy_metrics,
domain = c("Capacity", "Performance", "Demand", "Capacity", "Demand")
theme = c("Capacity", "Performance", "Demand", "Capacity", "Demand")
) |>
cross_join(
tibble(
Expand All @@ -224,7 +224,7 @@ test_that("the scenario data checker function ensures all values that are not re

historic_data <- inputs |>
distinct(
metric, domain
metric, theme
) |>
cross_join(
tibble(
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-fct_scenario_modelling.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ test_that("end to end modelling function works", {
outputs$year,
inputs |>
pivot_longer(
cols = !c("metric", "domain"),
cols = !c("metric", "theme"),
names_to = "year",
values_to = "value"
) |>
Expand Down

0 comments on commit 9faaed1

Please sign in to comment.