diff --git a/panoramix/forms.py b/panoramix/forms.py index 13c3bb559d188..d4cd8a3ad9198 100644 --- a/panoramix/forms.py +++ b/panoramix/forms.py @@ -185,6 +185,18 @@ def __init__(self, viz): "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([ @@ -426,11 +438,12 @@ class QueryForm(OmgWtForm): TextField("Super", default='')) for fieldset in viz.fieldsetizer(): for ff in fieldset['fields']: - if isinstance(ff, string_types): - ff = [ff] - for s in ff: - if s: - setattr(QueryForm, s, px_form_fields[s]) + if ff: + if isinstance(ff, string_types): + ff = [ff] + for s in ff: + if s: + setattr(QueryForm, s, px_form_fields[s]) # datasource type specific form elements diff --git a/panoramix/templates/panoramix/explore.html b/panoramix/templates/panoramix/explore.html index dbca1763fabe3..618b831287137 100644 --- a/panoramix/templates/panoramix/explore.html +++ b/panoramix/templates/panoramix/explore.html @@ -69,7 +69,9 @@ {% endif %}
{% for fieldname in fieldset.fields %} - {% if not fieldname.__iter__ %} + {% if not fieldname %} +
+ {% elif not fieldname.__iter__ %} {{ panofield(fieldname) }} {% else %}
diff --git a/panoramix/viz.py b/panoramix/viz.py index c8747fae2c19f..45970341c5150 100644 --- a/panoramix/viz.py +++ b/panoramix/viz.py @@ -5,7 +5,7 @@ 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 @@ -98,7 +98,7 @@ def flat_form_fields(cls): for obj in d['fields']: if isinstance(obj, (tuple, list)): l |= {a for a in obj} - else: + elif obj: l.add(obj) return l @@ -629,6 +629,8 @@ class NVD3TimeSeriesViz(NVD3Viz): ('rolling_type', 'rolling_periods'), 'time_compare', 'num_period_compare', + None, + ('resample_how', 'resample_rule',), 'resample_fillmethod' ), }, ) @@ -646,6 +648,17 @@ def get_df(self, query_obj=None): 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)