From 6fcd95984b6af16635a8f776344039fe19ce2b1f Mon Sep 17 00:00:00 2001 From: Giovanni Charles Date: Thu, 21 Jul 2022 10:44:11 +0100 Subject: [PATCH 1/2] Add ITN usage renderer --- R/processes.R | 3 ++- R/vector_control.R | 10 ++++++++++ tests/testthat/test-vector-control.R | 17 +++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/R/processes.R b/R/processes.R index f5b4b6ee..fc7749ee 100644 --- a/R/processes.R +++ b/R/processes.R @@ -200,7 +200,8 @@ create_processes <- function( events$throw_away_net, parameters, correlations - ) + ), + net_usage_renderer(variables$net_time, renderer) ) } diff --git a/R/vector_control.R b/R/vector_control.R index f197a7d1..0537d746 100644 --- a/R/vector_control.R +++ b/R/vector_control.R @@ -185,3 +185,13 @@ bednet_decay <- function(t, gamma) { spraying_decay <- function(t, theta, gamma) { 1 / (1 + exp(-(theta + gamma * t))) } + +net_usage_renderer <- function(net_time, renderer) { + function(t) { + renderer$render( + 'net_usage', + net_time$get_index_of(-1)$not(TRUE)$size(), + t + ) + } +} diff --git a/tests/testthat/test-vector-control.R b/tests/testthat/test-vector-control.R index 8af13a2e..25a72bf3 100644 --- a/tests/testthat/test-vector-control.R +++ b/tests/testthat/test-vector-control.R @@ -314,3 +314,20 @@ test_that('prob_bitten correctly combines spraying and net probabilities', { tolerance=1e-4 ) }) + +test_that('usage renderer outputs correct values', { + timestep <- 150 + + all <- individual::IntegerVariable$new(c(100, 50, 5, 50)) + half <- individual::IntegerVariable$new(c(100, 50, -1, -1)) + none <- individual::IntegerVariable$new(rep(-1, 4)) + + renderer <- list(render = mockery::mock()) + net_usage_renderer(all, renderer)(timestep) + net_usage_renderer(half, renderer)(timestep) + net_usage_renderer(none, renderer)(timestep) + + mockery::expect_args(renderer$render, 1, 'net_usage', 4, timestep) + mockery::expect_args(renderer$render, 2, 'net_usage', 2, timestep) + mockery::expect_args(renderer$render, 3, 'net_usage', 0, timestep) +}) From 2c71a44fe0ae7db3e64f5d727200d6161c0d24fd Mon Sep 17 00:00:00 2001 From: Giovanni Charles Date: Fri, 22 Jul 2022 15:04:57 +0100 Subject: [PATCH 2/2] Update ITN usage output name --- R/vector_control.R | 2 +- tests/testthat/test-vector-control.R | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/R/vector_control.R b/R/vector_control.R index 0537d746..3272b7f8 100644 --- a/R/vector_control.R +++ b/R/vector_control.R @@ -189,7 +189,7 @@ spraying_decay <- function(t, theta, gamma) { net_usage_renderer <- function(net_time, renderer) { function(t) { renderer$render( - 'net_usage', + 'n_use_net', net_time$get_index_of(-1)$not(TRUE)$size(), t ) diff --git a/tests/testthat/test-vector-control.R b/tests/testthat/test-vector-control.R index 25a72bf3..47a89d9d 100644 --- a/tests/testthat/test-vector-control.R +++ b/tests/testthat/test-vector-control.R @@ -327,7 +327,7 @@ test_that('usage renderer outputs correct values', { net_usage_renderer(half, renderer)(timestep) net_usage_renderer(none, renderer)(timestep) - mockery::expect_args(renderer$render, 1, 'net_usage', 4, timestep) - mockery::expect_args(renderer$render, 2, 'net_usage', 2, timestep) - mockery::expect_args(renderer$render, 3, 'net_usage', 0, timestep) + mockery::expect_args(renderer$render, 1, 'n_use_net', 4, timestep) + mockery::expect_args(renderer$render, 2, 'n_use_net', 2, timestep) + mockery::expect_args(renderer$render, 3, 'n_use_net', 0, timestep) })