Skip to content

Passing a AnySetting to infect person #214

@erik-rosenstrom

Description

@erik-rosenstrom

Ideally, we would want something like this in infection_attempt and infect_person but it results in an context immutability/mutability error

pub fn infection_attempt(context: &mut Context, person_id: PersonId) -> Option<PersonId> {
    if let Some(setting) = context.sample_setting(person_id) {
        let next_contact = context.get_contact(person_id, setting, ()).unwrap()?;
        match context.get_person_property(next_contact, InfectionStatus) {
            InfectionStatusValue::Susceptible => {
                if context.sample_bool(
                    ForecastRng,
                    context.get_relative_total_transmission(next_contact),
                ) {
                    context.infect_person(
                        next_contact,
                        Some(person_id),
                        Some(setting),
                    );
                    Some(next_contact)
                } else {
                    None
                }
            }
            _ => None,
        }
    } else {
        None
    }
}

fn infect_person(
        &mut self,
        target_id: PersonId,
        source_id: Option<PersonId>,
        setting: Option<&dyn AnySettingId>
    ) {
        let infection_time = self.get_current_time();
        trace!("Person {target_id}: Infected at {infection_time}");
        self.set_person_property(
            target_id,
            InfectionData,
            InfectionDataValue::Infectious {
                infection_time,
                infected_by: source_id,
                infection_setting_type: setting
                    .and_then(|s| Some(s.get_category_id())),
                infection_setting_id: setting.and_then(|s| Some(s.id()))
            },
        );
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions