Skip to content

Commit

Permalink
Checkpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Sep 15, 2015
1 parent 359a81e commit 521b000
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 27 deletions.
1 change: 0 additions & 1 deletion panoramix/highchart.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ def json(self):
.replace("\n", " ")
)


@property
def javascript_cmd(self):
js = self.json
Expand Down
16 changes: 13 additions & 3 deletions panoramix/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ class Slice(Model, AuditMixin):
__tablename__ = 'slices'
id = Column(Integer, primary_key=True)
slice_name = Column(String(250))
datasource_id = Column(Integer, ForeignKey('datasources.id'))
druid_datasource_id = Column(Integer, ForeignKey('datasources.id'))
table_id = Column(Integer, ForeignKey('tables.id'))
datasource_type = Column(String(200))
datasource_name = Column(String(2000))
viz_type = Column(String(250))
params = Column(Text)

table = relationship('Table', backref='slices')
druid_datasource = relationship('Datasource', backref='slices')
table = relationship(
'Table', foreign_keys=[table_id], backref='slices')
druid_datasource = relationship(
'Datasource', foreign_keys=[druid_datasource_id], backref='slices')

def __repr__(self):
return self.slice_name
Expand All @@ -50,6 +52,11 @@ def __repr__(self):
def datasource(self):
return self.table or self.druid_datasource

@property
def datasource_id(self):
datasource = self.datasource
return datasource.id if datasource else None

@property
def slice_link(self):
d = json.loads(self.params)
Expand All @@ -69,6 +76,9 @@ def css_files(self):
from panoramix.viz import viz_types
return viz_types[self.viz_type].css_files

def get_viz(self):
pass


dashboard_slices = Table('dashboard_slices', Model.metadata,
Column('id', Integer, primary_key=True),
Expand Down
4 changes: 2 additions & 2 deletions panoramix/templates/panoramix/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ <h5>{{ slice.slice_name }}</h5>
widget_base_dimensions: [150, 150],
resize: {enabled: true}
});
var url = "/panoramix/table/2/?flt_col_0=gender&datasource_id=2&flt_op_0=in&viz_type=pie&since=50%20years%20ago&until=now&metrics=total&limit=10&granularity=one%20day&datasource_name=baby_names&slice_name=Pie&where=&groupby=name&flt_eq_0=&datasource_type=table&standalone=true&skip_libs=true";
var url = "/panoramix/table/2/?flt_col_0=gender&rolling_periods=&datasource_id=2&flt_op_0=in&slice_name=Super%20Slice&viz_type=line&since=50%20years%20ago&groupby=name&metrics=total&limit=25&flt_eq_0=&granularity=one%20day&datasource_name=baby_names&where=&until=now&rolling_type=mean&datasource_type=table&skip_libs=true&standalone=true";
$.ajax({
url: url,
success: function(result){
$("#slice_content_2").html(result);
},
async: true,
});
var url = "/panoramix/table/2/?flt_col_0=gender&rolling_periods=&datasource_id=2&flt_op_0=in&slice_name=Super%20Slice&viz_type=line&since=50%20years%20ago&groupby=name&metrics=total&limit=25&flt_eq_0=&granularity=one%20day&datasource_name=baby_names&where=&until=now&rolling_type=mean&datasource_type=table&standalone=true&skip_libs=true";
var url = "/panoramix/table/2/?flt_col_0=gender&datasource_id=2&flt_op_0=in&viz_type=pie&since=50%20years%20ago&until=now&metrics=total&limit=10&granularity=one%20day&datasource_name=baby_names&slice_name=Pie&where=&groupby=name&flt_eq_0=&datasource_type=table&skip_libs=true&standalone=true";
$.ajax({
url: url,
success: function(result){
Expand Down
14 changes: 7 additions & 7 deletions panoramix/templates/panoramix/viz_highcharts.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{% macro viz_html(viz) %}
<div id="chart" style="height:100%; width:100%;">

<img src="{{ url_for("static", filename="loading.gif") }}" class="loading">
</div>
<div id="{{ viz.token }}" style="height:100%; width:100%;">
<img src="{{ url_for("static", filename="loading.gif") }}" class="loading">
</div>
{% endmacro %}

{% macro viz_js(viz) %}
Expand All @@ -24,10 +23,11 @@
console.log(url);
$.getJSON(url, function(data){
console.log(data);
new Highcharts.{{ viz.chart_call }}(data);
$("#{{ viz.token }}").highcharts('{{ viz.chart_call }}', data);
})
.fail(function() {
console.log( "error" );
.fail(function(xhr) {
var err = '<div class="alert alert-danger">' + xhr.responseText + '</div>';
$("#{{ viz.token }}").html(err);
});
});
</script>
Expand Down
8 changes: 4 additions & 4 deletions panoramix/templates/panoramix/viz_table.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</tbody>
</table>
{% else %}
<div id="unique" style="display: none;">
<div id="{{ viz.token }}" style="display: none;">
</div>
<img src="{{ url_for("static", filename="loading.gif") }}" class="loading">
{% endif %}
Expand All @@ -37,13 +37,13 @@
<script>
var url = window.location + '&async=true&standalone=true&skip_libs=true';
console.log(url);
$("#unique").load(url, function(){
$("#{{ viz.token }}").load(url, function(){
var table = $('table').DataTable({
paging: false,
});
})
$("#{{ viz.token }}").show();
table.column('-1').order( 'desc' ).draw();
$("img.loading").hide();
$("#unique").show();
});
</script>
{% endif %}
Expand Down
10 changes: 8 additions & 2 deletions panoramix/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,15 @@ def table(self, table_id):
table,
form_data=request.args, view=self)
if request.args.get("json") == "true":
try:
payload = obj.get_json()
status=200
except Exception as e:
payload = str(e)
status=500
return Response(
obj.get_json(),
#status=200,
payload,
status=status,
mimetype="application/json")
else:
return self.render_template("panoramix/viz.html", viz=obj)
Expand Down
19 changes: 11 additions & 8 deletions panoramix/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
import pandas as pd
from collections import OrderedDict
import config
import logging
import uuid
import numpy as np

from panoramix import utils
from panoramix.highchart import Highchart, HighchartBubble
from panoramix.forms import form_factory

CHART_ARGS = {
#'height': 700,
'title': None,
'target_div': 'chart',
}


Expand All @@ -28,6 +26,7 @@ class BaseViz(object):
css_files = []

def __init__(self, datasource, form_data, view):
self.token = form_data.get('token', 'token_' + uuid.uuid4().hex[:8])
self.datasource = datasource
self.view = view
self.form_data = form_data
Expand Down Expand Up @@ -97,7 +96,7 @@ def query_obj(self):
to_dttm = utils.parse_human_datetime(until)
if from_dttm >= to_dttm:
flash("The date range doesn't seem right.", "danger")
from_dttm = to_dttm # Making them identicial to not raise
from_dttm = to_dttm # Making them identical to not raise

# extras are used to query elements specific to a datasource type
# for instance the extra where clause that applies only to Tables
Expand Down Expand Up @@ -183,16 +182,20 @@ def query_obj(self):
raise Exception("Pick a metric for x, y and size")
return d

def render(self):
df = self.df.fillna(0)
def get_df(self):
df = super(BubbleViz, self).get_df()
df = df.fillna(0)
df['x'] = df[[self.x_metric]]
df['y'] = df[[self.y_metric]]
df['z'] = df[[self.z_metric]]
df['name'] = df[[self.entity]]
df['group'] = df[[self.series]]
return df

def get_json(self):
df = self.get_df()
chart = HighchartBubble(df)
self.chart_js = chart.javascript_cmd
return super(BubbleViz, self).render()
return chart.json


class TimeSeriesViz(HighchartsViz):
Expand Down

0 comments on commit 521b000

Please sign in to comment.