# list of countries, country has object containing, name, susceptible pop., infected pop., immune pop.
# simulate spread (travel btwn countries?)
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator

# 
class country():
    def __init__(self, country, suscept, infect, immune):
        self.name = country
        self.suscept = suscept
        self.infect = infect
        self.immune = immune

# 96k current cases, 80k recoveries, 7k deaths worldwide
# assume the dead are immune
infect = 96
recovd = 86
populn = 7800000
# per day multiplication of cases
factor = 1.169
# infection period in days
days = 22.4
# simulation length in days
length = 15

# initialize world
world = country("world", populn-infect-recovd, infect, recovd)

def spread(factor, country):
    if world.suscept == 0 or world.infect == 0: # none left to infect or eradicated
        return
    
    # number of new cases with logistic growth
    infected = (factor-1)*world.infect*(1-((world.infect+world.immune)/world.suscept))
    world.suscept -= infected # subtract new cases from suscept

    if world.suscept < 0: # prevent suscept from going negative
        world.infect += world.suscept
        world.suscept = 0
        return
    
    world.infect += infected # add new cases to infected

def recover(factor, country, days):
    if world.infect == 0: # if eradicated
        return
    
    # number of recoveries
    recovered = world.infect/(factor**days) # approximation of cases that were in progress days ago
    world.infect -= recovered # subtract recovered from infected

    if world.infect < 0: # prevent infect from going negative
        world.immune += world.infect
        world.infect = 0
        return

    world.immune += recovered # add recovered to immune

# aggregate infections list
aggrlist = [None] * (length)

# simulate over the length
for i in range(1, length+1):
    spread(factor, world)
    recover(factor, world, days)
    aggrlist[i-1] = world.infect+world.immune # add cumulative to list
    # print simulation results by day
    print("Day: {:d} Susceptible: {:.3f} Infected: {:.3f} Immune: {:.3f} Cumulative: {:.3f} ".format(i, world.suscept, world.infect, world.immune, world.infect+world.immune))

# plot simulation results
#plt.yticks(ticks=range(0,1000000,100000))
plt.grid(b=True)
plt.plot(range(1,length+1), aggrlist)
plt.savefig("aggr.png")

d5727245fc266b2f95e10abff229279fd366a2a7
<mask token>


class country:

    def __init__(self, country, suscept, infect, immune):
        self.name = country
        self.suscept = suscept
        self.infect = infect
        self.immune = immune


<mask token>


def spread(factor, country):
    if world.suscept == 0 or world.infect == 0:
        return
    infected = (factor - 1) * world.infect * (1 - (world.infect + world.
        immune) / world.suscept)
    world.suscept -= infected
    if world.suscept < 0:
        world.infect += world.suscept
        world.suscept = 0
        return
    world.infect += infected


def recover(factor, country, days):
    if world.infect == 0:
        return
    recovered = world.infect / factor ** days
    world.infect -= recovered
    if world.infect < 0:
        world.immune += world.infect
        world.infect = 0
        return
    world.immune += recovered


<mask token>

<mask token>


class country:

    def __init__(self, country, suscept, infect, immune):
        self.name = country
        self.suscept = suscept
        self.infect = infect
        self.immune = immune


<mask token>


def spread(factor, country):
    if world.suscept == 0 or world.infect == 0:
        return
    infected = (factor - 1) * world.infect * (1 - (world.infect + world.
        immune) / world.suscept)
    world.suscept -= infected
    if world.suscept < 0:
        world.infect += world.suscept
        world.suscept = 0
        return
    world.infect += infected


def recover(factor, country, days):
    if world.infect == 0:
        return
    recovered = world.infect / factor ** days
    world.infect -= recovered
    if world.infect < 0:
        world.immune += world.infect
        world.infect = 0
        return
    world.immune += recovered


<mask token>
for i in range(1, length + 1):
    spread(factor, world)
    recover(factor, world, days)
    aggrlist[i - 1] = world.infect + world.immune
    print(
        'Day: {:d} Susceptible: {:.3f} Infected: {:.3f} Immune: {:.3f} Cumulative: {:.3f} '
        .format(i, world.suscept, world.infect, world.immune, world.infect +
        world.immune))
plt.grid(b=True)
plt.plot(range(1, length + 1), aggrlist)
plt.savefig('aggr.png')

<mask token>


class country:

    def __init__(self, country, suscept, infect, immune):
        self.name = country
        self.suscept = suscept
        self.infect = infect
        self.immune = immune


infect = 96
recovd = 86
populn = 7800000
factor = 1.169
days = 22.4
length = 15
world = country('world', populn - infect - recovd, infect, recovd)


