Checkpoint

This commit is contained in:
Maxime Beauchemin 2015-09-15 12:33:26 -07:00
parent 359a81eee3
commit 521b000ab6
7 changed files with 45 additions and 27 deletions

View File

@ -16,7 +16,6 @@ class BaseHighchart(object):
.replace("\n", " ")
)
@property
def javascript_cmd(self):
js = self.json

View File

@ -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
@ -50,6 +52,11 @@ class Slice(Model, AuditMixin):
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)
@ -69,6 +76,9 @@ class Slice(Model, AuditMixin):
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),

View File

@ -73,7 +73,7 @@ $( document ).ready(function() {
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){
@ -81,7 +81,7 @@ $( document ).ready(function() {
},
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){

View File

@ -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) %}
@ -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>

View File

@ -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 %}
@ -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 %}

View File

@ -220,9 +220,15 @@ class Panoramix(BaseView):
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)

View File

@ -3,7 +3,7 @@ from flask import flash, request
import pandas as pd
from collections import OrderedDict
import config
import logging
import uuid
import numpy as np
from panoramix import utils
@ -11,9 +11,7 @@ from panoramix.highchart import Highchart, HighchartBubble
from panoramix.forms import form_factory
CHART_ARGS = {
#'height': 700,
'title': None,
'target_div': 'chart',
}
@ -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
@ -97,7 +96,7 @@ class BaseViz(object):
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
@ -183,16 +182,20 @@ class BubbleViz(HighchartsViz):
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):