mirror of https://github.com/apache/superset.git
Adding basic resampling capabilities from pandas
This commit is contained in:
parent
3a3e7c8964
commit
ade917582f
|
@ -185,6 +185,18 @@ class FormFactory(object):
|
|||
"The time granularity for the visualization. Note that you "
|
||||
"can define arbitrary expression that return a DATETIME "
|
||||
"column in the table editor")),
|
||||
'resample_rule': FreeFormSelectField(
|
||||
'Resample Rule', default='',
|
||||
choices=self.choicify(('1M', '1H', '1D', '7D', '1M', '1Y')),
|
||||
description=("Pandas resample rule")),
|
||||
'resample_how': FreeFormSelectField(
|
||||
'Resample How', default='',
|
||||
choices=self.choicify(('', 'avg', 'sum',)),
|
||||
description=("Pandas resample how")),
|
||||
'resample_fillmethod': FreeFormSelectField(
|
||||
'Resample Fill Method', default='',
|
||||
choices=self.choicify(('', 'ffill', 'bfill')),
|
||||
description=("Pandas resample fill method")),
|
||||
'since': FreeFormSelectField(
|
||||
'Since', default="7 days ago",
|
||||
choices=self.choicify([
|
||||
|
|
|
@ -5,7 +5,7 @@ import uuid
|
|||
|
||||
from flask import flash, request, Markup
|
||||
from markdown import markdown
|
||||
from pandas.io.json import dumps, to_json
|
||||
from pandas.io.json import dumps
|
||||
from werkzeug.datastructures import ImmutableMultiDict
|
||||
from werkzeug.urls import Href
|
||||
import numpy as np
|
||||
|
@ -629,6 +629,7 @@ class NVD3TimeSeriesViz(NVD3Viz):
|
|||
('rolling_type', 'rolling_periods'),
|
||||
'time_compare',
|
||||
'num_period_compare',
|
||||
('resample_how', 'resample_rule',), 'resample_fillmethod'
|
||||
),
|
||||
},
|
||||
)
|
||||
|
@ -646,6 +647,17 @@ class NVD3TimeSeriesViz(NVD3Viz):
|
|||
columns=form_data.get('groupby'),
|
||||
values=form_data.get('metrics'))
|
||||
|
||||
fm = form_data.get("resample_fillmethod")
|
||||
if not fm:
|
||||
fm = None
|
||||
how = form_data.get("resample_how")
|
||||
rule = form_data.get("resample_rule")
|
||||
if how and rule:
|
||||
df = df.resample(rule, how=how, fill_method=fm)
|
||||
if not fm:
|
||||
df = df.fillna(0)
|
||||
|
||||
|
||||
if self.sort_series:
|
||||
dfs = df.sum()
|
||||
dfs.sort(ascending=False)
|
||||
|
|
Loading…
Reference in New Issue