From 03e13cb957a63a2afa77fa3ae0d7ae3eef252364 Mon Sep 17 00:00:00 2001 From: Maxime Beauchemin Date: Mon, 30 Nov 2015 12:38:09 -0800 Subject: [PATCH] Adding cumsum to rolling functions --- panoramix/forms.py | 4 ++-- panoramix/viz.py | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/panoramix/forms.py b/panoramix/forms.py index 9048599aa83b8..d9408f10b0086 100644 --- a/panoramix/forms.py +++ b/panoramix/forms.py @@ -127,8 +127,8 @@ def __init__(self, viz): "Limits the number of time series that get displayed")), 'rolling_type': SelectField( 'Rolling', - default='mean', - choices=[(s, s) for s in ['mean', 'sum', 'std']], + default='None', + choices=[(s, s) for s in ['None', 'mean', 'sum', 'std', 'cumsum']], description=( "Defines a rolling window function to apply")), 'rolling_periods': IntegerField( diff --git a/panoramix/viz.py b/panoramix/viz.py index 216c7cd4f0005..78ff03fed4211 100644 --- a/panoramix/viz.py +++ b/panoramix/viz.py @@ -508,17 +508,21 @@ def get_df(self, query_obj=None): rolling_periods = form_data.get("rolling_periods") rolling_type = form_data.get("rolling_type") - if rolling_periods and rolling_type: + + if rolling_type in ('mean', 'std', 'sum') and rolling_periods: if rolling_type == 'mean': - df = pd.rolling_mean(df, int(rolling_periods), min_periods=1) + df = pd.rolling_mean(df, int(rolling_periods), min_periods=0) elif rolling_type == 'std': - df = pd.rolling_std(df, int(rolling_periods), min_periods=1) + df = pd.rolling_std(df, int(rolling_periods), min_periods=0) elif rolling_type == 'sum': - df = pd.rolling_sum(df, int(rolling_periods), min_periods=1) + df = pd.rolling_sum(df, int(rolling_periods), min_periods=0) + elif rolling_type == 'cumsum': + df = df.cumsum() return df def to_series(self, df, classed='', title_suffix=''): series = df.to_dict('series') + chart_data = [] for name in df.T.index.tolist(): ys = series[name] @@ -542,7 +546,7 @@ def to_series(self, df, classed='', title_suffix=''): "color": color, "classed": classed, "values": [ - {'x': ds, 'y': ys[i]} + {'x': ds, 'y': ys[ds]} for i, ds in enumerate(df.timestamp)] } chart_data.append(d)