Example #1
0
def calculate_ppe(city: City) -> None:
    """
    Calculate personal protective equipment.

    Consumes one PPE per medical worker and protects them from infection.

    :param city: the City object
    :precondition: city is a valid instance of City
    """

    num_ppe = city.get_num_ppe()

    for citizen in city.get_citizens():
        if citizen.get_role() == 'medical':
            if num_ppe > 0:
                num_ppe -= 1
                citizen.update_prob_infected(0.0)
            elif citizen.get_prob_infected() == 0:
                citizen.update_prob_infected(round(uniform(0.05, 0.12), 2))
    city.set_num_ppe(num_ppe)