コード例 #1
0
ファイル: geo.py プロジェクト: LukaP-BB/PyDiscord
def donnesDepistage(days=40, floatingMean=15):
    """réduit les données de dépistage en une valeur par département"""
    # chargement des données de dépistage
    df = loadFromUrl(urlDepistQuot)
    df = df[df.cl_age90 == 0]

    today = dtt.date.today()
    firsDay = dtt.timedelta(days=days)
    firsDay = today - firsDay
    df = timeFrame(df, firsDay.isoformat(), today.isoformat())

    # régression linéaire sur le timeframe pour les taux de contamination
    depDict = {}
    deps = list(pd.unique(df.dep))
    for dep in deps:
        subData = df[df.dep == dep]
        nb_jours = range(subData.count().jour)
        taux = subData.P / pd.to_numeric(list(subData.T))
        taux = taux.rolling(window=floatingMean, min_periods=1).mean()
        slope, intercept, rvalue, pvalue, stderr = stats.linregress(
            nb_jours, taux)
        depDict[depFromCode(dep)] = slope

    # transformation du dictionnaire en DataFrame
    df = pd.DataFrame(depDict.items())

    return df
コード例 #2
0
ファイル: geo.py プロジェクト: LukaP-BB/PyDiscord
def plotFrance(dep: str,
               days: int = 40,
               floatingMean=15,
               params=None,
               d1=None,
               d2=None):
    set_plt()
    if params == None:
        return False
    else:
        # print(params)
        if d2 == None:
            d2 = dtt.date.today()
        if d1 == None:
            d1 = dtt.timedelta(days=days)
            d1 = d2 - d1
        df = loadFromUrl(urlDepistQuot)

        df = setAgeClass(df, "0")
        df = timeFrame(df, d1, d2)
        # print(df.shape)
        df = df.groupby("jour", as_index=False).sum()
        # print(df.shape)
        # print(df)

        nb_jours = range(df.count().jour)

        if params["taux"]:
            a = df.P
            b = pd.to_numeric(list(df["T"]))
            # print(b)
            # print(a/b)
            taux = a / b
        else:
            taux = df.P
        if params["moy"]:
            taux = taux.rolling(window=floatingMean, min_periods=1).mean()
        if params["log"]:
            taux = np.log(taux)
        slope, intercept, rvalue, pvalue, stderr = stats.linregress(
            nb_jours, taux)

        fig, ax = plt.subplots()
        ax.plot(df.jour, taux, label="Tests journaliers totaux en France")
        if rvalue >= 0.9:
            ax.plot(
                nb_jours,
                nb_jours * slope + intercept,
                label=
                f"Pente : {round(slope, 5)} /jour\nrvalue : {round(rvalue, 2)}"
            )

        ax.legend()
        ax.xaxis.set_major_locator(plt.MaxNLocator(5))
        ax.yaxis.set_major_locator(plt.MaxNLocator(10))
        plt.title(f"Evolution des dépistages positifs en France")
        plt.savefig("fig.jpg")
        return "France", d1, d2
コード例 #3
0
ファイル: interface.py プロジェクト: LukaP-BB/PyDiscord
def plotFromArgs(args):
    """Creates a plot in jpg format with the given arguments formated by parseArgs()"""
    df2 = anl.loadData()

    if args["dep"] == "FR":
        df2 = anl.france(df2)
    else:
        df2 = anl.parDep(df2, args["dep"])
    df2 = anl.timeFrame(df2, args["d1"], args["d2"])
    anl.plotThat(df2, args)

    # generate some infos to be printed somewhere
    finalInfos = getInfos(args)
    return finalInfos
コード例 #4
0
ファイル: geo.py プロジェクト: LukaP-BB/PyDiscord
def plotGivenDep(dep: str,
                 days: int = 40,
                 floatingMean=15,
                 params=None,
                 d1=None,
                 d2=None):
    set_plt()
    if params == None:
        return False
    else:
        if d2 == None:
            d2 = dtt.date.today()
        if d1 == None:
            d1 = dtt.timedelta(days=days)
            d1 = d2 - d1
        df = loadFromUrl(urlDepistQuot)

        df = setAgeClass(df, "0")
        df = timeFrame(df, d1, d2)
        df = df[df.dep == str(dep)]

        nb_jours = range(df.count().jour)
        taux = df.P / pd.to_numeric(list(df.T))
        taux = taux.rolling(window=floatingMean, min_periods=1).mean()
        if params["log"]:
            taux = np.log(taux)
        slope, intercept, rvalue, pvalue, stderr = stats.linregress(
            nb_jours, taux)

        fig, ax = plt.subplots()
        ax.plot(df.jour, taux, label="Taux de tests positifs")
        if rvalue >= 0.8:
            ax.plot(
                nb_jours,
                nb_jours * slope + intercept,
                label=
                f"Pente : {round(slope, 5)} /jour\nrvalue : {round(rvalue, 2)}"
            )

        ax.legend()
        ax.xaxis.set_major_locator(plt.MaxNLocator(5))
        ax.yaxis.set_major_locator(plt.MaxNLocator(10))
        plt.title(
            f"Evolution des taux de dépistages positifs : {depFromCode(dep)}")
        plt.savefig("fig.jpg")
        return depFromCode(dep), d1, d2
コード例 #5
0
ファイル: geo.py プロジェクト: LukaP-BB/PyDiscord
def donnesHosp(days=40, floatingMean=15, type="hosp"):
    df = loadData()
    today = dtt.date.today()
    firsDay = dtt.timedelta(days=days)
    firsDay = today - firsDay
    df = timeFrame(df, firsDay.isoformat(), today.isoformat())

    # régression linéaire sur le timeframe pour les données hospitalières
    depDict = {}
    deps = list(pd.unique(df.dep))
    for dep in deps:
        subData = df[df.dep == dep]
        nb_jours = range(subData.count().jour)
        donnees = subData.dc
        slope, intercept, rvalue, pvalue, stderr = stats.linregress(
            nb_jours, donnees)
        depDict[depFromCode(dep)] = slope

    # transformation du dictionnaire en DataFrame
    df = pd.DataFrame(depDict.items())

    return df