fromemod_apiimportschema_to_classass2cfromemod_api.interventionsimportutilsfromemodpy_hiv.interventions.utilsimportset_intervention_propertiesfromtypingimportListdef_validate_times_and_values(times,values):iflen(times)!=len(values):raiseValueError(f"Length of times array ({times}) doesn't match length of values array ({values}).")ifany(t<0fortintimes):raiseValueError(f"All time values ({times}) must be greater than 0")iftimes!=sorted(times):raiseValueError(f"Time values ({times}) must be in ascending order")ifany(v<0orv>1forvinvalues):raiseValueError(f"All values ({values}) must be between 0 and 1")
[docs]defnew_intervention(camp,efficacy_times=[0,365],efficacy_values=[0.5,0],intervention_name:str=None,disqualifying_properties:List[str]=None,new_property_value:str=None):""" Create a new PrEP (Pre-Exposure Prophylaxis) intervention. This function creates and configures a new PrEP intervention using the provided efficacy times and values. Args: camp (emod_api.campaign): The central campaign builder object. efficacy_times (list of float): A list of times at which the PrEP efficacy changes. Times must be > 0 and in ascending order. efficacy_values (list of float): A list of efficacy values corresponding to the times. Values must be between 0 and 1. intervention_name (str): The name of the intervention. disqualifying_properties (list of str): A list of IndividualProperty key:value pairs that cause an intervention to be aborted new_property_value (str): An optional IndividualProperty key:value pair that will be assigned when the intervention is distributed. Returns: A new PrEP intervention with the specified efficacy configuration, which can be passed to a scheduled or triggered campaign event function. Raises: ValueError: If the lengths of efficacy_times and efficacy_values do not match. ValueError: If any time value in efficacy_times is not greater than 0. ValueError: If the time values in efficacy_times are not in ascending order. ValueError: If any value in efficacy_values is not between 0 and 1. Example: .. code-block:: python camp.set_schema("path/to/schema.json") times = [1, 2, 3, 4, 5, 6, 7] values = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7] intervention = new_intervention(camp, times, values) """_validate_times_and_values(efficacy_times,efficacy_values)intervention=s2c.get_class_with_defaults("ControlledVaccine",camp.schema_path)waning=s2c.get_class_with_defaults("WaningEffectMapPiecewise",camp.schema_path)waning.Durability_Map.Times=efficacy_timeswaning.Durability_Map.Values=efficacy_valueswaning.Initial_Effect=waning.Durability_Map.Values[0]intervention.Waning_Config=waningset_intervention_properties(intervention,intervention_name=intervention_name,disqualifying_properties=disqualifying_properties,new_property_value=new_property_value)returnintervention
[docs]defnew_intervention_event(camp,efficacy_times=[0,365],efficacy_values=[0.5,0],start_day=1,coverage=1.0,node_ids=None,intervention_name:str=None,disqualifying_properties:List[str]=None,new_property_value:str=None):""" Create a new PrEP (Pre-Exposure Prophylaxis) intervention as complete (scheduled) event. This function creates and configures a new PrEP intervention using the provided efficacy times and values, and adds it to a scheduled event. You need to add it to the campaign. Args: camp (emod_api.campaign): The central campaign builder object. efficacy_times (list of float): A list of times at which the PrEP efficacy changes. Times must be > 0 and in ascending order. efficacy_values (list of float): A list of efficacy values corresponding to the times. Values must be between 0 and 1. start_day (int): When this campaign event should occur. coverage (float): Who should get this -- i.e., what percentage of the population. node_ids (list of integers): Where this campaign event should be distributed. Leave as default if 'everywhere'. intervention_name (str): The name of the intervention. disqualifying_properties (list of str): A list of IndividualProperty key:value pairs that cause an intervention to be aborted new_property_value (str): An optional IndividualProperty key:value pair that will be assigned when the intervention is distributed. Returns: A new PrEP intervention with the specified efficacy configuration, which can be passed to a scheduled or triggered campaign event function. Raises: ValueError: If the lengths of efficacy_times and efficacy_values do not match. ValueError: If any time value in efficacy_times is not greater than 0. ValueError: If the time values in efficacy_times are not in ascending order. ValueError: If any value in efficacy_values is not between 0 and 1. Example: .. code-block:: python camp.set_schema("path/to/schema.json") times = [1, 2, 3, 4, 5, 6, 7] values = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7] event = new_intervention_event(camp, times, values, start_day=730, coverage=0.33, node_ides[ 1, 4, 5 ]) """new_iv=new_intervention(camp,efficacy_times,efficacy_values,intervention_name=intervention_name,disqualifying_properties=disqualifying_properties,new_property_value=new_property_value)# Coordinatorcoordinator=s2c.get_class_with_defaults("StandardEventCoordinator",camp.schema_path)coordinator.Intervention_Config=new_ivcoordinator.Demographic_Coverage=coverage# Eventevent=s2c.get_class_with_defaults("CampaignEvent",camp.schema_path)event.Event_Coordinator_Config=coordinatorevent.Start_Day=float(start_day)event.Nodeset_Config=utils.do_nodes(camp.schema_path,node_ids)from.importutilsashiv_utilshiv_utils.declutter(event)returnevent