Esempio n. 1
0
def filtra_obitos_covid(cases, estado):
    obitos = cases[(cases.state == estado) & (cases.place_type == 'state')][['date', 'confirmed', 'deaths']]
    obitos['data'] = pd.to_datetime(obitos.date)
    obitos.set_index('data', inplace=True)
    obitos.sort_index(inplace=True)
    obitos['incidencia'] = obitos.deaths.diff()
    obitos['ew'] = [int(episem.episem(x, out='W')) for x in obitos.index]
    return obitos
Esempio n. 2
0
def plot_excess_deaths(data, estado, only_viral=True):
    obitos = data[(data.state == estado) & (data.place_type == 'state')][[
        'date', 'Casos Confirmados', 'Mortes Acumuladas'
    ]]
    obitos['data'] = pd.to_datetime(obitos.date)
    obitos.set_index('data', inplace=True)
    obitos.sort_index(inplace=True)
    obitos['incidencia'] = obitos['Mortes Acumuladas'].diff()
    obitos['ew'] = [int(episem.episem(x, out='W')) for x in obitos.index]
    if only_viral:
        ob_sim = pd.read_csv(f'dashboard/dados/baseline_{estado}.csv.gz')
    else:
        ob_sim = pd.read_csv(
            f'dashboard/dados/baseline_{estado}_all_resp.csv.gz')
    obitos_W = obitos.groupby('ew').sum().incidencia.iloc[:-1]
    # obitos_W.reset_index()
    fig = px.line(ob_sim, x=ob_sim.index, y='median', line_shape='spline')
    fig.add_scatter(x=ob_sim.index,
                    y=ob_sim.perc_25,
                    name='1⁰ quartil',
                    fill='tonexty',
                    hovertemplate="1⁰ quartil: %{y:.0f} SE: %{x}")
    fig.add_scatter(x=ob_sim.index,
                    y=ob_sim.perc_75,
                    name='3⁰ quartil',
                    fill='tonexty',
                    hovertemplate="3⁰ quartil: %{y:.0f} SE: %{x}")
    fig.add_scatter(x=obitos_W.index.values,
                    y=obitos_W.values,
                    fillcolor='red',
                    marker_symbol=3,
                    hovertemplate="Mortes por semana: %{y:.0f} SE: %{x}",
                    name='Mortes por COVID-19')

    fig.update_traces(mode='lines+markers')
    fig.update_layout(
        xaxis_title="Semanas epidemiológicas",
        yaxis_title="Mortes",
        plot_bgcolor='rgba(0,0,0,0)',
        legend_orientation="h",
    )
    fig.update_xaxes(
        showgrid=True,
        gridwidth=1,
        gridcolor='rgb(211,211,211)',
        showline=True,
        linewidth=1,
        linecolor='black',
    )
    fig.update_yaxes(
        showgrid=True,
        gridwidth=1,
        gridcolor='rgb(211,211,211)',
        showline=True,
        linewidth=1,
        linecolor='black',
    )
    st.plotly_chart(fig)
def lastepiweek(year):
    # Calcula o valor da última semana do ano

    day = datetime.datetime(int(year), 12, 31)  # Ultimo dia do ano
    day_week = episem.extractweekday(day)  # dia semana do ultimo dia

    if day_week < 3:
        day = day - datetime.timedelta(days=(day_week+1))
    else:
        day = day + datetime.timedelta(days=(6-day_week))

    return(int(episem.episem(day, out='W')))
Esempio n. 4
0
def main(fname, sep=','):

    df = pd.read_csv(fname, low_memory=False, encoding='utf-8')
    target_cols = [
        'DT_NOTIFIC', 'DT_DIGITA', 'DT_SIN_PRI', 'DT_ANTIVIR', 'DT_COLETA',
        'DT_IFI', 'DT_PCR_1', 'DT_ENCERRA'
    ]
    yearweek_cols = ['%s_epiyearweek' % k for k in target_cols]
    year_cols = ['%s_epiyear' % k for k in target_cols]
    week_cols = ['%s_epiweek' % k for k in target_cols]
    df[yearweek_cols] = df[target_cols].applymap(episem)
    df[year_cols] = df[target_cols].applymap(lambda x: episem(x, out='Y'))
    df[week_cols] = df[target_cols].applymap(lambda x: episem(x, out='W'))

    # Calculate opportunities:
    df = opportunity_calc_epiweeks(df,
                                   colA='DT_SIN_PRI',
                                   colB='DT_DIGITA',
                                   colnew='SinPri2Digita_DelayWeeks')
    df = opportunity_calc_epiweeks(df,
                                   colA='DT_SIN_PRI',
                                   colB='DT_ANTIVIR',
                                   colnew='SinPri2Antivir_DelayWeeks')
    df = opportunity_calc_epiweeks(df,
                                   colA='DT_SIN_PRI',
                                   colB='DT_NOTIFIC',
                                   colnew='SinPri2Notific_DelayWeeks')
    df = opportunity_calc_epiweeks(df,
                                   colA='DT_SIN_PRI',
                                   colB='DT_COLETA',
                                   colnew='SinPri2Coleta_DelayWeeks')
    df = opportunity_calc_epiweeks(df,
                                   colA='DT_NOTIFIC',
                                   colB='DT_ENCERRA',
                                   colnew='Notific2Encerra_DelayWeeks')
    df = opportunity_calc_epiweeks(df,
                                   colA='DT_COLETA',
                                   colB='DT_IFI',
                                   colnew='Coleta2IFI_DelayWeeks')
    df = opportunity_calc_epiweeks(df,
                                   colA='DT_COLETA',
                                   colB='DT_PCR_1',
                                   colnew='Coleta2PCR_DelayWeeks')
    df = opportunity_calc_epiweeks(df,
                                   colA='DT_NOTIFIC',
                                   colB='DT_DIGITA',
                                   colnew='Notific2Digita_DelayWeeks')

    df = opportunity_calc_days(df,
                               colA='DT_SIN_PRI',
                               colB='DT_DIGITA',
                               colnew='SinPri2Digita_DelayDays')
    df = opportunity_calc_days(df,
                               colA='DT_SIN_PRI',
                               colB='DT_ANTIVIR',
                               colnew='SinPri2Antivir_DelayDays')
    df = opportunity_calc_days(df,
                               colA='DT_SIN_PRI',
                               colB='DT_NOTIFIC',
                               colnew='SinPri2Notific_DelayDays')
    df = opportunity_calc_days(df,
                               colA='DT_SIN_PRI',
                               colB='DT_COLETA',
                               colnew='SinPri2Coleta_DelayDays')
    df = opportunity_calc_days(df,
                               colA='DT_NOTIFIC',
                               colB='DT_ENCERRA',
                               colnew='Notific2Encerra_DelayDays')
    df = opportunity_calc_days(df,
                               colA='DT_COLETA',
                               colB='DT_IFI',
                               colnew='Coleta2IFI_DelayDays')
    df = opportunity_calc_days(df,
                               colA='DT_COLETA',
                               colB='DT_PCR_1',
                               colnew='Coleta2PCR_DelayDays')
    df = opportunity_calc_days(df,
                               colA='DT_NOTIFIC',
                               colB='DT_DIGITA',
                               colnew='Notific2Digita_DelayDays')

    fout = '../clean_data/%s_epiweek.csv' % fname.split('/')[-1][:-4]
    df.to_csv(fout, index=False, encoding='utf-8')