From bb3bb05acea36474d68ad776061aa73f69dcda74 Mon Sep 17 00:00:00 2001 From: Hillary Topazian <80535782+htopazian@users.noreply.github.com> Date: Fri, 17 May 2024 10:12:41 +0100 Subject: [PATCH] bugs + last_year vars --- R/mortality_processes.R | 3 +++ R/pev.R | 7 +++++-- R/processes.R | 3 ++- R/vector_control.R | 17 +++++++++++------ 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/R/mortality_processes.R b/R/mortality_processes.R index 39606ca0..592edcdc 100644 --- a/R/mortality_processes.R +++ b/R/mortality_processes.R @@ -113,6 +113,9 @@ reset_target <- function(variables, events, target, state, parameters, timestep) variables$pev_profile$queue_update(-1, target) variables$tbv_vaccinated$queue_update(-1, target) + # spraying + variables$spray_time$queue_update(-1, target) + # onwards infectiousness variables$infectivity$queue_update(0, target) diff --git a/R/pev.R b/R/pev.R index 25e20264..989fdde3 100644 --- a/R/pev.R +++ b/R/pev.R @@ -25,7 +25,7 @@ create_epi_pev_process <- function( if(coverage == 0){ return() } - + to_vaccinate <- variables$birth$get_index_of( set = timestep - parameters$pev_epi_age ) @@ -77,6 +77,7 @@ create_epi_pev_process <- function( #' @param events a list of events in the model #' @param parameters the model parameters #' @param correlations correlation parameters +#' @param renderer the model renderer object #' @noRd create_mass_pev_listener <- function( variables, @@ -86,6 +87,7 @@ create_mass_pev_listener <- function( renderer ) { renderer$set_default('n_new_vaccinations', 0) + renderer$set_default('n_pev_last_year', 0) function(timestep) { in_age_group <- individual::Bitset$new(parameters$human_population) for (i in seq_along(parameters$mass_pev_min_ages)) { @@ -111,7 +113,7 @@ create_mass_pev_listener <- function( } else { target <- target$to_vector() } - + time_index = which(parameters$mass_pev_timesteps == timestep) target <- target[ sample_intervention( @@ -129,6 +131,7 @@ create_mass_pev_listener <- function( )$size() renderer$render('n_new_vaccinations', n_new_vaccinations, timestep) + renderer$render('n_pev_last_year', used_intervention(variables$last_pev_timestep, timestep, 365)$size(), timestep) # Update the latest vaccination time variables$last_pev_timestep$queue_update(timestep, target) diff --git a/R/processes.R b/R/processes.R index 1a57626b..40bd581d 100644 --- a/R/processes.R +++ b/R/processes.R @@ -143,7 +143,7 @@ create_processes <- function( ) # ========= - # RTS,S EPI + # PEV EPI # ========= if (!is.null(parameters$pev_epi_coverage)) { processes <- c( @@ -239,6 +239,7 @@ create_processes <- function( processes, distribute_nets( variables, + renderer, events$throw_away_net, parameters, correlations diff --git a/R/vector_control.R b/R/vector_control.R index 34060b4c..dab6e1e5 100644 --- a/R/vector_control.R +++ b/R/vector_control.R @@ -102,13 +102,13 @@ prob_bitten <- function( #' `get_correlation_parameters` #' #' @param spray_time the variable for the time of spraying -#' @param renderer items to render +#' @param renderer the model renderer object #' @param parameters the model parameters #' @param correlations correlation parameters #' @noRd indoor_spraying <- function(spray_time, renderer, parameters, correlations) { - renderer$set_default("n_spray", 0) - renderer$set_default("spray_last_year", 0) + renderer$set_default('n_spray', 0) + renderer$set_default('n_spray_last_year', 0) function(timestep) { matches <- timestep == parameters$spraying_timesteps if (any(matches)) { @@ -119,9 +119,9 @@ indoor_spraying <- function(spray_time, renderer, parameters, correlations) { correlations )) spray_time$queue_update(timestep, target) - renderer$render("n_spray", length(target), timestep) + renderer$render('n_spray', length(target), timestep) } - renderer$render("spray_last_year", used_intervention(spray_time, timestep, 365)$size(), timestep) + renderer$render('n_spray_last_year', used_intervention(spray_time, timestep, 365)$size(), timestep) } } @@ -132,11 +132,14 @@ indoor_spraying <- function(spray_time, renderer, parameters, correlations) { #' `get_correlation_parameters` #' #' @param variables list of variables in the model +#' @param renderer the model renderer object #' @param throw_away_net an event to trigger when the net will be removed #' @param parameters the model parameters #' @param correlations correlation parameters #' @noRd -distribute_nets <- function(variables, throw_away_net, parameters, correlations) { +distribute_nets <- function(variables, renderer, throw_away_net, parameters, correlations) { + renderer$set_default('n_net', 0) + renderer$set_default('n_net_last_year', 0) function(timestep) { matches <- timestep == parameters$bednet_timesteps if (any(matches)) { @@ -152,7 +155,9 @@ distribute_nets <- function(variables, throw_away_net, parameters, correlations) target, log_uniform(length(target), parameters$bednet_retention) ) + renderer$render('n_net', length(target), timestep) } + renderer$render('n_net_last_year', used_intervention(variables$net_time, timestep, 365)$size(), timestep) } }