def test_update_individual(self):
     test = self.namespace_under_test
     # self.debug = True
     self.create_generic_gene_gina()
     curr_expected_gene_age = self.gene['expected']['age']
     curr_expected_gina_age = self.gina['expected']['age']
     timestep_size = 1  # TODO: figure out how to set / configure this
     gene = self.gene['observed']
     gina = self.gina['observed']
     gina_became_possible_mother = test.is_possible_mother(gina)
     gina_ceased_potential_motherhood = False
     age_of_potential_motherhood = None
     age_of_ceased_motherhood_potential = None
     self.assertFalse(gina_became_possible_mother,
                      "gina should not be a possible mother at creation.")
     for x in range(14600):
         self.check_property_of_individual('age',
                                           curr_expected_gene_age,
                                           test.get_age(gene),
                                           individual_label="gene")
         self.check_property_of_individual('age',
                                           curr_expected_gina_age,
                                           test.get_age(gina),
                                           individual_label="gina")
         if not gina_became_possible_mother:
             gina_became_possible_mother = test.is_possible_mother(gina)
             if gina_became_possible_mother:
                 age_of_potential_motherhood = curr_expected_gina_age
         elif not test.is_possible_mother(
                 gina) and not gina_ceased_potential_motherhood:
             gina_ceased_potential_motherhood = True
             age_of_ceased_motherhood_potential = curr_expected_gina_age
         test.update(gene)
         test.update(gina)
         curr_expected_gina_age += timestep_size
         curr_expected_gene_age += timestep_size
     self.assertTrue(gina_became_possible_mother,
                     "gina should have become a possible mother.")
     if self.debug:
         print(
             f"gina became a possible mother at age {age_of_potential_motherhood}.\nm"
         )
     self.assertTrue(gina_ceased_potential_motherhood,
                     "gina should have ceased being a potential mother.")
     if self.debug:
         print(
             f"gina ceased potential motherhood at age {age_of_ceased_motherhood_potential}.\n"
         )
Esempio n. 2
0
def do_shedding_update(human_pop):
    # This is not optimal. Only optimize if it really helps
    global fertility
    if fertility is None:
        config = json.loads(open("nd.json").read())
        fertility = config["Enable_Birth"] and config["Enable_Vital_Dynamics"]
    stat_pop = 0
    for human in human_pop:
        hum_id = human["id"]
        mcw = gi.get_mcw(hum_id)
        #Can we make this conditional on
        if fertility:
            nd.update_node_stats(
                (mcw, 0, gi.is_possible_mother(hum_id),
                 0))  # mcw, infectiousness, is_poss_mom, is_infected
        """
        if gi.is_infected(hum_id):
            if gi.has_latent_infection(hum_id):
                print( "{0} has latent infection.".format( hum_id ) )
            else:
                print( "{0} has active infection (I guess).".format( hum_id ) )
        else:
            print( "{0} has no infection.".format( hum_id ) )
        """
        stat_pop += mcw
        if gi.is_infected(hum_id):
            gi.update1(hum_id)  # this should do shedding & vital-dynamics
    return stat_pop
Esempio n. 3
0
def do_shedding_update(human_pop):
    for human in human_pop:
        hum_id = human["id"]
        nd.update_node_stats(
            (1.0, 0, gi.is_possible_mother(hum_id),
             0))  # mcw, infectiousness, is_poss_mom, is_infected
        """
        if gi.is_infected(hum_id):
            if gi.has_latent_infection(hum_id):
                print( "{0} has latent infection.".format( hum_id ) )
            else:
                print( "{0} has active infection (I guess).".format( hum_id ) )
        else:
            print( "{0} has no infection.".format( hum_id ) )
        """
        gi.update1(hum_id)  # this should do shedding & vital-dynamics
