Skip to content

Commit

Permalink
bugs + last_year vars
Browse files Browse the repository at this point in the history
  • Loading branch information
htopazian committed May 17, 2024
1 parent b7b4a12 commit bb3bb05
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
3 changes: 3 additions & 0 deletions R/mortality_processes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 5 additions & 2 deletions R/pev.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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,
Expand All @@ -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)) {
Expand All @@ -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(
Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion R/processes.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ create_processes <- function(
)

# =========
# RTS,S EPI
# PEV EPI
# =========
if (!is.null(parameters$pev_epi_coverage)) {
processes <- c(
Expand Down Expand Up @@ -239,6 +239,7 @@ create_processes <- function(
processes,
distribute_nets(
variables,
renderer,
events$throw_away_net,
parameters,
correlations
Expand Down
17 changes: 11 additions & 6 deletions R/vector_control.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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)
}
}

Expand All @@ -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)) {
Expand All @@ -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)
}
}

Expand Down

0 comments on commit bb3bb05

Please sign in to comment.