mirror of https://github.com/apache/superset.git
[line] growth vs factor option for 'Period Ratio' (#970)
* [line] growth vs factor option for 'Period Ratio' * i18n
This commit is contained in:
parent
379cf6cbd9
commit
84213ab8cd
|
@ -817,6 +817,18 @@ class FormFactory(object):
|
|||
"[integer] Number of period to compare against, "
|
||||
"this is relative to the granularity selected")
|
||||
}),
|
||||
'period_ratio_type': (SelectField, {
|
||||
"label": _("Period Ratio Type"),
|
||||
"default": 'growth',
|
||||
"choices": (
|
||||
('factor', _('factor')),
|
||||
('growth', _('growth')),
|
||||
('value', _('value')),
|
||||
),
|
||||
"description": _(
|
||||
"`factor` means (new/previous), `growth` is "
|
||||
"((new/previous) - 1), `value` is (new-previous)")
|
||||
}),
|
||||
'time_compare': (TextField, {
|
||||
"label": _("Time Shift"),
|
||||
"default": "",
|
||||
|
|
|
@ -997,7 +997,7 @@ class NVD3TimeSeriesViz(NVD3Viz):
|
|||
'fields': (
|
||||
('rolling_type', 'rolling_periods'),
|
||||
'time_compare',
|
||||
'num_period_compare',
|
||||
('num_period_compare', 'period_ratio_type'),
|
||||
None,
|
||||
('resample_how', 'resample_rule',), 'resample_fillmethod'
|
||||
),
|
||||
|
@ -1038,7 +1038,14 @@ class NVD3TimeSeriesViz(NVD3Viz):
|
|||
num_period_compare = form_data.get("num_period_compare")
|
||||
if num_period_compare:
|
||||
num_period_compare = int(num_period_compare)
|
||||
df = (df / df.shift(num_period_compare)) - 1
|
||||
prt = form_data.get('period_ratio_type')
|
||||
if prt and prt == 'growth':
|
||||
df = (df / df.shift(num_period_compare)) - 1
|
||||
elif prt and prt == 'value':
|
||||
df = df - df.shift(num_period_compare)
|
||||
else:
|
||||
df = df / df.shift(num_period_compare)
|
||||
|
||||
df = df[num_period_compare:]
|
||||
|
||||
rolling_periods = form_data.get("rolling_periods")
|
||||
|
|
Loading…
Reference in New Issue