Esempio n. 4
0
def do_vitaldynamics_update(human_pop,
                            graveyard,
                            contagion,
                            census_cb=None,
                            death_cb=None):
    num_infected = 0
    num_incubating = 0
    num_active = 0
    num_suscept = 0
    num_recover = 0
    num_people = 0
    num_deaths = 0
    new_graveyard = []

    for human in human_pop:
        hum_id = human["id"]
        if census_cb != None:
            census_cb(hum_id)

        gi.update2(
            hum_id
        )  # this should do exposure; possible optimization would be to skip this entirely if zero contagion

        mcw = gi.get_mcw(hum_id)
        if gi.is_dead(hum_id):
            # somebody died
            print("{0} is dead.".format(hum_id))
            new_graveyard.append(human)
            num_deaths += mcw  # can't use len(graveyard) coz mcw
            if death_cb != None:
                death_cb(hum_id)

        num_people += mcw
        global fertility
        if fertility:
            ipm = gi.is_possible_mother(hum_id)
            ip = gi.is_pregnant(hum_id)
            if hum_id == 0:
                pdb.set_trace()
            age = gi.get_age(hum_id)
            #print( "Calling cfp with {0}, {1}, {2}, and {3}.".format( str(ipm), str(ip), str(age), str(hum_id) ) )
            # TBD: Optimization? I happen to know that this is only necessary for females of a
            # certain age. But technically that knowledge is for nd.
            nd.consider_for_pregnancy((ipm, ip, hum_id, age, 1.0))

        #print( str( json.loads(gi.serialize( hum_id ))["individual"]["susceptibility"] ) )
        if gi.is_infected(hum_id):
            if is_incubating(hum_id):
                num_incubating += mcw
            else:
                num_infected += mcw  # TBD: use_mcw
        elif gi.get_immunity(hum_id) != 1.0:
            num_recover += mcw  # TBD: use mcw
        else:
            num_suscept += mcw  # TBD: use mcw
            #if gi.has_active_infection( hum_id ):
            #    num_active += 1
        # serialize seems to be broken when you had an intervention (or at least a SimpleVaccine)
        #serial_man = gi.serialize( hum_id )
        #if hum_id == 1:
        #print( json.dumps( json.loads( serial_man ), indent=4 ) )
        #print( "infectiousness: " + str( json.loads( serial_man )["individual"]["infectiousness"] ) )
    #print( "Updating fertility for this timestep." )
    for corpse in new_graveyard:
        if corpse in human_pop:
            human_pop.pop(human_pop.index(corpse))
        else:
            print("Exception trying to remove individual from python list: " +
                  str(ex))
    graveyard.extend(new_graveyard)
    nd.update_fertility()
    exposeds.append(num_incubating)
    prevalence.append(num_infected)
    active_prevalence.append(num_active)
    susceptible.append(num_suscept)
    recovered.append(num_recover)
    disdeaths.append(num_deaths)
Esempio n. 5
0
def do_vitaldynamics_update(human_pop,
                            graveyard,
                            census_cb=None,
                            death_cb=None):
    num_infected = 0
    num_incubating = 0
    num_active = 0
    num_suscept = 0
    num_recover = 0
    new_graveyard = []
    for human in human_pop:
        hum_id = human["id"]
        if census_cb != None:
            census_cb(hum_id)
        gi.update2(hum_id)  # this should do exposure

        if gi.is_dead(hum_id):
            # somebody died
            print("{0} is dead.".format(hum_id))
            new_graveyard.append(human)
            if death_cb != None:
                death_cb(hum_id)

        # TESTING THIS
        ipm = gi.is_possible_mother(hum_id)
        ip = gi.is_pregnant(hum_id)
        if hum_id == 0:
            pdb.set_trace()
        age = gi.get_age(hum_id)
        #print( "Calling cfp with {0}, {1}, {2}, and {3}.".format( str(ipm), str(ip), str(age), str(hum_id) ) )
        nd.consider_for_pregnancy((ipm, ip, hum_id, age, 1.0))

        #print( str( json.loads(gi.serialize( hum_id ))["individual"]["susceptibility"] ) )
        if gi.is_infected(hum_id):
            if is_incubating(hum_id):
                num_incubating += 1
            else:
                num_infected += 1  # TBD: use_mcw
        elif gi.get_immunity(hum_id) != 1.0:
            num_recover += 1  # TBD: use mcw
        else:
            num_suscept += 1  # TBD: use mcw
            #if gi.has_active_infection( hum_id ):
            #    num_active += 1
        # serialize seems to be broken when you had an intervention (or at least a SimpleVaccine)
        #serial_man = gi.serialize( hum_id )
        #if hum_id == 1:
        #print( json.dumps( json.loads( serial_man ), indent=4 ) )
        #print( "infectiousness: " + str( json.loads( serial_man )["individual"]["infectiousness"] ) )
    #print( "Updating fertility for this timestep." )
    for corpse in new_graveyard:
        if corpse in human_pop:
            human_pop.pop(human_pop.index(corpse))
        else:
            print("Exception trying to remove individual from python list: " +
                  str(ex))
    graveyard.extend(new_graveyard)
    nd.update_fertility()
    exposeds.append(num_incubating)
    prevalence.append(num_infected)
    active_prevalence.append(num_active)
    susceptible.append(num_suscept)
    recovered.append(num_recover)
    disdeaths.append(len(graveyard))