Skip to content

Commit

Permalink
Now supporting multi-metric selection
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Jul 17, 2015
1 parent 8b17563 commit d268b6b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# TODO
* Multi-filters
* multi-metrics
2 changes: 1 addition & 1 deletion app/templates/panoramix/datasource.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ <h3>
<hr>
<form method="GET">
<div>{{ form.viz_type.label }}: {{ form.viz_type(class_="form-control select2") }}</div>
<div>{{ form.metric.label }}: {{ form.metric(class_="form-control select2") }}</div>
<div>{{ form.metrics.label }}: {{ form.metrics(class_="form-control select2") }}</div>
<div>{{ form.granularity.label }}: {{ form.granularity(class_="form-control select2_free_granularity") }}</div>
<div class="row">
<div class="form-group">
Expand Down
2 changes: 1 addition & 1 deletion app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class QueryForm(OmgWtForm):
viz_type = SelectField(
'Viz',
choices=[(k, v.verbose_name) for k, v in viz.viz_types.items()])
metric = SelectField('Metric', choices=datasource.metrics_combo)
metrics = SelectMultipleField('Metrics', choices=datasource.metrics_combo)
groupby = SelectMultipleField(
'Group by', choices=[
(s, s) for s in datasource.groupby_column_names])
Expand Down
31 changes: 14 additions & 17 deletions app/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def __init__(self, datasource, form_class, form_data, view):
self.datasource = datasource
self.form_class = form_class
self.form_data = form_data
self.metric = form_data.get('metric', 'count')
self.metrics = form_data.getlist('metrics') or ['count']
self.groupby = form_data.getlist('groupby') or []

self.df = self.bake_query()
self.view = view
if self.df is not None:
Expand Down Expand Up @@ -70,7 +72,7 @@ def query_obj(self):
granularity = utils.parse_human_timedelta(granularity).total_seconds() * 1000
aggregations = {
m.metric_name: m.json_obj
for m in ds.metrics if m.metric_name == self.metric
for m in ds.metrics if m.metric_name in self.metrics
}
limit = int(
args.get("limit", config.ROW_LIMIT)) or config.ROW_LIMIT
Expand All @@ -94,7 +96,7 @@ def query_obj(self):
"type": "default",
"limit": limit,
"columns": [{
"dimension": self.metric,
"dimension": self.metrics[0],
"direction": "descending",
}],
},
Expand Down Expand Up @@ -156,13 +158,12 @@ class TimeSeriesViz(HighchartsViz):
chart_kind = "line"

def render(self):
metric = self.metric
metrics = self.metrics
df = self.df
df = df.pivot_table(
index="timestamp",
columns=[
col for col in df.columns if col not in ["timestamp", metric]],
values=[metric])
columns=self.groupby,
values=metrics)

chart_js = serialize(
df, kind=self.chart_kind, stacked=self.stacked, **CHART_ARGS)
Expand Down Expand Up @@ -226,13 +227,11 @@ def query_obj(self):
return d

def render(self):
metric = self.metric
df = self.df
df = df.pivot_table(
index=[
col for col in df.columns if col not in ['timestamp', metric]],
values=[metric])
df = df.sort(metric, ascending=False)
index=self.groupby,
values=self.metrics)
df = df.sort(self.metrics[0], ascending=False)
chart_js = serialize(
df, kind=self.chart_kind, **CHART_ARGS)
return super(DistributionBarViz, self).render(chart_js=chart_js)
Expand All @@ -248,13 +247,11 @@ def query_obj(self):
return d

def render(self):
metric = self.metric
df = self.df
df = df.pivot_table(
index=[
col for col in df.columns if col not in ['timestamp', metric]],
values=[metric])
df = df.sort(metric, ascending=False)
index=self.groupby,
values=[self.metrics[0]])
df = df.sort(self.metrics[0], ascending=False)
chart_js = serialize(
df, kind=self.chart_kind, **CHART_ARGS)
return super(DistributionPieViz, self).render(chart_js=chart_js)
Expand Down

0 comments on commit d268b6b

Please sign in to comment.