From c9bab221eab56a145953e029961e3d5c2e252879 Mon Sep 17 00:00:00 2001 From: Kate Hudson <145493147+k88hudson-cfa@users.noreply.github.com> Date: Thu, 12 Dec 2024 16:33:45 -0500 Subject: [PATCH] Properties should use the convention N, NValue (#121) Fixes #120 --- examples/births-deaths/README.md | 2 +- examples/births-deaths/incidence_report.rs | 8 +- examples/births-deaths/infection_manager.rs | 18 +- examples/births-deaths/population_manager.rs | 9 +- .../births-deaths/transmission_manager.rs | 10 +- examples/load-people/README.md | 12 +- examples/load-people/logger.rs | 4 +- examples/load-people/population_loader.rs | 14 +- examples/load-people/sir.rs | 36 ++-- examples/load-people/vaccine.rs | 8 +- .../parameter-loading/incidence_report.rs | 8 +- .../parameter-loading/infection_manager.rs | 16 +- examples/parameter-loading/main.rs | 8 +- .../parameter-loading/transmission_manager.rs | 14 +- examples/time-varying-infection/README.md | 20 +-- .../exposure_manager.rs | 10 +- .../incidence_report.rs | 14 +- .../infection_manager.rs | 30 ++-- examples/time-varying-infection/main.rs | 4 +- examples/time-varying-infection/plot_output.R | 2 +- .../population_loader.rs | 4 +- src/people.rs | 158 +++++++++--------- 22 files changed, 206 insertions(+), 203 deletions(-) diff --git a/examples/births-deaths/README.md b/examples/births-deaths/README.md index 0055c0c4..1a02f22e 100644 --- a/examples/births-deaths/README.md +++ b/examples/births-deaths/README.md @@ -112,7 +112,7 @@ Infected individuals are scheduled to recover based on the infection period. The ```rust let plan_id = context .add_plan(recovery_time, move |context| { -context.set_person_property(person_id, InfectionStatusType, InfectionStatus::R); +context.set_person_property(person_id, InfectionStatus, InfectionStatusValue::R); }) .clone(); let plans_data_container = context.get_data_container_mut(InfectionPlansPlugin); diff --git a/examples/births-deaths/incidence_report.rs b/examples/births-deaths/incidence_report.rs index ba4bb54d..daac39b5 100644 --- a/examples/births-deaths/incidence_report.rs +++ b/examples/births-deaths/incidence_report.rs @@ -8,7 +8,7 @@ use std::path::Path; use std::path::PathBuf; use crate::population_manager::{ - Age, AgeGroupFoi, AgeGroupRisk, InfectionStatus, InfectionStatusType, + Age, AgeGroupFoi, AgeGroupRisk, InfectionStatus, InfectionStatusValue, }; use serde::{Deserialize, Serialize}; @@ -21,14 +21,14 @@ struct IncidenceReportItem { person_id: String, age_group: AgeGroupRisk, age: u8, - infection_status: InfectionStatus, + infection_status: InfectionStatusValue, } create_report_trait!(IncidenceReportItem); fn handle_infection_status_change( context: &mut Context, - event: PersonPropertyChangeEvent, + event: PersonPropertyChangeEvent, ) { let age_person = context.get_person_property(event.person_id, Age); let age_group_person = context.get_person_property(event.person_id, AgeGroupFoi); @@ -53,7 +53,7 @@ pub fn init(context: &mut Context) -> Result<(), IxaError> { context.add_report::(¶meters.output_file)?; context.subscribe_to_event( - |context, event: PersonPropertyChangeEvent| { + |context, event: PersonPropertyChangeEvent| { handle_infection_status_change(context, event); }, ); diff --git a/examples/births-deaths/infection_manager.rs b/examples/births-deaths/infection_manager.rs index a00bd92b..b219f9fc 100644 --- a/examples/births-deaths/infection_manager.rs +++ b/examples/births-deaths/infection_manager.rs @@ -1,6 +1,6 @@ use crate::population_manager::Alive; use crate::population_manager::InfectionStatus; -use crate::population_manager::InfectionStatusType; +use crate::population_manager::InfectionStatusValue; use crate::Parameters; use ixa::context::Context; use ixa::define_data_plugin; @@ -37,7 +37,7 @@ fn schedule_recovery(context: &mut Context, person_id: PersonId) { if context.get_person_property(person_id, Alive) { let plan_id = context.add_plan(recovery_time, move |context| { - context.set_person_property(person_id, InfectionStatusType, InfectionStatus::R); + context.set_person_property(person_id, InfectionStatus, InfectionStatusValue::R); }); let plans_data_container = context.get_data_container_mut(InfectionPlansPlugin); plans_data_container @@ -70,12 +70,12 @@ fn cancel_recovery_plans(context: &mut Context, person_id: PersonId) { fn handle_infection_status_change( context: &mut Context, - event: PersonPropertyChangeEvent, + event: PersonPropertyChangeEvent, ) { - if matches!(event.current, InfectionStatus::I) { + if matches!(event.current, InfectionStatusValue::I) { schedule_recovery(context, event.person_id); } - if matches!(event.current, InfectionStatus::R) { + if matches!(event.current, InfectionStatusValue::R) { remove_recovery_plan_data(context, event.person_id); } } @@ -87,7 +87,7 @@ fn handle_person_removal(context: &mut Context, event: PersonPropertyChangeEvent } pub fn init(context: &mut Context) { context.subscribe_to_event( - move |context, event: PersonPropertyChangeEvent| { + move |context, event: PersonPropertyChangeEvent| { handle_infection_status_change(context, event); }, ); @@ -134,8 +134,8 @@ mod test { init(&mut context); context.subscribe_to_event( - move |context, event: PersonPropertyChangeEvent| { - if matches!(event.current, InfectionStatus::R) { + move |context, event: PersonPropertyChangeEvent| { + if matches!(event.current, InfectionStatusValue::R) { *context.get_data_container_mut(RecoveryPlugin) += 1; } }, @@ -146,7 +146,7 @@ mod test { let person = context.create_new_person(0); context.add_plan(1.0, move |context| { - context.set_person_property(person, InfectionStatusType, InfectionStatus::I); + context.set_person_property(person, InfectionStatus, InfectionStatusValue::I); }); if index == 0 { diff --git a/examples/births-deaths/population_manager.rs b/examples/births-deaths/population_manager.rs index b5df1b3d..0d07db80 100644 --- a/examples/births-deaths/population_manager.rs +++ b/examples/births-deaths/population_manager.rs @@ -16,7 +16,7 @@ use serde::Serialize; use std::fmt; #[derive(Debug, Hash, Eq, PartialEq, Clone, Copy, Serialize, Deserialize)] -pub enum InfectionStatus { +pub enum InfectionStatusValue { S, I, R, @@ -35,8 +35,11 @@ impl fmt::Display for AgeGroupRisk { } } -define_person_property_with_default!(InfectionStatusType, InfectionStatus, InfectionStatus::S); - +define_person_property_with_default!( + InfectionStatus, + InfectionStatusValue, + InfectionStatusValue::S +); define_person_property!(Age, u8); define_person_property_with_default!(Alive, bool, true); define_derived_property!(AgeGroupFoi, AgeGroupRisk, [Age], |age| { diff --git a/examples/births-deaths/transmission_manager.rs b/examples/births-deaths/transmission_manager.rs index a3914100..5df11df1 100644 --- a/examples/births-deaths/transmission_manager.rs +++ b/examples/births-deaths/transmission_manager.rs @@ -8,7 +8,7 @@ use crate::parameters_loader::Foi; use crate::population_manager::AgeGroupRisk; use crate::population_manager::ContextPopulationExt; use crate::population_manager::InfectionStatus; -use crate::population_manager::InfectionStatusType; +use crate::population_manager::InfectionStatusValue; use crate::Parameters; use rand_distr::Exp; @@ -29,11 +29,11 @@ fn attempt_infection(context: &mut Context, age_group: AgeGroupRisk) { if population_size > 0 { let person_to_infect = context.sample_person(age_group).unwrap(); - let person_status: InfectionStatus = - context.get_person_property(person_to_infect, InfectionStatusType); + let person_status: InfectionStatusValue = + context.get_person_property(person_to_infect, InfectionStatus); - if matches!(person_status, InfectionStatus::S) { - context.set_person_property(person_to_infect, InfectionStatusType, InfectionStatus::I); + if matches!(person_status, InfectionStatusValue::S) { + context.set_person_property(person_to_infect, InfectionStatus, InfectionStatusValue::I); } #[allow(clippy::cast_precision_loss)] let next_attempt_time = context.get_current_time() diff --git a/examples/load-people/README.md b/examples/load-people/README.md index ad74421c..2d0bae52 100644 --- a/examples/load-people/README.md +++ b/examples/load-people/README.md @@ -33,10 +33,10 @@ For example, this model implements Age and RiskStatus using ```rust #[derive(Copy)] -pub enum RiskCategory { High, Low } +pub enum RiskCategoryValue { High, Low } define_person_property!(Age, u8); -define_person_property!(RiskCategoryType, RiskCategory); +define_person_property!(RiskCategory, RiskCategoryValue); ``` Person property value types **must** implement `Copy` in order to make them efficient @@ -73,8 +73,8 @@ status: ```rust #[derive(Copy)] -pub enum DiseaseStatus { S, I, R } -define_person_property_with_default!(DiseaseStatusType, DiseaseStatus, DiseaseStatus::S); +pub enum DiseaseStatusValue { S, I, R } +define_person_property_with_default!(DiseaseStatus, DiseaseStatusValue, DiseaseStatus::S); ``` #### Custom initializer @@ -133,7 +133,7 @@ You can see an example of this in `population_loader.rs`: ```rust let person = context.add_person(); context.set_person_property(person, Age, record.age); -context.set_person_property(person, RiskCategoryType, record.risk_category); +context.set_person_property(person, RiskCategory, record.risk_category); let (vaccine_efficacy, vaccine_type) = context.generate_vaccine_props(record.risk_category); context.set_person_property(person, VaccineEfficacy, vaccine_efficacy); context.set_person_property(person, VaccineType, vaccine_type); @@ -151,7 +151,7 @@ that when properties are first set, they will *not* emit any change events; ```rust context.subscribe_to_event( - |_context, event: PersonPropertyChangeEvent| { + |_context, event: PersonPropertyChangeEvent| { let person = event.person_id; println!( "Person {} changed disease status from {:?} to {:?}", diff --git a/examples/load-people/logger.rs b/examples/load-people/logger.rs index 72e390d6..36d41be9 100644 --- a/examples/load-people/logger.rs +++ b/examples/load-people/logger.rs @@ -1,6 +1,6 @@ use crate::{ population_loader::Age, - sir::DiseaseStatusType, + sir::DiseaseStatus, vaccine::{VaccineDoses, VaccineEfficacy, VaccineType}, }; use ixa::{ @@ -12,7 +12,7 @@ pub fn init(context: &mut Context) { // This subscribes to the disease status change events // Note that no event gets fired when the property is set the first time context.subscribe_to_event( - |_context, event: PersonPropertyChangeEvent| { + |_context, event: PersonPropertyChangeEvent| { let person = event.person_id; println!( "{:?} changed disease status from {:?} to {:?}", diff --git a/examples/load-people/population_loader.rs b/examples/load-people/population_loader.rs index 598e5c07..788a824a 100644 --- a/examples/load-people/population_loader.rs +++ b/examples/load-people/population_loader.rs @@ -7,7 +7,7 @@ use ixa::{ContextPeopleExt, PersonId}; use serde::Deserialize; #[derive(Deserialize, Copy, Clone, PartialEq, Eq, Debug, Hash)] -pub enum RiskCategory { +pub enum RiskCategoryValue { High, Low, } @@ -15,18 +15,18 @@ pub enum RiskCategory { #[derive(Deserialize, Debug)] struct PeopleRecord { age: u8, - risk_category: RiskCategory, + risk_category: RiskCategoryValue, } define_person_property!(Age, u8); -define_person_property!(RiskCategoryType, RiskCategory); +define_person_property!(RiskCategory, RiskCategoryValue); fn create_person_from_record(context: &mut Context, record: &PeopleRecord) -> PersonId { let (t, e) = context.get_vaccine_props(record.risk_category); context .add_person(( (Age, record.age), - (RiskCategoryType, record.risk_category), + (RiskCategory, record.risk_category), (VaccineType, t), (VaccineEfficacy, e), )) @@ -75,8 +75,8 @@ mod tests { // Define expected computed values for each person let expected_computed = vec![ - (20, RiskCategory::Low, VaccineTypeValue::B, 0.8, 1), - (80, RiskCategory::High, VaccineTypeValue::A, 0.9, 2), + (20, RiskCategoryValue::Low, VaccineTypeValue::B, 0.8, 1), + (80, RiskCategoryValue::High, VaccineTypeValue::A, 0.9, 2), ]; let mut context = Context::new(); @@ -105,7 +105,7 @@ mod tests { assert_eq!(context.get_person_property(person, Age), age); assert_eq!( - context.get_person_property(person, RiskCategoryType), + context.get_person_property(person, RiskCategory), risk_category ); assert_eq!( diff --git a/examples/load-people/sir.rs b/examples/load-people/sir.rs index b59e1c20..20dc2ce3 100644 --- a/examples/load-people/sir.rs +++ b/examples/load-people/sir.rs @@ -5,22 +5,22 @@ use ixa::{ }; #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] -pub enum DiseaseStatus { +pub enum DiseaseStatusValue { S, I, R, } -define_person_property_with_default!(DiseaseStatusType, DiseaseStatus, DiseaseStatus::S); +define_person_property_with_default!(DiseaseStatus, DiseaseStatusValue, DiseaseStatusValue::S); pub fn init(context: &mut Context) { context.subscribe_to_event(move |context, event: PersonCreatedEvent| { let person = event.person_id; context.add_plan(1.0, move |context| { - context.set_person_property(person, DiseaseStatusType, DiseaseStatus::I); + context.set_person_property(person, DiseaseStatus, DiseaseStatusValue::I); }); context.add_plan(2.0, move |context| { - context.set_person_property(person, DiseaseStatusType, DiseaseStatus::R); + context.set_person_property(person, DiseaseStatus, DiseaseStatusValue::R); }); }); } @@ -39,29 +39,27 @@ mod tests { // People should start in the S state assert_eq!( - context.get_person_property(person, DiseaseStatusType), - DiseaseStatus::S + context.get_person_property(person, DiseaseStatus), + DiseaseStatusValue::S ); // At 1.0, people should be in the I state - context.subscribe_to_event( - |context, event: PersonPropertyChangeEvent| { - let person = event.person_id; - if context.get_current_time() == 1.0 { - assert_eq!( - context.get_person_property(person, DiseaseStatusType), - DiseaseStatus::I - ); - } - }, - ); + context.subscribe_to_event(|context, event: PersonPropertyChangeEvent| { + let person = event.person_id; + if context.get_current_time() == 1.0 { + assert_eq!( + context.get_person_property(person, DiseaseStatus), + DiseaseStatusValue::I + ); + } + }); context.execute(); // People should end up in the R state by the end of the simulation assert_eq!( - context.get_person_property(person, DiseaseStatusType), - DiseaseStatus::R + context.get_person_property(person, DiseaseStatus), + DiseaseStatusValue::R ); } } diff --git a/examples/load-people/vaccine.rs b/examples/load-people/vaccine.rs index b7055479..700b769c 100644 --- a/examples/load-people/vaccine.rs +++ b/examples/load-people/vaccine.rs @@ -1,6 +1,6 @@ use std::hash::Hash; -use crate::population_loader::{Age, RiskCategory}; +use crate::population_loader::{Age, RiskCategoryValue}; use ixa::{ context::Context, define_person_property, define_rng, people::ContextPeopleExt, random::ContextRandomExt, @@ -28,15 +28,15 @@ define_person_property!(VaccineDoses, u8, |context: &Context, person_id| { }); pub trait ContextVaccineExt { - fn get_vaccine_props(&self, risk: RiskCategory) -> (VaccineTypeValue, OrderedFloat); + fn get_vaccine_props(&self, risk: RiskCategoryValue) -> (VaccineTypeValue, OrderedFloat); } impl ContextVaccineExt for Context { fn get_vaccine_props( self: &Context, - risk: RiskCategory, + risk: RiskCategoryValue, ) -> (VaccineTypeValue, OrderedFloat) { - if risk == RiskCategory::High { + if risk == RiskCategoryValue::High { (VaccineTypeValue::A, OrderedFloat(0.9)) } else { (VaccineTypeValue::B, OrderedFloat(0.8)) diff --git a/examples/parameter-loading/incidence_report.rs b/examples/parameter-loading/incidence_report.rs index 8f1eaa1c..79e9516d 100644 --- a/examples/parameter-loading/incidence_report.rs +++ b/examples/parameter-loading/incidence_report.rs @@ -7,7 +7,7 @@ use ixa::{create_report_trait, report::Report}; use std::path::PathBuf; use crate::InfectionStatus; -use crate::InfectionStatusType; +use crate::InfectionStatusValue; use serde::{Deserialize, Serialize}; use crate::Parameters; @@ -16,14 +16,14 @@ use crate::Parameters; struct IncidenceReportItem { time: f64, person_id: String, - infection_status: InfectionStatus, + infection_status: InfectionStatusValue, } create_report_trait!(IncidenceReportItem); fn handle_infection_status_change( context: &mut Context, - event: PersonPropertyChangeEvent, + event: PersonPropertyChangeEvent, ) { context.send_report(IncidenceReportItem { time: context.get_current_time(), @@ -42,7 +42,7 @@ pub fn init(context: &mut Context) -> Result<(), IxaError> { .directory(PathBuf::from(parameters.output_dir)); context.add_report::(¶meters.output_file)?; context.subscribe_to_event( - |context, event: PersonPropertyChangeEvent| { + |context, event: PersonPropertyChangeEvent| { handle_infection_status_change(context, event); }, ); diff --git a/examples/parameter-loading/infection_manager.rs b/examples/parameter-loading/infection_manager.rs index 0a70600f..af4cbf21 100644 --- a/examples/parameter-loading/infection_manager.rs +++ b/examples/parameter-loading/infection_manager.rs @@ -6,7 +6,7 @@ use ixa::random::ContextRandomExt; use rand_distr::Exp; use crate::InfectionStatus; -use crate::InfectionStatusType; +use crate::InfectionStatusValue; use crate::Parameters; define_rng!(InfectionRng); @@ -20,22 +20,22 @@ fn schedule_recovery(context: &mut Context, person_id: PersonId) { let recovery_time = context.get_current_time() + context.sample_distr(InfectionRng, Exp::new(1.0 / infection_duration).unwrap()); context.add_plan(recovery_time, move |context| { - context.set_person_property(person_id, InfectionStatusType, InfectionStatus::R); + context.set_person_property(person_id, InfectionStatus, InfectionStatusValue::R); }); } fn handle_infection_status_change( context: &mut Context, - event: PersonPropertyChangeEvent, + event: PersonPropertyChangeEvent, ) { - if matches!(event.current, InfectionStatus::I) { + if matches!(event.current, InfectionStatusValue::I) { schedule_recovery(context, event.person_id); } } pub fn init(context: &mut Context) { context.subscribe_to_event( - move |context, event: PersonPropertyChangeEvent| { + move |context, event: PersonPropertyChangeEvent| { handle_infection_status_change(context, event); }, ); @@ -73,8 +73,8 @@ mod test { init(&mut context); context.subscribe_to_event( - move |context, event: PersonPropertyChangeEvent| { - if matches!(event.current, InfectionStatus::R) { + move |context, event: PersonPropertyChangeEvent| { + if matches!(event.current, InfectionStatusValue::R) { *context.get_data_container_mut(RecoveryPlugin) += 1; } }, @@ -85,7 +85,7 @@ mod test { let person = context.add_person(()).unwrap(); context.add_plan(1.0, move |context| { - context.set_person_property(person, InfectionStatusType, InfectionStatus::I); + context.set_person_property(person, InfectionStatus, InfectionStatusValue::I); }); } context.execute(); diff --git a/examples/parameter-loading/main.rs b/examples/parameter-loading/main.rs index 380e8454..3af9ebd6 100644 --- a/examples/parameter-loading/main.rs +++ b/examples/parameter-loading/main.rs @@ -17,12 +17,16 @@ use crate::parameters_loader::Parameters; use serde::{Deserialize, Serialize}; #[derive(Debug, Hash, Eq, PartialEq, Clone, Copy, Serialize, Deserialize)] -pub enum InfectionStatus { +pub enum InfectionStatusValue { S, I, R, } -define_person_property_with_default!(InfectionStatusType, InfectionStatus, InfectionStatus::S); +define_person_property_with_default!( + InfectionStatus, + InfectionStatusValue, + InfectionStatusValue::S +); fn initialize() -> Result { let mut context = Context::new(); diff --git a/examples/parameter-loading/transmission_manager.rs b/examples/parameter-loading/transmission_manager.rs index 3be015e3..7fc4adaa 100644 --- a/examples/parameter-loading/transmission_manager.rs +++ b/examples/parameter-loading/transmission_manager.rs @@ -5,7 +5,7 @@ use ixa::people::ContextPeopleExt; use ixa::random::ContextRandomExt; use crate::InfectionStatus; -use crate::InfectionStatusType; +use crate::InfectionStatusValue; use crate::Parameters; use rand_distr::Exp; @@ -14,15 +14,15 @@ define_rng!(TransmissionRng); fn attempt_infection(context: &mut Context) { let population_size: usize = context.get_current_population(); let person_to_infect = context.sample_person(TransmissionRng).unwrap(); - let person_status: InfectionStatus = - context.get_person_property(person_to_infect, InfectionStatusType); + let person_status: InfectionStatusValue = + context.get_person_property(person_to_infect, InfectionStatus); let parameters = context .get_global_property_value(Parameters) .unwrap() .clone(); - if matches!(person_status, InfectionStatus::S) { - context.set_person_property(person_to_infect, InfectionStatusType, InfectionStatus::I); + if matches!(person_status, InfectionStatusValue::S) { + context.set_person_property(person_to_infect, InfectionStatus, InfectionStatusValue::I); } // With a food-borne illness (i.e., constant force of infection), @@ -75,8 +75,8 @@ mod test { context.init_random(123); let pid = context.add_person(()).unwrap(); attempt_infection(&mut context); - let person_status = context.get_person_property(pid, InfectionStatusType); - assert_eq!(person_status, InfectionStatus::I); + let person_status = context.get_person_property(pid, InfectionStatus); + assert_eq!(person_status, InfectionStatusValue::I); context.execute(); } } diff --git a/examples/time-varying-infection/README.md b/examples/time-varying-infection/README.md index 3876d0b5..e5e4e420 100644 --- a/examples/time-varying-infection/README.md +++ b/examples/time-varying-infection/README.md @@ -151,13 +151,13 @@ use roots::find_root_brent; use reikna::integral::integrate; define_rng!(InfectionRng); -pub enum DiseaseStatus { +pub enum DiseaseStatusValue { S, I, R } -define_person_property_with_default!(DiseaseStatusType, - DiseaseStatus, - DiseaseStatus::S); +define_person_property_with_default!(DiseaseStatus, + DiseaseStatusValue, + DiseaseStatusValue::S); define_person_property_with_default!(InfectionTime, Option, None); @@ -196,7 +196,7 @@ fn inverse_sampling_infection(context: &mut Context, person_id: PersonID) { let t = find_root_brent(0f64, 100f64, // lower and upper bounds for the root finding f_int_shifted).unwrap(); context.add_plan(t, move |context| { - context.set_person_property(person_id, DiseaseStatus, DiseaseStatusType::I); + context.set_person_property(person_id, DiseaseStatus, DiseaseStatusValue::I); // for reasons that will become apparent with the recovery rate example, // we also need to record the time at which a person becomes infected context.set_person_property(person_id, InfectionTime, t); @@ -322,15 +322,15 @@ define_rng!(RecoveryRng); fn init(context: &mut Context) { context.subscribe_to_event(move |context, - event: PersonPropertyChangeEvent| { + event: PersonPropertyChangeEvent| { handle_infection_status_change(context, event); }); } fn handle_infection_status_change(context: &mut Context, - event: PersonPropertyChangeEvent) { + event: PersonPropertyChangeEvent) { let parameters = context.get_global_property_value(Parameters).clone(); - if matches!(event.current, DiseaseStatus::I) { + if matches!(event.current, DiseaseStatusValue::I) { evaluate_recovery(context, event.person_id, parameters.foi * 2.0 + 1.0 / parameters.infection_distribution); } } @@ -345,7 +345,7 @@ fn n_effective_infected(context: &mut Context) -> f64 { let mut n_infected = 0; for usize_id in 0..context.get_current_population() { if matches!(context.get_person_property(context.get_person_id(usize_id), - DiseaseStatusType), DiseaseStatus::I) { + DiseaseStatus), DiseaseStatusValue::I) { n_infected += 1; } } @@ -360,7 +360,7 @@ fn evaluate_recovery(context: &mut Context, person_id: PersonId, resampling_rate let recovery_probability = recovery_cdf(context, time_spent_infected); if context.sample_bool(RecoveryRng, recovery_probability) { // recovery has happened by now - context.set_person_property(person_id, DiseaseStatusType, DiseaseStatus::R); + context.set_person_property(person_id, DiseaseStatus, DiseaseStatusValue::R); } else { // add plan for recovery evaluation to happen again at fastest rate context.add_plan(context.get_current_time() + context.sample_distr(ExposureRng, diff --git a/examples/time-varying-infection/exposure_manager.rs b/examples/time-varying-infection/exposure_manager.rs index 585880d9..b5ce8e9f 100644 --- a/examples/time-varying-infection/exposure_manager.rs +++ b/examples/time-varying-infection/exposure_manager.rs @@ -6,7 +6,7 @@ use ordered_float::OrderedFloat; use std::rc::Rc; use crate::parameters_loader::Parameters; -use crate::population_loader::{DiseaseStatus, DiseaseStatusType, InfectionTime}; +use crate::population_loader::{DiseaseStatus, DiseaseStatusValue, InfectionTime}; use rand_distr::Exp1; use reikna::func; @@ -23,7 +23,7 @@ fn expose_person_to_deviled_eggs(context: &mut Context, person_created_event: Pe let t = inverse_sampling_infection(context); let person_id = person_created_event.person_id; context.add_plan(t, move |context| { - context.set_person_property(person_id, DiseaseStatusType, DiseaseStatus::I); + context.set_person_property(person_id, DiseaseStatus, DiseaseStatusValue::I); // for reasons that will become apparent with the recovery rate example, // we also need to record the time at which a person becomes infected context.set_person_property(person_id, InfectionTime, Some(OrderedFloat(t))); @@ -71,7 +71,7 @@ pub fn init(context: &mut Context) { mod test { use super::*; - use crate::population_loader::{DiseaseStatus, DiseaseStatusType}; + use crate::population_loader::{DiseaseStatus, DiseaseStatusValue}; use ixa::context::Context; use ixa::global_properties::ContextGlobalPropertiesExt; use ixa::people::ContextPeopleExt; @@ -105,8 +105,8 @@ mod test { init(&mut context); let person = context.add_person(()).unwrap(); context.execute(); - let person_status = context.get_person_property(person, DiseaseStatusType); - assert_eq!(person_status, DiseaseStatus::I); + let person_status = context.get_person_property(person, DiseaseStatus); + assert_eq!(person_status, DiseaseStatusValue::I); let infection_time = context.get_person_property(person, InfectionTime).unwrap(); assert_eq!(infection_time, context.get_current_time()); } diff --git a/examples/time-varying-infection/incidence_report.rs b/examples/time-varying-infection/incidence_report.rs index b350ccea..fcd89459 100644 --- a/examples/time-varying-infection/incidence_report.rs +++ b/examples/time-varying-infection/incidence_report.rs @@ -9,20 +9,20 @@ use std::path::PathBuf; use serde::{Deserialize, Serialize}; use crate::parameters_loader::Parameters; -use crate::population_loader::{DiseaseStatus, DiseaseStatusType}; +use crate::population_loader::{DiseaseStatus, DiseaseStatusValue}; #[derive(Serialize, Deserialize, Clone)] struct IncidenceReportItem { time: f64, person_id: String, - infection_status: DiseaseStatus, + infection_status: DiseaseStatusValue, } create_report_trait!(IncidenceReportItem); fn handle_infection_status_change( context: &mut Context, - event: PersonPropertyChangeEvent, + event: PersonPropertyChangeEvent, ) { context.send_report(IncidenceReportItem { time: context.get_current_time(), @@ -40,10 +40,8 @@ pub fn init(context: &mut Context) -> Result<(), IxaError> { .report_options() .directory(PathBuf::from(parameters.output_dir)); context.add_report::(¶meters.output_file)?; - context.subscribe_to_event( - |context, event: PersonPropertyChangeEvent| { - handle_infection_status_change(context, event); - }, - ); + context.subscribe_to_event(|context, event: PersonPropertyChangeEvent| { + handle_infection_status_change(context, event); + }); Ok(()) } diff --git a/examples/time-varying-infection/infection_manager.rs b/examples/time-varying-infection/infection_manager.rs index aa18c109..65882bfb 100644 --- a/examples/time-varying-infection/infection_manager.rs +++ b/examples/time-varying-infection/infection_manager.rs @@ -7,7 +7,7 @@ use ixa::random::ContextRandomExt; use rand_distr::Exp; use crate::parameters_loader::Parameters; -use crate::population_loader::{DiseaseStatus, DiseaseStatusType, InfectionTime}; +use crate::population_loader::{DiseaseStatus, DiseaseStatusValue, InfectionTime}; define_rng!(InfectionRng); @@ -22,7 +22,7 @@ fn n_eff_inv_infec(context: &mut Context) -> f64 { .unwrap() .clone(); // get number of infected people - let n_infected = context.query_people_count((DiseaseStatusType, DiseaseStatus::I)); + let n_infected = context.query_people_count((DiseaseStatus, DiseaseStatusValue::I)); (1.0 / parameters.infection_duration) / (n_infected as f64) } @@ -40,7 +40,7 @@ fn evaluate_recovery( let recovery_probability = recovery_cdf(context, time_spent_infected); if context.sample_bool(InfectionRng, recovery_probability) { // recovery has happened by now - context.set_person_property(person_id, DiseaseStatusType, DiseaseStatus::R); + context.set_person_property(person_id, DiseaseStatus, DiseaseStatusValue::R); Some(context.get_current_time()) } else { // add plan for recovery evaluation to happen again at fastest rate @@ -57,13 +57,13 @@ fn evaluate_recovery( fn handle_infection_status_change( context: &mut Context, - event: PersonPropertyChangeEvent, + event: PersonPropertyChangeEvent, ) { let parameters = context .get_global_property_value(Parameters) .unwrap() .clone(); - if matches!(event.current, DiseaseStatus::I) { + if matches!(event.current, DiseaseStatusValue::I) { // recall resampling rate is sum of maximum foi rate and gamma // maximum foi rate is foi * 2 -- the 2 because foi is sin(t + c) + 1 evaluate_recovery( @@ -76,7 +76,7 @@ fn handle_infection_status_change( pub fn init(context: &mut Context) { context.subscribe_to_event( - move |context, event: PersonPropertyChangeEvent| { + move |context, event: PersonPropertyChangeEvent| { handle_infection_status_change(context, event); }, ); @@ -91,11 +91,11 @@ mod test { use ordered_float::OrderedFloat; use crate::parameters_loader::ParametersValues; - use crate::population_loader::{DiseaseStatus, DiseaseStatusType}; + use crate::population_loader::{DiseaseStatus, DiseaseStatusValue}; - fn handle_recovery_event(event: PersonPropertyChangeEvent) { - assert_eq!(event.current, DiseaseStatus::R); - assert_eq!(event.previous, DiseaseStatus::I); + fn handle_recovery_event(event: PersonPropertyChangeEvent) { + assert_eq!(event.current, DiseaseStatusValue::R); + assert_eq!(event.previous, DiseaseStatusValue::I); } #[test] @@ -127,14 +127,14 @@ mod test { let person_id = context .add_person((InfectionTime, Some(OrderedFloat(0.0)))) .unwrap(); - context.set_person_property(person_id, DiseaseStatusType, DiseaseStatus::I); + context.set_person_property(person_id, DiseaseStatus, DiseaseStatusValue::I); } // put this subscription after every agent has become infected // so that handle_recovery_event is not triggered by an S --> I transition // but only I --> R transitions, which is what it checks for context.subscribe_to_event( - move |_context, event: PersonPropertyChangeEvent| { + move |_context, event: PersonPropertyChangeEvent| { handle_recovery_event(event); }, ); @@ -165,7 +165,7 @@ mod test { for _ in 0..parameters.population { let person_id = context.add_person(()).unwrap(); people.push(person_id); - context.set_person_property(person_id, DiseaseStatusType, DiseaseStatus::I); + context.set_person_property(person_id, DiseaseStatus, DiseaseStatusValue::I); } assert_eq!( n_eff_inv_infec(&mut context), @@ -175,7 +175,7 @@ mod test { let cdf_value_many_infected = recovery_cdf(&mut context, time_spent_infected); // now make it so that all but 1 person becomes recovered for i in 1..parameters.population { - context.set_person_property(people[i], DiseaseStatusType, DiseaseStatus::R); + context.set_person_property(people[i], DiseaseStatus, DiseaseStatusValue::R); } assert_eq!( n_eff_inv_infec(&mut context), @@ -215,7 +215,7 @@ mod test { let person_id = context .add_person((InfectionTime, Some(OrderedFloat(0.0)))) .unwrap(); - context.set_person_property(person_id, DiseaseStatusType, DiseaseStatus::I); + context.set_person_property(person_id, DiseaseStatus, DiseaseStatusValue::I); // there should only be one infected person in the simulation assert_eq!( n_eff_inv_infec(&mut context), diff --git a/examples/time-varying-infection/main.rs b/examples/time-varying-infection/main.rs index 8445905d..69982e40 100644 --- a/examples/time-varying-infection/main.rs +++ b/examples/time-varying-infection/main.rs @@ -4,7 +4,7 @@ use ixa::error::IxaError; use ixa::random::ContextRandomExt; use ixa::report::ContextReportExt; use ixa::{context::Context, global_properties::ContextGlobalPropertiesExt}; -use population_loader::DiseaseStatusType; +use population_loader::DiseaseStatus; mod exposure_manager; mod incidence_report; @@ -33,7 +33,7 @@ fn initialize() -> Result { infection_manager::init(&mut context); incidence_report::init(&mut context)?; // add periodic report - context.add_periodic_report("person_property_count", 1.0, (DiseaseStatusType,))?; + context.add_periodic_report("person_property_count", 1.0, (DiseaseStatus,))?; context.add_plan(parameters.max_time, |context| { context.shutdown(); diff --git a/examples/time-varying-infection/plot_output.R b/examples/time-varying-infection/plot_output.R index 51cdfb83..b024decb 100644 --- a/examples/time-varying-infection/plot_output.R +++ b/examples/time-varying-infection/plot_output.R @@ -63,7 +63,7 @@ person_property_report <- readr::read_csv(file.path( )) ggplot2::ggplot() + - geom_point(aes(t, count, color = DiseaseStatusType), person_property_report) + + geom_point(aes(t, count, color = DiseaseStatus), person_property_report) + geom_line(aes(time_array_susc, expected_susc), color = "black") + xlab("Time") + ylab("People") + diff --git a/examples/time-varying-infection/population_loader.rs b/examples/time-varying-infection/population_loader.rs index 34f40759..7fad6a70 100644 --- a/examples/time-varying-infection/population_loader.rs +++ b/examples/time-varying-infection/population_loader.rs @@ -8,13 +8,13 @@ use serde::{Deserialize, Serialize}; use crate::parameters_loader::Parameters; #[derive(Deserialize, Serialize, Copy, Clone, PartialEq, Eq, Debug, Hash)] -pub enum DiseaseStatus { +pub enum DiseaseStatusValue { S, I, R, } -define_person_property_with_default!(DiseaseStatusType, DiseaseStatus, DiseaseStatus::S); +define_person_property_with_default!(DiseaseStatus, DiseaseStatusValue, DiseaseStatusValue::S); define_person_property_with_default!(InfectionTime, Option>, None); pub fn init(context: &mut Context) { diff --git a/src/people.rs b/src/people.rs index 08cd4f7c..3383921b 100644 --- a/src/people.rs +++ b/src/people.rs @@ -1370,25 +1370,25 @@ mod test { define_person_property!(Age, u8); #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] - pub enum AgeGroupType { + pub enum AgeGroupValue { Child, Adult, } - define_derived_property!(AgeGroup, AgeGroupType, [Age], |age| { + define_derived_property!(AgeGroup, AgeGroupValue, [Age], |age| { if age < 18 { - AgeGroupType::Child + AgeGroupValue::Child } else { - AgeGroupType::Adult + AgeGroupValue::Adult } }); #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] - pub enum RiskCategory { + pub enum RiskCategoryValue { High, Low, } - define_person_property!(RiskCategoryType, RiskCategory); + define_person_property!(RiskCategory, RiskCategoryValue); define_person_property_with_default!(IsRunner, bool, false); define_person_property!(RunningShoes, u8, |context: &Context, person: PersonId| { let is_runner = context.get_person_property(person, IsRunner); @@ -1465,12 +1465,12 @@ mod test { let mut context = Context::new(); let person_id = context - .add_person(((Age, 42), (RiskCategoryType, RiskCategory::Low))) + .add_person(((Age, 42), (RiskCategory, RiskCategoryValue::Low))) .unwrap(); assert_eq!(context.get_person_property(person_id, Age), 42); assert_eq!( - context.get_person_property(person_id, RiskCategoryType), - RiskCategory::Low + context.get_person_property(person_id, RiskCategory), + RiskCategoryValue::Low ); } @@ -1479,12 +1479,12 @@ mod test { let mut context = Context::new(); let person_id = context - .add_person(((Age, 42), (RiskCategoryType, RiskCategory::Low))) + .add_person(((Age, 42), (RiskCategory, RiskCategoryValue::Low))) .unwrap(); assert_eq!(context.get_person_property(person_id, Age), 42); assert_eq!( - context.get_person_property(person_id, RiskCategoryType), - RiskCategory::Low + context.get_person_property(person_id, RiskCategory), + RiskCategoryValue::Low ); } @@ -1555,25 +1555,25 @@ mod test { let flag = Rc::new(RefCell::new(false)); let flag_clone = flag.clone(); context.subscribe_to_event( - move |_context, event: PersonPropertyChangeEvent| { + move |_context, event: PersonPropertyChangeEvent| { *flag_clone.borrow_mut() = true; assert_eq!(event.person_id.id, 0, "Person id is correct"); assert_eq!( event.previous, - RiskCategory::Low, + RiskCategoryValue::Low, "Previous value is correct" ); assert_eq!( event.current, - RiskCategory::High, + RiskCategoryValue::High, "Current value is correct" ); }, ); let person_id = context - .add_person((RiskCategoryType, RiskCategory::Low)) + .add_person((RiskCategory, RiskCategoryValue::Low)) .unwrap(); - context.set_person_property(person_id, RiskCategoryType, RiskCategory::High); + context.set_person_property(person_id, RiskCategory, RiskCategoryValue::High); context.execute(); assert!(*flag.borrow()); } @@ -1600,7 +1600,7 @@ mod test { fn initialize_without_initializer_succeeds() { let mut context = Context::new(); context - .add_person((RiskCategoryType, RiskCategory::High)) + .add_person((RiskCategory, RiskCategoryValue::High)) .unwrap(); } @@ -1609,7 +1609,7 @@ mod test { fn set_without_initializer_panics() { let mut context = Context::new(); let person_id = context.add_person(()).unwrap(); - context.set_person_property(person_id, RiskCategoryType, RiskCategory::High); + context.set_person_property(person_id, RiskCategory, RiskCategoryValue::High); } #[test] @@ -1617,7 +1617,7 @@ mod test { fn get_without_initializer_panics() { let mut context = Context::new(); let person_id = context.add_person(()).unwrap(); - context.get_person_property(person_id, RiskCategoryType); + context.get_person_property(person_id, RiskCategory); } #[test] @@ -1626,7 +1626,7 @@ mod test { let person = context.add_person((Age, 10)).unwrap(); assert_eq!( context.get_person_property(person, AgeGroup), - AgeGroupType::Child + AgeGroupValue::Child ); } @@ -1636,12 +1636,12 @@ mod test { let person = context.add_person((Age, 17)).unwrap(); assert_eq!( context.get_person_property(person, AgeGroup), - AgeGroupType::Child + AgeGroupValue::Child ); context.set_person_property(person, Age, 18); assert_eq!( context.get_person_property(person, AgeGroup), - AgeGroupType::Adult + AgeGroupValue::Adult ); } #[test] @@ -1655,8 +1655,8 @@ mod test { context.subscribe_to_event( move |_context, event: PersonPropertyChangeEvent| { assert_eq!(event.person_id.id, 0); - assert_eq!(event.previous, AgeGroupType::Child); - assert_eq!(event.current, AgeGroupType::Adult); + assert_eq!(event.previous, AgeGroupValue::Child); + assert_eq!(event.current, AgeGroupValue::Adult); *flag_clone.borrow_mut() = true; }, ); @@ -1767,10 +1767,10 @@ mod test { fn query_people() { let mut context = Context::new(); let _ = context - .add_person((RiskCategoryType, RiskCategory::High)) + .add_person((RiskCategory, RiskCategoryValue::High)) .unwrap(); - let people = context.query_people((RiskCategoryType, RiskCategory::High)); + let people = context.query_people((RiskCategory, RiskCategoryValue::High)); assert_eq!(people.len(), 1); } @@ -1778,7 +1778,7 @@ mod test { fn query_people_empty() { let context = Context::new(); - let people = context.query_people((RiskCategoryType, RiskCategory::High)); + let people = context.query_people((RiskCategory, RiskCategoryValue::High)); assert_eq!(people.len(), 0); } @@ -1786,11 +1786,11 @@ mod test { fn query_people_count() { let mut context = Context::new(); let _ = context - .add_person((RiskCategoryType, RiskCategory::High)) + .add_person((RiskCategory, RiskCategoryValue::High)) .unwrap(); assert_eq!( - context.query_people_count((RiskCategoryType, RiskCategory::High)), + context.query_people_count((RiskCategory, RiskCategoryValue::High)), 1 ); } @@ -1800,7 +1800,7 @@ mod test { let context = Context::new(); assert_eq!( - context.query_people_count((RiskCategoryType, RiskCategory::High)), + context.query_people_count((RiskCategory, RiskCategoryValue::High)), 0 ); } @@ -1809,11 +1809,11 @@ mod test { fn query_people_macro_index_first() { let mut context = Context::new(); let _ = context - .add_person((RiskCategoryType, RiskCategory::High)) + .add_person((RiskCategory, RiskCategoryValue::High)) .unwrap(); - context.index_property(RiskCategoryType); - assert!(property_is_indexed::(&context)); - let people = context.query_people((RiskCategoryType, RiskCategory::High)); + context.index_property(RiskCategory); + assert!(property_is_indexed::(&context)); + let people = context.query_people((RiskCategory, RiskCategoryValue::High)); assert_eq!(people.len(), 1); } @@ -1830,13 +1830,13 @@ mod test { #[test] fn query_people_macro_index_second() { let mut context = Context::new(); - let _ = context.add_person((RiskCategoryType, RiskCategory::High)); - let people = context.query_people((RiskCategoryType, RiskCategory::High)); - assert!(!property_is_indexed::(&context)); + let _ = context.add_person((RiskCategory, RiskCategoryValue::High)); + let people = context.query_people((RiskCategory, RiskCategoryValue::High)); + assert!(!property_is_indexed::(&context)); assert_eq!(people.len(), 1); - context.index_property(RiskCategoryType); - assert!(property_is_indexed::(&context)); - let people = context.query_people((RiskCategoryType, RiskCategory::High)); + context.index_property(RiskCategory); + assert!(property_is_indexed::(&context)); + let people = context.query_people((RiskCategory, RiskCategoryValue::High)); assert_eq!(people.len(), 1); } @@ -1844,18 +1844,18 @@ mod test { fn query_people_macro_change() { let mut context = Context::new(); let person1 = context - .add_person((RiskCategoryType, RiskCategory::High)) + .add_person((RiskCategory, RiskCategoryValue::High)) .unwrap(); - let people = context.query_people((RiskCategoryType, RiskCategory::High)); + let people = context.query_people((RiskCategory, RiskCategoryValue::High)); assert_eq!(people.len(), 1); - let people = context.query_people((RiskCategoryType, RiskCategory::Low)); + let people = context.query_people((RiskCategory, RiskCategoryValue::Low)); assert_eq!(people.len(), 0); - context.set_person_property(person1, RiskCategoryType, RiskCategory::Low); - let people = context.query_people((RiskCategoryType, RiskCategory::High)); + context.set_person_property(person1, RiskCategory, RiskCategoryValue::Low); + let people = context.query_people((RiskCategory, RiskCategoryValue::High)); assert_eq!(people.len(), 0); - let people = context.query_people((RiskCategoryType, RiskCategory::Low)); + let people = context.query_people((RiskCategory, RiskCategoryValue::Low)); assert_eq!(people.len(), 1); } @@ -1863,11 +1863,11 @@ mod test { fn query_people_index_after_add() { let mut context = Context::new(); let _ = context - .add_person((RiskCategoryType, RiskCategory::High)) + .add_person((RiskCategory, RiskCategoryValue::High)) .unwrap(); - context.index_property(RiskCategoryType); - assert!(property_is_indexed::(&context)); - let people = context.query_people((RiskCategoryType, RiskCategory::High)); + context.index_property(RiskCategory); + assert!(property_is_indexed::(&context)); + let people = context.query_people((RiskCategory, RiskCategoryValue::High)); assert_eq!(people.len(), 1); } @@ -1875,17 +1875,17 @@ mod test { fn query_people_add_after_index() { let mut context = Context::new(); let _ = context - .add_person((RiskCategoryType, RiskCategory::High)) + .add_person((RiskCategory, RiskCategoryValue::High)) .unwrap(); - context.index_property(RiskCategoryType); - assert!(property_is_indexed::(&context)); - let people = context.query_people((RiskCategoryType, RiskCategory::High)); + context.index_property(RiskCategory); + assert!(property_is_indexed::(&context)); + let people = context.query_people((RiskCategory, RiskCategoryValue::High)); assert_eq!(people.len(), 1); let _ = context - .add_person((RiskCategoryType, RiskCategory::High)) + .add_person((RiskCategory, RiskCategoryValue::High)) .unwrap(); - let people = context.query_people((RiskCategoryType, RiskCategory::High)); + let people = context.query_people((RiskCategory, RiskCategoryValue::High)); assert_eq!(people.len(), 2); } @@ -1894,7 +1894,7 @@ mod test { fn query_people_add_after_index_without_query() { let mut context = Context::new(); let _ = context.add_person(()).unwrap(); - context.index_property(RiskCategoryType); + context.index_property(RiskCategory); } #[test] @@ -1903,8 +1903,8 @@ mod test { fn query_people_add_after_index_panic() { let mut context = Context::new(); context.add_person(()).unwrap(); - context.index_property(RiskCategoryType); - context.query_people((RiskCategoryType, RiskCategory::High)); + context.index_property(RiskCategory); + context.query_people((RiskCategory, RiskCategoryValue::High)); } #[test] @@ -1921,16 +1921,16 @@ mod test { fn query_people_intersection() { let mut context = Context::new(); let _ = context - .add_person(((Age, 42), (RiskCategoryType, RiskCategory::High))) + .add_person(((Age, 42), (RiskCategory, RiskCategoryValue::High))) .unwrap(); let _ = context - .add_person(((Age, 42), (RiskCategoryType, RiskCategory::Low))) + .add_person(((Age, 42), (RiskCategory, RiskCategoryValue::Low))) .unwrap(); let _ = context - .add_person(((Age, 40), (RiskCategoryType, RiskCategory::Low))) + .add_person(((Age, 40), (RiskCategory, RiskCategoryValue::Low))) .unwrap(); - let people = context.query_people(((Age, 42), (RiskCategoryType, RiskCategory::High))); + let people = context.query_people(((Age, 42), (RiskCategory, RiskCategoryValue::High))); assert_eq!(people.len(), 1); } @@ -1938,16 +1938,16 @@ mod test { fn query_people_intersection_non_macro() { let mut context = Context::new(); let _ = context - .add_person(((Age, 42), (RiskCategoryType, RiskCategory::High))) + .add_person(((Age, 42), (RiskCategory, RiskCategoryValue::High))) .unwrap(); let _ = context - .add_person(((Age, 42), (RiskCategoryType, RiskCategory::Low))) + .add_person(((Age, 42), (RiskCategory, RiskCategoryValue::Low))) .unwrap(); let _ = context - .add_person(((Age, 40), (RiskCategoryType, RiskCategory::Low))) + .add_person(((Age, 40), (RiskCategory, RiskCategoryValue::Low))) .unwrap(); - let people = context.query_people(((Age, 42), (RiskCategoryType, RiskCategory::High))); + let people = context.query_people(((Age, 42), (RiskCategory, RiskCategoryValue::High))); assert_eq!(people.len(), 1); } @@ -1955,17 +1955,17 @@ mod test { fn query_people_intersection_one_indexed() { let mut context = Context::new(); let _ = context - .add_person(((Age, 42), (RiskCategoryType, RiskCategory::High))) + .add_person(((Age, 42), (RiskCategory, RiskCategoryValue::High))) .unwrap(); let _ = context - .add_person(((Age, 42), (RiskCategoryType, RiskCategory::Low))) + .add_person(((Age, 42), (RiskCategory, RiskCategoryValue::Low))) .unwrap(); let _ = context - .add_person(((Age, 40), (RiskCategoryType, RiskCategory::Low))) + .add_person(((Age, 40), (RiskCategory, RiskCategoryValue::Low))) .unwrap(); context.index_property(Age); - let people = context.query_people(((Age, 42), (RiskCategoryType, RiskCategory::High))); + let people = context.query_people(((Age, 42), (RiskCategory, RiskCategoryValue::High))); assert_eq!(people.len(), 1); } @@ -2020,11 +2020,11 @@ mod test { fn text_match_person() { let mut context = Context::new(); let person = context - .add_person(((Age, 42), (RiskCategoryType, RiskCategory::High))) + .add_person(((Age, 42), (RiskCategory, RiskCategoryValue::High))) .unwrap(); - assert!(context.match_person(person, ((Age, 42), (RiskCategoryType, RiskCategory::High)))); - assert!(!context.match_person(person, ((Age, 43), (RiskCategoryType, RiskCategory::High)))); - assert!(!context.match_person(person, ((Age, 42), (RiskCategoryType, RiskCategory::Low)))); + assert!(context.match_person(person, ((Age, 42), (RiskCategory, RiskCategoryValue::High)))); + assert!(!context.match_person(person, ((Age, 43), (RiskCategory, RiskCategoryValue::High)))); + assert!(!context.match_person(person, ((Age, 42), (RiskCategory, RiskCategoryValue::Low)))); } #[test] @@ -2057,12 +2057,12 @@ mod test { #[test] fn test_tabulator() { - let cols = (Age, RiskCategoryType); + let cols = (Age, RiskCategory); assert_eq!( cols.get_typelist(), - vec![TypeId::of::(), TypeId::of::()] + vec![TypeId::of::(), TypeId::of::()] ); - assert_eq!(cols.get_columns(), vec!["Age", "RiskCategoryType"]); + assert_eq!(cols.get_columns(), vec!["Age", "RiskCategory"]); } fn tabulate_properties_test_setup(