def _create_virus(self, virus_number, row_number): virus = Virus(self) virus_width, virus_height = virus.rect.size virus.x = virus_width + 2 * virus_width * virus_number virus.rect.x = virus.x virus.rect.y = virus.rect.height + 2 * virus.rect.height * row_number self.virus.add(virus)
def __init__(self, population_size, vacc_percentage, virus_name, mortality_rate, basic_repro_num, initial_infected=10): #print("LOADED") self.population_size = population_size self.population = [] self.total_infected = 0 self.current_infected = 0 self.next_person_id = 0 self.vacc_percentage = vacc_percentage self.virus = Virus(virus_name, mortality_rate, basic_repro_num) file_name = "{}_simulation_pop_{}_vp_{}_infected_{}.txt".format( self.virus.virus_name, population_size, vacc_percentage, initial_infected) self.log = Logger(file_name) self.log.write_metadata(population_size, vacc_percentage, virus_name, mortality_rate, basic_repro_num) self._create_population(initial_infected) # TODO: Create a Logger object and bind it to self.logger. You should use this # logger object to log all events of any importance during the simulation. Don't forget # to call these logger methods in the corresponding parts of the simulation! # This attribute will be used to keep track of all the people that catch # the infection during a given time step. We'll store each newly infected # person's .ID attribute in here. At the end of each time step, we'll call # self._infect_newly_infected() and then reset .newly_infected back to an empty # list. self.newly_infected = []
def __init__(self, population_size, vacc_percentage, virus_name, mortality_rate, basic_repro_num, initial_infected=1): self.population_size = population_size self.vacc_percentage = vacc_percentage self.virus_name = virus_name self.mortality_rate = mortality_rate self.basic_repro_num = basic_repro_num self.initial_infected = initial_infected self.population = [] self.newly_infected = [] self.total_infected = 0 self.total_dead = 0 self.current_infected = 0 self.next_person_id = 0 self.virus = Virus(virus_name, mortality_rate, basic_repro_num) self.file_name = "{}_simulation_pop_{}_vp_{}_infected_{}.txt".format( virus_name, population_size, vacc_percentage, initial_infected) self.logger = Logger(self.file_name) self.logger.write_metadata(population_size, vacc_percentage, virus_name, mortality_rate, basic_repro_num) self._create_population(initial_infected)
def test_is_alive_and_is_vaccinated(): virus = Virus("HIV", 0.8, 0.3) person = Person(925, True, virus) assert person._id == 925 assert person.is_vaccinated == True assert person.infected == virus
def crear_virus(): # funcion para crear una lista de virus distancia = 100 height = 100 for x in range(6): virus = Virus(distancia, height, window_width, window_height) lista_virus.append(virus) distancia = distancia + height
def test_constructor(): virus = Virus("AIDS", 0.12, 0.56) env = Simulation(20, .6, virus, 3) assert env.population_size == 50 assert env.virus == virus assert env.initial_infected == 4
def _create_fleet(self): virus = Virus(self) virus_width, virus_height = virus.rect.size available_space_x = self.settings.screen_width - (2 * virus_width) number_virus_x = available_space_x // (2 * virus_width) ship_height = self.ship.rect.height available_space_y = (self.settings.screen_height - (3 * virus_height) - ship_height) number_rows = available_space_y // (2 * virus_height) for row_number in range(number_rows): for virus_number in range(number_virus_x): self._create_virus(virus_number, row_number)
def analyze_dir(self, _dir): """ Creates a Virus object containng all files in the specifiled directory and retrieves metadata from each file found. Args: _dir: The directory containing files to analyze. Returns: Virus object containing information retrieved from the data source. Raises: Exception if the provided directory is null or empty. """ if (_dir and len(_dir) > 0): self.logger.print_info(MSG_INFO_ANALYZING.format(_dir)) vx = Virus(_logger=self.logger) vx.add_dir(_dir) self.datasource.retrieve_metadata(vx) return vx else: raise NullOrEmptyArgumentException()
def analyze_file(self, _file): """ Creates a Virus object with metadata retrieved from the given data source of the analyzer. Args: _file: The file to analyze. Returns: Virus object containing information retrieved from the data source. Raises: Exception if the provided file is null or empty. """ if (_file and len(_file) > 0): self.logger.print_info(MSG_INFO_ANALYZING.format(_file)) #********************************************************** # Create a Virus object to manipulate the malware. #********************************************************** vx = Virus(_logger=self.logger) vx.add_file(_file) vx_dst_file = "" #****************************************************** # Retrieve the information about the file from the # given data source. #****************************************************** try: self.datasource.retrieve_metadata(vx) except: pass return vx else: raise NullOrEmptyArgumentException()
def test_create_population(): virus = Virus("AIDS", 0.12, 0.56) env = Simulation(20, .6, virus, 3) vaccination_count = 0 infection_count = 0 for person in env.population: assert person.is_alive == True if person.is_vaccinated: vaccination_count += 1 if person.infection is not None: infection_count += 1 assert vaccination_count == 5 assert infection_count == 2 assert len(env.population) == 10
elif random_person.is_alive is False: return elif random_person.is_vaccinated: return elif random_person.is_vaccinated is False: random_float = random.random() if random_float < infected_person.infection.reproduction_num: random_person.infection is True else: random_person.is_vaccinated is True if __name__ == "__main__": # Set up the initial simulations values virus_name = "Malaise" reproduction_num = 0.20 mortality_num = .99 initial_healthy = 10 initial_vaccinated = 5 initial_infected = 1 virus = Virus(virus_name, reproduction_num, mortality_num) simulation = Simulation(initial_vaccinated, initial_infected, initial_healthy, virus, "results.txt") # run the simulation simulation.run()
input &= 0x00ff #python's right-shift is signed, so make sure there's a leading 0 while (input % 2 == 1): input >>= 1 n += 1 return n if __name__ == "__main__": """ Basic test function for Agent-Virus interaction. Generates an Agent and a Virus, then gives daily updates on the course of the Agent's illness until it resolves. """ a = Agent() v = Virus() print("Generated agent with infirmity " + str(a.infirmity)) print("Generated virus with generator " + hex(v.generator)) print(v.string_summary()) print("Agent Status: " + a.status_string()) print(a.status_values()) print("Infecting agent with virus... \n") a.infect(v) n = 1 while not (a.healthy or a.dead): print("Day " + str(n) + " Status: " + a.status_string()) print(a.status_values()) a.progress_courses() n += 1
all 9*2^16 unique virus signatures with the same distribution they are generated from a random seed. Then, infects a few agents with each virus. Agent infirmity is random unless specified. Caution: this produces over 16 million viruses. Do not use large values for the inner loop. """ survivors = 0 deaths = 0 contagious_days = 0 asym_days = 0 for i in range(0x01000000): v = Virus(i) for j in range(4): a = Agent() a.infect(v) while not (a.healthy or a.dead): a.progress_courses() if a.shedding and not a.critical: contagious_days += 1 if a.shedding and not a.symptoms: asym_days += 1 if a.healthy: survivors += 1 else: deaths += 1 print("Death toll: " + str(deaths)) print("Survivors: " + str(survivors)) print("Fatality Rate: " + str((deaths / (deaths + survivors)) * 100) + "%") print("Average days spent contagious: " + str(contagious_days /
''' The simulation will contain people who will make up a population.''' def __init__(self, is_vaccinated, infection=None): ''' We start out with is_alive = True All other values will be set by the simulation through the parameters when it instantiates each Person object. ''' self.is_alive = True # boolean self.is_vaccinated = is_vaccinated # boolean self.infection = infection # virus object def did_survive_infection(self): ''' Generate a random number between 0.0 and 1.0 and compare to the virus's mortality_num. If the random number is smaller, person dies from the disease. Set the person's is alive attribute to False If Person survives, they become vaccinated and they have no infection (set the vaccinated attibute to True and the infection to None) Return True if they survived the infection and False if they did not. ''' random_float = random.uniform(0, 1) if random_float < self.infection.mortality_num: self.is_alive is False return False else: self.is_alive is True self.is_vaccinated is True self.infection is False return True if __name__ == '__main__': louie_virus = Virus("Aids", .5, .9) louie = Person(True, louie_virus) print(louie.did_survive_infection())
from Person import Person from Simulation import Simulation from Virus import Virus HIV = Virus("HIV", 0.50, 0.3) def test_virus_initializer(): assert HIV.name == "HIV" assert HIV.reproduction_num == 0.50 assert HIV.mortality_num == 0.3
from Virus import Virus virus_1 = Virus("COVID-19", "China", 850, 200, 15, 0) virus_2 = Virus("Ebola", "Africa", 450, 300, 10, 1) print(virus_1.is_curable()) virusInfo = { 1: 45674, 2: 95, 3: 234, 4: 8921, 5: 12, 6: 1, 7: 345, 8: 23, 9: 5354, 10: "COVID", } count = 0 virusList = ["Ebola", "Langusta", "COVID19", "Delust56", "Herpees", "HIV", "AIDS"] for row in virusList: count += 1 print(str(count) + ")" + " " + row) coronaList = [ ["elvis", "marvin", "izzy"], ["jose", "sofia", "liz"], ["lennise", "ismael"], ["joshua", "mila"]
def test_person(): v = Virus("HIV", 0.8, 0.3) p = Person(1, False, None) p.did_survive_infection()
def test_simulation_should_continue(): virus = Virus("AIDS", 0.12, 0.56) env = Simulation(20, .6, virus, 3) assert env.simulation_should_continue()
def test_infect_newly(): virus = Virus("AIDS", 0.12, 0.56) env = Simulation(20, .6, virus, 3) env.infect_newly_infected() assert env.initial_infected == 4