Skip to content

Commit

Permalink
Table view now shows metrics histograms
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Aug 19, 2015
1 parent 584ced5 commit 4ecf9d1
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
24 changes: 23 additions & 1 deletion app/templates/panoramix/viz_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,29 @@
{% endblock %}

{% block viz %}
{{ table|safe }}
{{ super() }}
<table class="dataframe table table-striped table-bordered table-condensed">
<thead>
<tr>
{% for col in df.columns if not col.endswith('__perc') %}
<th>{{ col }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for row in df.to_dict(orient="records") %}
<tr>
{% for col in df.columns if not col.endswith('__perc') %}
{% if col + '__perc' in df.columns %}
<td style="background-image: linear-gradient(to right, lightgrey, lightgrey {{ row[col+'__perc'] }}%, rgba(0,0,0,0) {{ row[col+'__perc'] }}%">{{ row[col] }}</td>
{% else %}
<td>{{ row[col] }}</td>
{% endif %}
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% endblock %}

{% block extra_fields %}
Expand Down
15 changes: 8 additions & 7 deletions app/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,22 @@ def render(self, *args, **kwargs):
class TableViz(BaseViz):
verbose_name = "Table View"
template = 'panoramix/viz_table.html'

def render(self):
if self.error_msg:
return super(TableViz, self).render(error_msg=self.error_msg)

df = self.df
row_limit = request.args.get("row_limit")
if df is None or df.empty:
flash("No data.", "error")
table = None
else:
if self.form_data.get("granularity") == "all" and 'timestamp' in df:
del df['timestamp']
table = df.to_html(
classes=[
'table', 'table-striped', 'table-bordered',
'table-condensed'],
index=False)
return super(TableViz, self).render(table=table)
for m in self.metrics:
import numpy as np
df[m + '__perc'] = np.rint((df[m] / np.max(df[m])) * 100)
return super(TableViz, self).render(df=df)

def form_class(self):
limits = [10, 50, 100, 500, 1000, 5000, 10000]
Expand Down

0 comments on commit 4ecf9d1

Please sign in to comment.