Created
March 16, 2016 09:10
-
-
Save minorsecond/1c1727b24c1c6a6c33e5 to your computer and use it in GitHub Desktop.
Function that is not running correctly
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def simulation(): | |
""" | |
Main simulation function. | |
:return: | |
""" | |
rowNum = 1 | |
day = 1 | |
number_humans = session.query(Humans).count() | |
number_vectors = session.query(Vectors).count() | |
clear_screen() | |
print("Currently running simulation. This will take a while. \nGrab some coffee and catch up on some reading.") | |
sleep(5) | |
try: | |
for d in range(days_to_run): # TODO: Finish this next. | |
exposures = 0 | |
#for h in range(number_humans): # Select each human by id | |
#row = session.query(Humans).filter_by(id=h) # TODO: handle situations where h doesn't match any ID | |
row = session.query(Humans).yield_per(1000) # This might be way more efficient than querying each id | |
for r in row: | |
i = 0 | |
if rowNum % 100 == 0: # Status indicator | |
clear_screen() | |
print("***Python Epidemiological Simulator***\n\n" | |
" Status: Simulation running \n" | |
" Current Day: {0} \n" | |
" Current Exposure Count: {1} \n" | |
" {2} of {3} Contacts Scanned".format(day, exposures, rowNum, | |
days_to_run*number_humans*contact_rate)) | |
while i < contact_rate: # Infect by contact rate per day | |
# Choose any random number except the one that identifies the person selected, 'h' | |
pid = random.randint(1, number_humans) | |
while pid == r.id: | |
input("Identical PID") | |
pid = random.randint(1, number_humans) | |
contact = session.query(Humans).filter_by(id=pid).first() | |
# If human_a is susceptible & human_b is infected, human_a becomes exposed | |
if contact.infected == 'True' and r.susceptible == 'True': | |
exposures += 1 | |
#print("*Exposure Count: {0}".format(exposures)) | |
row.update({"exposed": 'True'}, synchronize_session='fetch') | |
row.update({"susceptible": 'False'}, synchronize_session='fetch') | |
# If human_b is susceptible & human_a is infected, human_b becomes exposed | |
elif r.infected == 'True' and contact.susceptible == 'True': | |
exposures += 1 | |
#print("*Exposure Count: {0}".format(exposures)) | |
# contact.update({"exposed": 'True'}, synchronize_session='fetch') | |
# contact.update({"susceptible": 'False'}, synchronize_session='fetch') | |
contact.exposed = 'True' | |
contact.susceptible = 'False' | |
i += 1 | |
rowNum += 1 | |
session.commit() | |
day += 1 | |
# TODO: human within 'range' of mosquito - chance of infection | |
except KeyboardInterrupt: | |
clear_screen() | |
input("You interrupted me. Going back to main menu.") | |
main_menu() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment