Exemple #1
0
    def fn(self, cb):
        nodelist = {x: [] for x in self.irs_dates}

        irs_distr = zip(self.irs_dates, self.irs_fracs)
        with open(self.reffname) as fin:
            cov = json.loads(fin.read())
        for irscov in cov[self.channel]:
            if irscov['coverage'] > 0:
                for i, (irs_date, irs_frac) in enumerate(irs_distr):
                    c = irscov['coverage'] * irs_frac
                    if i < len(self.irs_fracs) - 1:
                        c /= np.prod([
                            1 - x * irscov['coverage']
                            for x in self.irs_fracs[i + 1:]
                        ])
                    nodeIDs = [
                        x for x in irscov['nodes'] if np.random.random() <= c
                    ]
                    nodelist[irs_date] += nodeIDs

        for i, (irs_date, irs_frac) in enumerate(irs_distr):
            if len(nodelist[irs_date]) > 0:
                add_node_IRS(cb,
                             irs_date,
                             initial_killing=self.initial_killing,
                             box_duration=self.box_duration,
                             nodeIDs=nodelist[irs_date])
    count_triggers=['HappyBirthday'],
    threshold_type=
    'COUNT',  #this is the default, we can also look at % per eligible population
    thresholds=[13, 254],
    triggered_events=['Party', 'PartyHarder'])

add_incidence_counter(cb,
                      start_day=50,
                      count_duration=30,
                      count_triggers=['HappyBirthday'],
                      thresholds=[1, 9],
                      triggered_events=['Party', 'PartyHarder'])

# adding an intervention node IRS intervention that starts listening for Action1 trigger and when/if it hears it,
# listening_duration of -1 indicates that this intervention will listen forever and perform the tasks whenever Action1 is sent out
add_node_IRS(cb, 30, trigger_condition_list=["Party"], listening_duration=-1)

# this intervention is distributed and starts listening on day 60, but distributes the IRS 1000 days after it is triggered
# please note if the listening duration was less than triggered day + campaign delay, the intervention would not run.
add_node_IRS(cb,
             60,
             triggered_campaign_delay=1000,
             trigger_condition_list=["PartyHarder"])

# listens for 15 days and, as the result, hears nothing and does nothing.
add_node_IRS(cb,
             60,
             trigger_condition_list=["PartyHarder"],
             listening_duration=15)

# run_sim_args is what the `dtk run` command will look for