Skip to content

Commit

Permalink
Calculate "sealed" within distribute_measures()
Browse files Browse the repository at this point in the history
  • Loading branch information
hsonne committed Jul 23, 2024
1 parent b95a238 commit b82f4a1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
11 changes: 11 additions & 0 deletions R/distribute_measures.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ distribute_measures <- function(blocks, targets, intermediates = FALSE)
blocks$pvd <- unpaved_area_table$pvd
blocks$to_swale <- swale_connection_table$to_swale

# Recalculate "sealed"
blocks$sealed <- get_sealed(blocks)

# Return the tables with intermediate values as attributes, if requested
if (intermediates) {
return(structure(
Expand Down Expand Up @@ -199,3 +202,11 @@ get_to_swale_area <- function(blocks)
{
select_columns(blocks, "to_swale") * get_sealed_area(blocks)
}

# get_sealed -------------------------------------------------------------------
get_sealed <- function(blocks)
{
dividend <- get_roof_area(blocks) + get_paved_area(blocks)
divisor <- kwb.utils::selectColumns(blocks, "total_area")
ifelse(dividend > 0, dividend / divisor, 0)
}
13 changes: 1 addition & 12 deletions inst/scripts/distribute-measures.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,6 @@ if (FALSE)
blocks, targets = new_targets, intermediates = TRUE
)

new_blocks$sealed <- get_sealed(new_blocks)

# Current mean degrees of application of measures
check_equality(unlist(get_measure_means(new_blocks)), new_targets)

Expand Down Expand Up @@ -135,7 +133,7 @@ create_example_blocks <- function(block_areas)
blocks$swg_pvd_r <- 1

blocks$roof <- get_roof(cbind(blocks, block_areas))
blocks$sealed <- get_sealed(blocks)
blocks$sealed <- kwb.rabimo:::get_sealed(blocks)
blocks$to_swale <- get_to_swale(cbind(blocks, block_areas))

# Provide columns in the same order as they are stored in the package
Expand Down Expand Up @@ -320,15 +318,6 @@ get_unpaved <- function(blocks) {
kwb.rabimo:::get_main_area(blocks)
}

# get_sealed -------------------------------------------------------------------
get_sealed <- function(blocks) {
quotient_or_zero(
dividend = kwb.rabimo:::get_roof_area(blocks) +
kwb.rabimo:::get_paved_area(blocks),
divisor = kwb.utils::selectColumns(blocks, "total_area")
)
}

# get_to_swale -----------------------------------------------------------------
get_to_swale <- function(blocks) {
quotient_or_zero(
Expand Down

0 comments on commit b82f4a1

Please sign in to comment.