generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db293d1
commit eddca43
Showing
5 changed files
with
61 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use ixa::context::Context; | ||
use ixa::define_rng; | ||
use ixa::global_properties::ContextGlobalPropertiesExt; | ||
use ixa::people::{ContextPeopleExt, PersonId, PersonPropertyChangeEvent}; | ||
use ixa::random::ContextRandomExt; | ||
use rand_distr::Exp; | ||
|
||
use crate::population_manager::InfectionStatus; | ||
use crate::population_manager::InfectionStatusType; | ||
use crate::population_manager::Alive; | ||
use crate::Parameters; | ||
|
||
define_rng!(InfectionRng); | ||
|
||
fn schedule_recovery(context: &mut Context, person_id: PersonId) { | ||
let parameters = context.get_global_property_value(Parameters).clone(); | ||
let infection_duration = parameters.infection_duration; | ||
let recovery_time = context.get_current_time() | ||
+ context.sample_distr(InfectionRng, Exp::new(1.0 / infection_duration).unwrap()); | ||
if context.get_person_property(person_id, Alive) { | ||
context.add_plan(recovery_time, move |context| { | ||
context.set_person_property(person_id, InfectionStatusType, InfectionStatus::R); | ||
}); | ||
} | ||
} | ||
|
||
fn handle_infection_status_change( | ||
context: &mut Context, | ||
event: PersonPropertyChangeEvent<InfectionStatusType>, | ||
) { | ||
if matches!(event.current, InfectionStatus::I) { | ||
schedule_recovery(context, event.person_id); | ||
} | ||
} | ||
|
||
pub fn init(context: &mut Context) { | ||
context.subscribe_to_event( | ||
move |context, event: PersonPropertyChangeEvent<InfectionStatusType>| { | ||
handle_infection_status_change(context, event); | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters