Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[table viz] allow showing time granularity in table #2284

Merged
merged 1 commit into from
Feb 27, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,24 +363,34 @@ class TableViz(BaseViz):
credits = 'a <a href="https://github.com/airbnb/superset">Superset</a> original'
is_timeseries = False

def should_be_timeseries(self):
fd = self.form_data
# TODO handle datasource-type-specific code in datasource
return (
(fd.get('granularity') and fd.get('granularity') != 'all') or
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code below says: self.form_data.get("granularity") == "all" and here u return fd.get('granularity') != 'all'

(fd.get('granularity_sqla') and fd.get('time_grain_sqla'))
)

def query_obj(self):
d = super(TableViz, self).query_obj()
fd = self.form_data

if fd.get('all_columns') and (fd.get('groupby') or fd.get('metrics')):
raise Exception(
"Choose either fields to [Group By] and [Metrics] or "
"[Columns], not both")

if fd.get('all_columns'):
d['columns'] = fd.get('all_columns')
d['groupby'] = []
order_by_cols = fd.get('order_by_cols') or []
d['orderby'] = [json.loads(t) for t in order_by_cols]

d['is_timeseries'] = self.should_be_timeseries()
return d

def get_data(self, df):
if (
self.form_data.get("granularity") == "all" and
DTTM_ALIAS in df):
if not self.should_be_timeseries() and DTTM_ALIAS in df:
del df[DTTM_ALIAS]

return dict(
Expand Down