Esempio n. 1
0
def tabulateStateResults(states, showMethods=False):

    results = OrderedDict()
    results["State"] = []
    if showMethods:
        for m in methodsToAvgOver: results[m+"(%)"] = []

    results["Cases"] = []; results["Deaths"] = []; results["IncidenceRate"] = []
    results["InfChance"] = []; results["ContactBudget"] = [];
    #results["ActiveInf"] = []; results["infOnDate"] = []

    diffAvg = {x:0 for x in methodsToAvgOver}
    odds = {x:0 for x in methodsToAvgOver}
    for s in states:
        results["State"].append(s)

        cumCases = dataIO.getEntryFromCTPData(s, userParams["consideredDate"], "positive")
        cumCasesPerMil = float(cumCases)*1000000.0 / statePopulation[s]
        results["Cases"].append(int(cumCasesPerMil))

        cumDeaths = dataIO.getEntryFromCTPData(s, userParams["consideredDate"], "death")
        cumDeathsPerMil = float(cumDeaths)*1000000.0 / statePopulation[s]
        results["Deaths"].append(int(cumDeathsPerMil))

        infectionsOverPast14Days = dataIO.getEntryFromCTPData(s, userParams["consideredDate"], "positiveIncrease", 14)
        incidenceRate = (1000000.0*infectionsOverPast14Days)/statePopulation[s]
        results["IncidenceRate"].append(int(incidenceRate*100)/100.0)

        oddsAvg = 100 * model.getInfecProbability(s, userParams["TP"], userParams["contacts"], methodsToAvgOver, tqspace=userParams["timeToQuar"])
        # results["InfProb(%)"].append(oddsAvg)
        results["InfChance"].append(str(int(oddsAvg*100)/100.0)+"%")

        outcome, maxM = model.getContactsBudget(s, userParams["TP"], userParams["comfortProb"], methodsToAvgOver,
                                                tqspace=userParams["timeToQuar"])
        if outcome != "NO LIMIT":
            results["ContactBudget"].append(int(maxM))
        else:
            results["ContactBudget"].append(outcome)

        # activeInfections = model.getPhi_i(s, userParams["TP"], userParams["contacts"], ["A"], tqspace=userParams["timeToQuar"])
        # results["ActiveInf"].append(ceil(activeInfections))
        #
        # infOnDate = model.getInfectionsOnRefDateInRegion(userParams["consideredDate"], s, ["A"], tqspace=lag)
        # results["infOnDate"].append(ceil(infOnDate))

        if showMethods:
            for method in methodsToAvgOver:
                odds[method] = 100 * model.getInfecProbability(s, userParams["TP"], userParams["contacts"], method)
                diffAvg[method] += (odds[method] - oddsAvg)

                results[method+"(%)"].append(odds[method])

    resultsCache["results"] = results
    resultsCache["lastUpdate"] = datetime.datetime.now()
    print("Cached results at", resultsCache["lastUpdate"])

    outputResults(results, showMethods, diffAvg)
Esempio n. 2
0
def study_pim_vs_m_CompareQuar(region, mspace, methods, quarValues):
    for tq in quarValues:
        pim = model.getInfecProbability(region, userParams["TP"], mspace, methods, tq)
        plt.plot(mspace, pim, label=["No Quar" if tq==lag else "Quar aft 5d"])

    figTitle = "Infection Probability vs contacts for " + region + ": p_t=" + str(int(userParams["TP"] * 100)) + "%"
    showPlot(figTitle, "Number of contacts (m)", "Infection probability")
Esempio n. 3
0
def study_pim_vs_m_compareDays(region, mspace, methods, dateValues):
    for date in dateValues:
        pim = model.getInfecProbability(region, userParams["TP"], mspace, methods, userParams["timeToQuar"], date)
        plt.plot(mspace, pim, label=date)

    figTitle = "Infection Probability vs contacts for " + region + ": p_t=" + str(int(userParams["TP"] * 100)) + "%"
    showPlot(figTitle, "Number of contacts (m)",  "Infection probability")
