Adding cumsum to rolling functions
This commit is contained in:
parent
525bd509cb
commit
03e13cb957
|
|
@ -127,8 +127,8 @@ class FormFactory(object):
|
|||
"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(
|
||||
|
|
|
|||
|
|
@ -508,17 +508,21 @@ class NVD3TimeSeriesViz(NVD3Viz):
|
|||
|
||||
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 @@ class NVD3TimeSeriesViz(NVD3Viz):
|
|||
"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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue