Skip to content

Commit

Permalink
Period ratio compare
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Sep 28, 2015
1 parent 7143972 commit 625bd9d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 4 deletions.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ List of TODO items for Panoramix
* Contribution to total (added to line chart already)
* Time comparison
* Time ratios
* Use legend shapes that match line markers (useful?)
* Line types (dash, dotted)

## New Features
Expand Down
7 changes: 6 additions & 1 deletion panoramix/forms.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from wtforms import (
Field, Form, SelectMultipleField, SelectField, TextField, TextAreaField,
BooleanField)
BooleanField, IntegerField)
from copy import copy


Expand Down Expand Up @@ -138,6 +138,11 @@ def form_factory(viz):
'contribution': BooleanField(
"Contribution", default=False,
description="Compute the contribution to the total"),
'num_period_compare': IntegerField(
"Period Ratio", default=None,
description=(
"Number of period to compare against, "
"this is relative to the granularity selected")),
}
field_css_classes = {k: ['form-control'] for k in px_form_fields.keys()}
select2 = [
Expand Down
13 changes: 12 additions & 1 deletion panoramix/templates/panoramix/datasource.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@
img.loading {
width: 30px;
}
.row {
margin-right: -5px;
margin-left: -5px;
}
.col-sm-1, .col-md-1, .col-lg-1, .col-xs-2, .col-sm-2, .col-md-2, .col-lg-2, .col-xs-3, .col-sm-3, .col-md-3, .col-lg-3, .col-xs-4, .col-sm-4, .col-md-4, .col-lg-4, .col-xs-5, .col-sm-5, .col-md-5, .col-lg-5, .col-xs-6, .col-sm-6, .col-md-6, .col-lg-6, .col-xs-7, .col-sm-7, .col-md-7, .col-lg-7, .col-xs-8, .col-sm-8, .col-md-8, .col-lg-8, .col-xs-9, .col-sm-9, .col-md-9, .col-lg-9, .col-xs-10, .col-sm-10, .col-md-10, .col-lg-10, .col-xs-11, .col-sm-11, .col-md-11, .col-lg-11, .col-xs-12, .col-sm-12, .col-md-12, .col-lg-12 {
position: relative;
min-height: 1px;
padding-right: 5px;
padding-left: 5px;
}


</style>
{% endblock %}
Expand Down Expand Up @@ -167,7 +178,7 @@ <h4 class="modal-title" id="myModalLabel">Query</h4>

$(".select2").select2();
$("form").slideDown("slow");
$('[data-toggle="tooltip"]').tooltip();
$('[data-toggle="tooltip"]').tooltip({container: 'body'});

function set_filters(){
for (var i=1; i<10; i++){
Expand Down
3 changes: 2 additions & 1 deletion panoramix/templates/panoramix/viz_nvd3.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@
.tickFormat(function (d) {return tickMultiFormat(new Date(d)); });
chart.showLegend({{ "{}".format(viz.args.show_legend=='y')|lower }});
chart.yAxis.tickFormat(d3.format('.3s'));
{% if viz.args.contribution=='y' %}
{% if viz.args.contribution=='y' or viz.args.get("num_period_compare") %}
chart.yAxis.tickFormat(d3.format('.3p'));
chart.y2Axis.tickFormat(d3.format('.3p'));
{% endif %}

{% elif viz.chart_type == 'nvd3_bar' %}
Expand Down
7 changes: 7 additions & 0 deletions panoramix/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ class NVD3TimeSeriesViz(NVD3Viz):
'metrics',
'groupby', 'limit',
('rolling_type', 'rolling_periods'),
('num_period_compare', None),
('show_brush', 'show_legend'),
('rich_tooltip', 'y_axis_zero'),
('y_log_scale', 'contribution')
Expand All @@ -346,6 +347,12 @@ def get_df(self):
dft = df.T
df = (dft / dft.sum()).T

num_period_compare = self.form_data.get("num_period_compare")
if num_period_compare:
num_period_compare = int(num_period_compare)
df = df / df.shift(num_period_compare)
df = df[num_period_compare:]

rolling_periods = args.get("rolling_periods")
rolling_type = args.get("rolling_type")
if rolling_periods and rolling_type:
Expand Down

0 comments on commit 625bd9d

Please sign in to comment.