Esempio n. 4
0
def study_pim_vs_m_Compare_p_t(region, mspace, methods, p_t_values):
    for pt in p_t_values:
        pim = model.getInfecProbability(region, pt, mspace, methods)
        plt.plot(mspace, pim, label="p_t = " + str(pt))

    figTitle = "Infection Probability vs contacts for " + region + " for different p_t values"
    showPlot(figTitle, "Number of contacts (m)", "Infection probability")
Esempio n. 5
0
def study_pim_vs_p_t_CompareMethodsForGivenRegion(region, ptspace, methodList):
    for method in methodList:
        pim = model.getInfecProbability(region, ptspace, userParams["contacts"], method)
        plt.plot(ptspace, pim, methColors[method], label="Method-" + method)

    figTitle = "Infection Prob vs Transfer Prob for " + region + ": " + str(userParams["contacts"]) + " contacts"
    showPlot(figTitle, "Transfer probability (p_t)", "Infection probability")
Esempio n. 6
0
def study_pim_vs_m_CompareMethodsForGivenRegion(region, mspace, methodList):
    for method in methodList:
        pim = model.getInfecProbability(region, userParams["TP"], mspace, method)
        plt.plot(mspace, pim, methColors[method], label="Method-" + method)

    figTitle = "Infection Prob vs contacts for " + region + ": p_t=" + str(int(userParams["TP"]*100)) + "%"
    showPlot(figTitle, "Number of contacts (m)", "Infection probability")
Esempio n. 7
0
def study_pim_vs_tq_CompareRegions(regionList, tqspace, methods):
    for region in regionList:
        pim = model.getInfecProbability(region, userParams["TP"], userParams["contacts"], methods, tqspace)
        plt.plot(tqspace, pim, label=region)

    figTitle = "Infection Probability vs days-to-quarantine " + ": p_t=" + str(int(userParams["TP"] * 100)) + "%"
    plt.xlim(24,0)
    showPlot(figTitle, "Days to quarantine (t_q)", "Infection probability")
Esempio n. 8
0
def study_pim_vs_m_CompareRegions(regionList, mspace, methods):
    for region in regionList:
        pim = model.getInfecProbability(region, userParams["TP"], mspace, methods)
        #plt.plot(mspace, pim, regColors[region], label=region)
        plt.plot(mspace, pim, label=region)

    figTitle = "Infection Probability vs contacts:"  + " p_t=" + str(int(userParams["TP"]*100)) + "%"
    showPlot(figTitle, "Number of contacts (m)", "Infection probability")
Esempio n. 9
0
def tabulateRoleInfProbabilities(states):
    scenarioVals = {
        "Grocery Store Shopper": (500, 15),
        "Grocery Store Cashier": (200, 100),
        "Warehouse Worker": (100, 50),
        "Meatpacking Worker": (10, 50),
        "Subway Rider": (75, 30),
        "Takeout Cashier": (200, 30),
        "Non ER Nurse": (20, 20)
    }

    for p in scenarioVals.keys():
        print(p, " & ", "1/" + str(scenarioVals[p][0]), " & ", scenarioVals[p][1], end="  ")
        for s in states:
            pim = model.getInfecProbability(s, 1 / scenarioVals[p][0], scenarioVals[p][1], methodsToAvgOver)
            print(" & ", "{:.2f}".format(100 * pim) + "\%", "  ", end="")

        print("\\\\ \hline")
Esempio n. 10
0
def study_pim_vs_days_CompareRegions(regionList, drange, methods):
    movAvgWin = userParams["avgOverDays"]
    for region in regionList:
        pims = []
        for d in drange:
            refDate = userParams["consideredDate"] - datetime.timedelta(days=d)
            pim = model.getInfecProbability(region, userParams["TP"], userParams["contacts"], methods, userParams["timeToQuar"], refDate)
            pims.append(pim)

        pims.reverse()
        pimsMA = model.movingAverage(pims, movAvgWin)

        plt.plot(drange[(movAvgWin-1):], pimsMA, label=region)

    figTitle = "Infection Prob. history " + ": " + str(userParams["contacts"]) + " contacts" + " p_t=" + \
               str(int(userParams["TP"] * 100)) + "%, " + str(movAvgWin) + " day avg"
    showPlot(figTitle, "Days since" + str(userParams["consideredDate"] - datetime.timedelta(days=userParams["history"])),
                    "Infection probability")