Source code for emodpy_tbhiv.interventions.hsb

from emod_api import schema_to_class as s2c
import emod_api.interventions.common as common
import emod_api.interventions.utils as utils
from emodpy_tbhiv.interventions import purge_campaign_event

[docs]def HSB( camp, trigger_treatment_list, output_event, probability_per_step=1.0, start_day=1, duration=-1, property_restrictions_list=[], nodeIDs=[], event_name='HSB', prevent_duplicates=False, fixed_initial_delay=0 ): """ Create and return triggered campaign event that issues an SimpleHealthSeekingBehavior intervention. See :doc:`emod-tbhiv:parameter-campaign-individual-simplehealthseekingbehavior` Args: camp: The :py:obj:`emod_api:emod_api.campaign` module instance which serves as the campaign accumulator. trigger_treatment_list: List of 1 or more triggers (or events or signals) which are listened to and trigger the distribution of the intervention. There is no default. output_event: Signal to broadcast when 'health' is ultimately sought (string). probability_per_step: Probability of seeking per timestep, default to 1 which means near instantaneous. start_day: The timestep when this campaign event takes effect. Defaults to 1. duration: How long the campaign event remains in effect. Defaults to forever. property_restrictions_list: Optiional list of Individual Properties to limit the intervention to. nodeIDs: Optional list of node ids to target. Defaults to all. prevent_duplicates: If an individual were to get one of these when they already have one, the default behaviour is to proceed addiditively. Use this param to cause the new one to replace the old one. Same-ness is based on same event_name. fixed_initial_delay: Optional param that lets us add a fixed delay before the HSB. event_name: Undocumented. Returns: New campaign event that can be added to the campaign. """ schema_path = camp.schema_path intervention = s2c.get_class_with_defaults( "SimpleHealthSeekingBehavior", schema_path ) intervention.Event_Or_Config = 'Event' intervention.Actual_IndividualIntervention_Event = camp.get_send_trigger(output_event) intervention.Tendency = probability_per_step if prevent_duplicates: intervention.Enable_Intervention_Replacement = 1 intervention.Intervention_Name = event_name if fixed_initial_delay>0: from emod_api.interventions.common import DelayedIntervention as DI delay = DI( camp, Delay_Dict={ "Delay_Period_Constant": fixed_initial_delay }, Configs=[intervention] ) delay.Intervention_Name = event_name # delay needs to 'masquerade' as the intervention itself. intervention = delay event = common.TriggeredCampaignEvent( camp, start_day,event_name, trigger_treatment_list, [ intervention ], Node_Ids=nodeIDs, Duration=duration, Property_Restrictions=property_restrictions_list ) purge_campaign_event( event ) return event
[docs]def new_intervention_as_file( camp, filename="hsb_diag.json" ): camp.add( HSB( camp, trigger_treatment_list=[ "Births" ], output_event="Seeking" ) ) camp.save( filename ) return filename