Skip to content

Commit

Permalink
Fully abstracted facemask from intervention mgr
Browse files Browse the repository at this point in the history
  • Loading branch information
KOVALW committed Dec 13, 2024
1 parent 440bf35 commit fdb9fc6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 25 deletions.
18 changes: 14 additions & 4 deletions src/facemask_manager.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
use crate::intervention_manager::{ContextInterventionExt, FacemaskStatus, FacemaskStatusType};
use crate::intervention_manager::ContextInterventionExt;
use crate::parameters::Parameters;
use crate::population_loader::Alive;
use crate::transmission_manager::InfectiousStatusType;
use ixa::{
define_rng, Context, ContextGlobalPropertiesExt, ContextPeopleExt, ContextRandomExt, PersonId,
define_person_property, define_person_property_with_default, define_rng, Context,
ContextGlobalPropertiesExt, ContextPeopleExt, ContextRandomExt, PersonId,
};
use std::hash::Hash;

#[derive(Debug, PartialEq, Clone, Copy, Eq, Hash)]
pub enum FacemaskStatusType {
None,
Wearing,
}

define_person_property_with_default!(FacemaskStatus, FacemaskStatusType, FacemaskStatusType::None);

define_rng!(FacemaskRng);

pub fn init(context: &mut Context) {
context.register_facemask(
context.register_intervention(
InfectiousStatusType::Susceptible,
FacemaskStatusType::Wearing,
0.5,
);
context.register_facemask(
context.register_intervention(
InfectiousStatusType::Infectious,
FacemaskStatusType::Wearing,
0.25,
Expand Down
31 changes: 11 additions & 20 deletions src/intervention_manager.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
use crate::transmission_manager::{InfectiousStatus, InfectiousStatusType};
use ixa::{
define_data_plugin, define_person_property, define_person_property_with_default,
people::ContextPeopleExt, Context, PersonId, PersonProperty,
};
use std::{collections::HashMap, hash::Hash};
use ixa::{define_data_plugin, people::ContextPeopleExt, Context, PersonId, PersonProperty};
use std::collections::HashMap;

#[derive(Debug, PartialEq, Clone, Copy, Eq, Hash)]
pub enum FacemaskStatusType {
None,
Wearing,
}
struct InterventionContainer {
intervention_map: HashMap<InfectiousStatusType, HashMap<String, f64>>,
}
Expand All @@ -22,8 +14,6 @@ define_data_plugin!(
}
);

define_person_property_with_default!(FacemaskStatus, FacemaskStatusType, FacemaskStatusType::None);

pub fn init(context: &mut Context) {
let _ = context.get_data_container_mut(InterventionPlugin);
}
Expand All @@ -34,10 +24,10 @@ pub trait ContextInterventionExt {
person_id: PersonId,
intervention_type: T,
) -> f64;
fn register_facemask(
fn register_intervention<T: std::fmt::Debug>(
&mut self,
infectious_status: InfectiousStatusType,
facemask_status: FacemaskStatusType,
intervention_status: T,
relative_transmission: f64,
);
}
Expand All @@ -62,25 +52,26 @@ impl ContextInterventionExt for Context {
.unwrap_or(&1.0)
}

fn register_facemask(
fn register_intervention<T: std::fmt::Debug>(
&mut self,
infectious_status: InfectiousStatusType,
facemask_status: FacemaskStatusType,
intervention_status: T,
relative_transmission: f64,
) {
let mut facemask_map = HashMap::new();
let mut transmission_map = HashMap::new();

facemask_map.insert(format!("{facemask_status:?}"), relative_transmission);
transmission_map.insert(format!("{intervention_status:?}"), relative_transmission);

self.get_data_container_mut(InterventionPlugin)
.intervention_map
.insert(infectious_status, facemask_map);
.insert(infectious_status, transmission_map);
}
}

#[cfg(test)]
mod test {
use super::*;
use crate::facemask_manager::{FacemaskStatus, FacemaskStatusType};
use ixa::{people::ContextPeopleExt, Context};

#[test]
Expand All @@ -89,7 +80,7 @@ mod test {
let mut context = Context::new();
let contact_id = context.add_person(()).unwrap();

context.register_facemask(
context.register_intervention(
InfectiousStatusType::Susceptible,
FacemaskStatusType::Wearing,
0.5,
Expand Down
3 changes: 2 additions & 1 deletion src/transmission_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use ixa::{
};
use statrs::distribution::{ContinuousCDF, Exp, Poisson};

use crate::intervention_manager::{ContextInterventionExt, FacemaskStatus};
use crate::facemask_manager::FacemaskStatus;
use crate::intervention_manager::ContextInterventionExt;
use crate::parameters::Parameters;
use crate::{contact::ContextContactExt, population_loader::Alive};

Expand Down

0 comments on commit fdb9fc6

Please sign in to comment.