def spread(factor, country):
    if world.suscept == 0 or world.infect == 0:
        return
    infected = (factor - 1) * world.infect * (1 - (world.infect + world.
        immune) / world.suscept)
    world.suscept -= infected
    if world.suscept < 0:
        world.infect += world.suscept
        world.suscept = 0
        return
    world.infect += infected


def recover(factor, country, days):
    if world.infect == 0:
        return
    recovered = world.infect / factor ** days
    world.infect -= recovered
    if world.infect < 0:
        world.immune += world.infect
        world.infect = 0
        return
    world.immune += recovered


aggrlist = [None] * length
for i in range(1, length + 1):
    spread(factor, world)
    recover(factor, world, days)
    aggrlist[i - 1] = world.infect + world.immune
    print(
        'Day: {:d} Susceptible: {:.3f} Infected: {:.3f} Immune: {:.3f} Cumulative: {:.3f} '
        .format(i, world.suscept, world.infect, world.immune, world.infect +
        world.immune))
plt.grid(b=True)
plt.plot(range(1, length + 1), aggrlist)
plt.savefig('aggr.png')

import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator


class country:

    def __init__(self, country, suscept, infect, immune):
        self.name = country
        self.suscept = suscept
        self.infect = infect
        self.immune = immune


infect = 96
recovd = 86
populn = 7800000
factor = 1.169
days = 22.4
length = 15
world = country('world', populn - infect - recovd, infect, recovd)


def spread(factor, country):
    if world.suscept == 0 or world.infect == 0:
        return
    infected = (factor - 1) * world.infect * (1 - (world.infect + world.
        immune) / world.suscept)
    world.suscept -= infected
    if world.suscept < 0:
        world.infect += world.suscept
        world.suscept = 0
        return
    world.infect += infected


def recover(factor, country, days):
    if world.infect == 0:
        return
    recovered = world.infect / factor ** days
    world.infect -= recovered
    if world.infect < 0:
        world.immune += world.infect
        world.infect = 0
        return
    world.immune += recovered


aggrlist = [None] * length
for i in range(1, length + 1):
    spread(factor, world)
    recover(factor, world, days)
    aggrlist[i - 1] = world.infect + world.immune
    print(
        'Day: {:d} Susceptible: {:.3f} Infected: {:.3f} Immune: {:.3f} Cumulative: {:.3f} '
        .format(i, world.suscept, world.infect, world.immune, world.infect +
        world.immune))
plt.grid(b=True)
plt.plot(range(1, length + 1), aggrlist)
plt.savefig('aggr.png')

# list of countries, country has object containing, name, susceptible pop., infected pop., immune pop.
# simulate spread (travel btwn countries?)
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator

# 
class country():
    def __init__(self, country, suscept, infect, immune):
        self.name = country
        self.suscept = suscept
        self.infect = infect
        self.immune = immune

# 96k current cases, 80k recoveries, 7k deaths worldwide
# assume the dead are immune
infect = 96
recovd = 86
populn = 7800000
# per day multiplication of cases
factor = 1.169
# infection period in days
days = 22.4
# simulation length in days
length = 15

# initialize world
world = country("world", populn-infect-recovd, infect, recovd)

def spread(factor, country):
    if world.suscept == 0 or world.infect == 0: # none left to infect or eradicated
        return
    
    # number of new cases with logistic growth
    infected = (factor-1)*world.infect*(1-((world.infect+world.immune)/world.suscept))
    world.suscept -= infected # subtract new cases from suscept

    if world.suscept < 0: # prevent suscept from going negative
        world.infect += world.suscept
        world.suscept = 0
        return
    
    world.infect += infected # add new cases to infected

def recover(factor, country, days):
    if world.infect == 0: # if eradicated
        return
    
    # number of recoveries
    recovered = world.infect/(factor**days) # approximation of cases that were in progress days ago
    world.infect -= recovered # subtract recovered from infected

    if world.infect < 0: # prevent infect from going negative
        world.immune += world.infect
        world.infect = 0
        return

    world.immune += recovered # add recovered to immune

# aggregate infections list
aggrlist = [None] * (length)

# simulate over the length
for i in range(1, length+1):
    spread(factor, world)
    recover(factor, world, days)
    aggrlist[i-1] = world.infect+world.immune # add cumulative to list
    # print simulation results by day
    print("Day: {:d} Susceptible: {:.3f} Infected: {:.3f} Immune: {:.3f} Cumulative: {:.3f} ".format(i, world.suscept, world.infect, world.immune, world.infect+world.immune))

# plot simulation results
#plt.yticks(ticks=range(0,1000000,100000))
plt.grid(b=True)
plt.plot(range(1,length+1), aggrlist)
plt.savefig("aggr.png")
