Beispiel #1
0
        print(
            "               plotCorona.py [country {optional}] [state {optional}] getRegions"
        )
        exit()

    if sys.argv[-1] == 'getRegions':
        if numArg == 2:
            print(np.sort(getRegionsCountry()))
        elif numArg == 3:
            print(np.sort(getRegionsState()))
        else:
            print(np.sort(getRegionsCounty()))
        exit()

    country = sys.argv[1]
    if numArg == 2:
        I, D, T = createTimeDataCountry()
    elif numArg == 3:
        I, D, T = createTimeDataState()
    else:
        I, D, T = createTimeDataCounty()

    print("\nRaw Data")
    printRawData(I, D, T)
    print("\nInfection Growth Factor")
    printGrowthFactor(I)
    print("\nDeath Growth Factor")
    printGrowthFactor(D)

    infect.showDailyChange(T, I, D)
Beispiel #2
0
def createTimeDataCountry():
    region = sys.argv[1]
    infected = []
    deaths = []
    days = []

    posRegions = getRegionsCountry()
    if region not in posRegions:
        print("Region: %s, is not a posible region..." % region)
        print("Possible Regions:\n")
        print(np.sort(posRegions))
        exit()

    k = 0
    while True:
        curDate = startDate + dt.timedelta(days=k)
        k += 1
        if curDate > endDate:
            break
        df = getData(curDate)
        cr = 'Country/Region'
        try:
            df[cr]
        except:
            cr = 'Country_Region'
        try:
            if df is None:
                continue
            if region == "all":
                break
            elif region == "world":
                infected.append(np.sum(df['Confirmed']))
                deaths.append(np.sum(df['Deaths']))
                days.append(k)
            else:
                if region == 'China':
                    gg = df.loc[df[cr] == 'China']
                    if len(gg) == 0:
                        gg = gg = df.loc[df[cr] == 'Mainland China']
                else:
                    gg = df.loc[df[cr] == region]
                numInfected = np.sum(gg['Confirmed'])
                numDeaths = np.sum(gg['Deaths'])
                if numInfected * numDeaths > 0:
                    infected.append(np.sum(gg['Confirmed']))
                    deaths.append(np.sum(gg['Deaths']))
                    days.append(k)
        except:
            print(df)
    infected = np.array(infected)
    deaths = np.array(deaths)
    days = np.array(days)

    ids = []
    temp = np.where(infected > 0)
    ids.append(temp[0])
    temp = np.where(deaths > 0)
    ids.append(temp[0])
    minIDlen = 1.0e10
    for idc in ids:
        if len(idc) < minIDlen:
            minIDlen = len(idc)
            minID = idc

    if minIDlen > 3:
        return infected[minID], deaths[minID], days[minID]
    else:
        print("Not enough data... Exiting...")
        daysAll = np.array(daysAll)
        infectedAll = np.array(infectedAll)
        deathsAll = np.array(deathsAll)
        printFlag = False
        print('Days, Infected, Deaths')
        for k in range(len(infectedAll)):
            if infectedAll[k] > 0:
                printFlag = True
            if printFlag:
                print("%d, %d, %d" %
                      (daysAll[k], infectedAll[k], deathsAll[k]))
                # print(daysAll[k],', ',infectedAll[k],', ',deathsAll[k])
        infect.showDailyChange(daysAll, infectedAll, deathsAll)
        exit()
Beispiel #3
0
def createTimeData(region):
    infected = []
    deaths = []
    days = []

    infectedAll = []
    deathsAll = []
    daysAll = []

    if not (region == 'all'):
        posRegions = getRegions()
        if region not in posRegions:
            print("Region: %s, is not a posible region..." % region)
            print("Possible Regions:\n")
            print(posRegions)
            exit()

    getTotalPopulation(region)

    k = 0
    gotData = False
    while True:
        curDate = startDate + dt.timedelta(days=k)
        k += 1
        if curDate > endDate:
            break
        df = getData(curDate)
        cr = 'Province_State'
        try:
            df[cr]
            df = df[df[cr] == 'Iowa']
            cr = 'Admin2'
        except:
            cr = 'Province_State'
        try:
            if df is None:
                continue
            if region == "all":
                infected.append(np.sum(df['Confirmed']))
                deaths.append(np.sum(df['Deaths']))
                days.append(k)
            else:
                gg = df.loc[df[cr] == region]
                numInfected = np.sum(gg['Confirmed'])
                numDeaths = np.sum(gg['Deaths'])
                infectedAll.append(numInfected)
                deathsAll.append(numDeaths)
                daysAll.append(k)
                if numInfected * numDeaths > 0:
                    infected.append(np.sum(gg['Confirmed']))
                    deaths.append(np.sum(gg['Deaths']))
                    days.append(k)
            gotData = True
        except:
            if gotData:
                print(df)

    infected = np.array(infected)
    deaths = np.array(deaths)
    days = np.array(days)

    ids = []
    temp = np.where(infected > 0)
    ids.append(temp[0])
    temp = np.where(deaths > 0)
    ids.append(temp[0])
    minIDlen = 1.0e10
    for idc in ids:
        if len(idc) < minIDlen:
            minIDlen = len(idc)
            minID = idc

    if minIDlen > 3:
        return infected[minID], deaths[minID], days[minID]
    else:
        print("Not enough data... Exiting...")
        daysAll = np.array(daysAll)
        infectedAll = np.array(infectedAll)
        deathsAll = np.array(deathsAll)
        printFlag = False
        print('Days, Infected, Deaths')
        for k in range(len(infectedAll)):
            if infectedAll[k] > 0:
                printFlag = True
            if printFlag:
                print("%d, %d, %d" %
                      (daysAll[k], infectedAll[k], deathsAll[k]))
                # print(daysAll[k],', ',infectedAll[k],', ',deathsAll[k])
        infect.showDailyChange(daysAll, infectedAll)
        exit()