Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Seria legal se a média móvel fosse calculada com intervalo de 7 dias por causa da frequencia de atualização dos dados oficiais #2

Open
Caboverde opened this issue Aug 20, 2020 · 1 comment

Comments

@Caboverde
Copy link

No description provided.

@gdmarmerola
Copy link
Contributor

Opa, beleza?

Este repositório não espelha 100% o produtivo (que tem chaves para o deploy e cronjobs). No loft.science agora reportamos uma suavização gaussiana de 14 dias. O seguinte código altera esse comportamento:

def smooth_new_cases(new_cases):
    
    """
    Function to apply gaussian smoothing to cases

    Arguments
    ----------
    new_cases: time series of new cases

    Returns 
    ----------
    smoothed_cases: cases after gaussian smoothing

    See also
    ----------
    This code is heavily based on Realtime R0
    by Kevin Systrom
    https://github.com/k-sys/covid-19/blob/master/Realtime%20R0.ipynb
    """

    smoothed_cases = new_cases.rolling(14,
        win_type='gaussian',
        min_periods=1,
        #center=True
        ).mean(std=3).round()
    
    zeros = smoothed_cases.index[smoothed_cases.eq(0)]
    if len(zeros) == 0:
        idx_start = 0
    else:
        last_zero = zeros.max()
        idx_start = smoothed_cases.index.get_loc(last_zero) + 1
    smoothed_cases = smoothed_cases.iloc[idx_start:]
    original = new_cases.loc[smoothed_cases.index]
    
    return original, smoothed_cases

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants