Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 3E5302004F1 for ; Wed, 30 Aug 2017 22:32:14 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 3CED9169E0C; Wed, 30 Aug 2017 20:32:14 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 82BFF169DF8 for ; Wed, 30 Aug 2017 22:32:13 +0200 (CEST) Received: (qmail 67740 invoked by uid 500); 30 Aug 2017 20:32:12 -0000 Mailing-List: contact commits-help@superset.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@superset.incubator.apache.org Delivered-To: mailing list commits@superset.incubator.apache.org Received: (qmail 67731 invoked by uid 99); 30 Aug 2017 20:32:12 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 30 Aug 2017 20:32:12 +0000 Received: by gitbox.apache.org (ASF Mail Server at gitbox.apache.org, from userid 33) id 50D7B81735; Wed, 30 Aug 2017 20:32:10 +0000 (UTC) Date: Wed, 30 Aug 2017 20:32:10 +0000 To: "commits@superset.apache.org" Subject: [incubator-superset] branch master updated: [line chart] add 'min_periods' control related to rolling windows (#3397) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Message-ID: <150412513040.7662.11585103172463822840@gitbox.apache.org> From: maximebeauchemin@apache.org Reply-To: "commits@superset.apache.org" X-Git-Host: gitbox.apache.org X-Git-Repo: incubator-superset X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: 497a6f1df9c63afc9a065a005c733b8b428babad X-Git-Newrev: ac5da46fb2ddc225f02152a51cbaafcb171b1227 X-Git-Rev: ac5da46fb2ddc225f02152a51cbaafcb171b1227 X-Git-NotificationType: ref_changed_plus_diff X-Git-Multimail-Version: 1.5.dev Auto-Submitted: auto-generated archived-at: Wed, 30 Aug 2017 20:32:14 -0000 This is an automated email from the ASF dual-hosted git repository. maximebeauchemin pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-superset.git The following commit(s) were added to refs/heads/master by this push: new ac5da46 [line chart] add 'min_periods' control related to rolling windows (#3397) ac5da46 is described below commit ac5da46fb2ddc225f02152a51cbaafcb171b1227 Author: Maxime Beauchemin AuthorDate: Wed Aug 30 13:32:07 2017 -0700 [line chart] add 'min_periods' control related to rolling windows (#3397) * [line chart] add 'min_periods' control related to rolling windows * Linting js --- superset/assets/javascripts/explore/stores/controls.jsx | 13 +++++++++++++ superset/assets/javascripts/explore/stores/visTypes.js | 7 +++---- superset/viz.py | 16 +++++++++++----- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/superset/assets/javascripts/explore/stores/controls.jsx b/superset/assets/javascripts/explore/stores/controls.jsx index 554554c..21d8cc8 100644 --- a/superset/assets/javascripts/explore/stores/controls.jsx +++ b/superset/assets/javascripts/explore/stores/controls.jsx @@ -654,6 +654,19 @@ export const controls = { 'relative to the time granularity selected', }, + min_periods: { + type: 'TextControl', + label: 'Min Periods', + isInt: true, + description: ( + 'The minimum number of rolling periods required to show ' + + 'a value. For instance if you do a cumulative sum on 7 days ' + + 'you may want your "Min Period" to be 7, so that all data points ' + + 'shown are the total of 7 periods. This will hide the "ramp up" ' + + 'taking place over the first 7 periods' + ), + }, + series: { type: 'SelectControl', label: 'Series', diff --git a/superset/assets/javascripts/explore/stores/visTypes.js b/superset/assets/javascripts/explore/stores/visTypes.js index d3ee320..318d3327 100644 --- a/superset/assets/javascripts/explore/stores/visTypes.js +++ b/superset/assets/javascripts/explore/stores/visTypes.js @@ -59,11 +59,10 @@ export const sections = { 'that allow for advanced analytical post processing ' + 'of query results', controlSetRows: [ - ['rolling_type', 'rolling_periods'], - ['time_compare'], + ['rolling_type', 'rolling_periods', 'min_periods'], + ['time_compare', null], ['num_period_compare', 'period_ratio_type'], - ['resample_how', 'resample_rule'], - ['resample_fillmethod'], + ['resample_how', 'resample_rule', 'resample_fillmethod'], ], }, ], diff --git a/superset/viz.py b/superset/viz.py index a3d9a5a..b3c49bb 100644 --- a/superset/viz.py +++ b/superset/viz.py @@ -886,18 +886,25 @@ class NVD3TimeSeriesViz(NVD3Viz): dft = df.T df = (dft / dft.sum()).T - rolling_periods = fd.get("rolling_periods") rolling_type = fd.get("rolling_type") + rolling_periods = int(fd.get("rolling_periods") or 0) + min_periods = int(fd.get("min_periods") or 0) if rolling_type in ('mean', 'std', 'sum') and rolling_periods: + kwargs = dict( + arg=df, + window=rolling_periods, + min_periods=min_periods) if rolling_type == 'mean': - df = pd.rolling_mean(df, int(rolling_periods), min_periods=0) + df = pd.rolling_mean(**kwargs) elif rolling_type == 'std': - df = pd.rolling_std(df, int(rolling_periods), min_periods=0) + df = pd.rolling_std(**kwargs) elif rolling_type == 'sum': - df = pd.rolling_sum(df, int(rolling_periods), min_periods=0) + df = pd.rolling_sum(**kwargs) elif rolling_type == 'cumsum': df = df.cumsum() + if min_periods: + df = df[min_periods:] num_period_compare = fd.get("num_period_compare") if num_period_compare: @@ -911,7 +918,6 @@ class NVD3TimeSeriesViz(NVD3Viz): df = df / df.shift(num_period_compare) df = df[num_period_compare:] - return df def get_data(self, df): -- To stop receiving notification emails like this one, please contact ['"commits@superset.apache.org" '].