def data(self): """Data representation of the datasource sent to the frontend""" order_by_choices = [] for s in sorted(self.column_names): order_by_choices.append((json.dumps([s, True]), s + ' [asc]')) order_by_choices.append((json.dumps([s, False]), s + ' [desc]')) verbose_map = { o.metric_name: o.verbose_name or o.metric_name for o in self.metrics } verbose_map.update({ o.column_name: o.verbose_name or o.column_name for o in self.columns }) return { 'all_cols': utils.choicify(self.column_names), 'column_formats': self.column_formats, 'edit_url': self.url, 'filter_select': self.filter_select_enabled, 'filterable_cols': utils.choicify(self.filterable_column_names), 'gb_cols': utils.choicify(self.groupby_column_names), 'id': self.id, 'metrics_combo': self.metrics_combo, 'name': self.name, 'order_by_choices': order_by_choices, 'type': self.type, 'metrics': [o.data for o in self.metrics], 'columns': [o.data for o in self.columns], 'verbose_map': verbose_map, }
def data(self): """Data representation of the datasource sent to the frontend""" order_by_choices = [] for s in sorted(self.column_names): order_by_choices.append((json.dumps([s, True]), s + ' [asc]')) order_by_choices.append((json.dumps([s, False]), s + ' [desc]')) verbose_map = {'__timestamp': 'Time'} verbose_map.update({ o.metric_name: o.verbose_name or o.metric_name for o in self.metrics }) verbose_map.update({ o.column_name: o.verbose_name or o.column_name for o in self.columns }) return { 'all_cols': utils.choicify(self.column_names), 'column_formats': self.column_formats, 'database': self.database.data, # pylint: disable=no-member 'edit_url': self.url, 'filter_select': self.filter_select_enabled, 'filterable_cols': utils.choicify(self.filterable_column_names), 'gb_cols': utils.choicify(self.groupby_column_names), 'id': self.id, 'metrics_combo': self.metrics_combo, 'name': self.name, 'order_by_choices': order_by_choices, 'type': self.type, 'metrics': [o.data for o in self.metrics], 'columns': [o.data for o in self.columns], 'verbose_map': verbose_map, }
def data(self): """Data representation of the datasource sent to the frontend""" order_by_choices = [] for s in sorted(self.column_names): order_by_choices.append((json.dumps([s, True]), s + ' [asc]')) order_by_choices.append((json.dumps([s, False]), s + ' [desc]')) verbose_map = {'__timestamp': 'Time'} verbose_map.update({ o.metric_name: o.verbose_name or o.metric_name for o in self.metrics }) verbose_map.update({ o.column_name: o.verbose_name or o.column_name for o in self.columns }) return { # simple fields 'id': self.id, 'column_formats': self.column_formats, 'description': self.description, 'database': self.database.data, # pylint: disable=no-member 'default_endpoint': self.default_endpoint, 'filter_select': self.filter_select_enabled, # TODO deprecate 'filter_select_enabled': self.filter_select_enabled, 'name': self.name, 'datasource_name': self.datasource_name, 'type': self.type, 'schema': self.schema, 'offset': self.offset, 'cache_timeout': self.cache_timeout, 'params': self.params, 'perm': self.perm, # sqla-specific 'sql': self.sql, # computed fields 'all_cols': utils.choicify(self.column_names), 'columns': [o.data for o in self.columns], 'edit_url': self.url, 'filterable_cols': utils.choicify(self.filterable_column_names), 'geofilterable_cols': utils.choicify(self.geofilterable_column_names), 'gb_cols': utils.choicify(self.groupby_column_names), 'metrics': [o.data for o in self.metrics], 'metrics_combo': self.metrics_combo, 'order_by_choices': order_by_choices, 'owner': self.owner.id if self.owner else None, 'verbose_map': verbose_map, 'select_star': self.select_star, }
def data(self): d = super(SqlaTable, self).data if self.type == 'table': grains = self.database.grains() or [] if grains: grains = [(g.name, g.name) for g in grains] d['granularity_sqla'] = utils.choicify(self.dttm_cols) d['time_grain_sqla'] = grains return d
def data(self): d = super(PandasDatasource, self).data # Note that the front end uses `granularity_sqla` and # `time_grain_sqla` as the parameters for selecting the # column and time grain separately. d['granularity_sqla'] = utils.choicify(self.dttm_cols) d['time_grain_sqla'] = [(g, g) for g in self.GRAINS.keys()] logging.info(d) return d
def data(self): """Data representation of the datasource sent to the frontend""" order_by_choices = [] for s in sorted(self.column_names): order_by_choices.append((json.dumps([s, True]), s + ' [asc]')) order_by_choices.append((json.dumps([s, False]), s + ' [desc]')) d = { 'all_cols': utils.choicify(self.column_names), 'column_formats': self.column_formats, 'edit_url': self.url, 'filter_select': self.filter_select_enabled, 'filterable_cols': utils.choicify(self.filterable_column_names), 'gb_cols': utils.choicify(self.groupby_column_names), 'id': self.id, 'metrics_combo': self.metrics_combo, 'name': self.name, 'order_by_choices': order_by_choices, 'type': self.type, } return d
def data(self): d = super(SqlaTable, self).data if self.type == 'table': grains = self.database.grains() or [] if grains: grains = [(g.name, g.label) for g in grains] d['granularity_sqla'] = utils.choicify(self.dttm_cols) d['time_grain_sqla'] = grains # d['metrics'] = [m.data for m in self.metrics if self.has_met_access(m)] # d['columns'] = [c.data for c in self.columns if self.has_col_access(c)] # verbose_map = { # o.metric_name: o.verbose_name or o.metric_name # for o in self.metrics if self.has_met_access(o) # } # verbose_map.update({ # o.column_name: o.verbose_name or o.column_name # for o in self.columns if self.has_col_access(o) # }) # d['verbose_map'] = verbose_map return d