Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed caravel/assets/images/tutorial/add_db.png
Binary file not shown.
Binary file removed caravel/assets/images/viz_thumbnails/bar.png
Binary file not shown.
Binary file removed caravel/assets/images/viz_thumbnails/big_number.png
Binary file not shown.
Binary file removed caravel/assets/images/viz_thumbnails/bubble.png
Binary file not shown.
Binary file removed caravel/assets/images/viz_thumbnails/filter.png
Binary file not shown.
Binary file not shown.
Binary file removed caravel/assets/images/viz_thumbnails/line.png
Binary file not shown.
Binary file not shown.
Binary file removed caravel/assets/images/viz_thumbnails/pie.png
Binary file not shown.
Binary file not shown.
Binary file removed caravel/assets/images/viz_thumbnails/sankey.png
Binary file not shown.
Binary file removed caravel/assets/images/viz_thumbnails/stacked.png
Binary file not shown.
Binary file removed caravel/assets/images/viz_thumbnails/sunburst.png
Binary file not shown.
Binary file removed caravel/assets/images/viz_thumbnails/table.png
Binary file not shown.
Binary file removed caravel/assets/images/viz_thumbnails/word_cloud.png
Binary file not shown.
6 changes: 5 additions & 1 deletion caravel/assets/javascripts/modules/caravel.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,13 @@ var px = (function () {
$('.query-and-save button').removeAttr('disabled');
always(data);
},
error: function (msg) {
error: function (error) {
var msg = error.responseText;
token.find("img.loading").hide();
var err = '<div class="alert alert-danger">' + msg + '</div>';
if (error.getResponseHeader("Caravel-Exception") === "NoResultsException") {
err = '<div class="alert-nodata">' + msg + '</div>';
}
container.html(err);
container.show();
$('span.query').removeClass('disabled');
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/big_number.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function bigNumberVis(slice) {
d3.json(slice.jsonEndpoint(), function (error, payload) {
//Define the percentage bounds that define color from red to green
if (error !== null) {
slice.error(error.responseText);
slice.error(error);
return '';
}
var fd = payload.form_data;
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/directed_force.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function directedForceVis(slice) {
d3.json(slice.jsonEndpoint(), function (error, json) {

if (error !== null) {
slice.error(error.responseText);
slice.error(error);
return '';
}
var links = json.data;
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/heatmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function heatmapVis(slice) {
d3.json(slice.jsonEndpoint(), function (error, payload) {
var matrix = {};
if (error) {
slice.error(error.responseText);
slice.error(error);
return '';
}
var fd = payload.form_data;
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/sankey.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function sankeyVis(slice) {

d3.json(slice.jsonEndpoint(), function (error, json) {
if (error !== null) {
slice.error(error.responseText);
slice.error(error);
return '';
}
var links = json.data;
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/sunburst.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function sunburstVis(slice) {

d3.json(slice.jsonEndpoint(), function (error, rawData) {
if (error !== null) {
slice.error(error.responseText);
slice.error(error);
return '';
}

Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/word_cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function wordCloudChart(slice) {
function refresh() {
d3.json(slice.jsonEndpoint(), function (error, json) {
if (error !== null) {
slice.error(error.responseText);
slice.error(error);
return '';
}
var data = json.data;
Expand Down
2 changes: 1 addition & 1 deletion caravel/assets/visualizations/world_map.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function worldMapChart(slice) {
var fd = json.form_data;

if (error !== null) {
slice.error(error.responseText);
slice.error(error);
return '';
}
var ext = d3.extent(json.data, function (d) {
Expand Down
15 changes: 14 additions & 1 deletion caravel/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,20 @@ def query( # sqla
select_exprs += [timestamp_grain]
groupby_exprs += [timestamp_grain]

tf = '%Y-%m-%d %H:%M:%S.%f'
# UGLY: I guess correct way is to delegate on SQLAlchemy dialect
# UPDATE: Datetime depends on each dialect and I haven't found an easy way to manage
# Maybe we can allow user to define its custome format at Database definition
def get_dtformat(type):
if type == 'SMALLDATETIME' or type == 'DATETIME':
return '%Y-%m-%d %H:%M:%S'
if type == 'DATE':
return '%Y-%m-%d'
if type == 'TIME':
return '%H:%M:%S'
return '%Y-%m-%d %H:%M:%S.%f'

tf = get_dtformat(cols[granularity].type or 'DATE')

time_filter = [
timestamp >= from_dttm.strftime(tf),
timestamp <= to_dttm.strftime(tf),
Expand Down
4 changes: 4 additions & 0 deletions caravel/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,7 @@ def readfile(filepath):
with open(filepath) as f:
content = f.read()
return content


class NoResultsException(Exception):
pass
23 changes: 15 additions & 8 deletions caravel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from wtforms.validators import ValidationError

from caravel import appbuilder, db, models, viz, utils, app, sm, ascii_art
from caravel.utils import NoResultsException

config = app.config
log_this = models.Log.log_this
Expand All @@ -40,12 +41,12 @@ def validate_json(form, field): # noqa
raise ValidationError("json isn't valid")


def generate_download_headers(extension):
def generate_download_headers(extension, headers=None):
filename = datetime.now().strftime("%Y%m%d_%H%M%S")
content_disp = "attachment; filename={}.{}".format(filename, extension)
headers = {
"Content-Disposition": content_disp,
}
if headers is None:
headers = {}
headers["Content-Disposition"] = content_disp
return headers


Expand Down Expand Up @@ -481,18 +482,24 @@ def explore(self, datasource_type, datasource_id):
slice=slc)
if request.args.get("json") == "true":
status = 200
headers = {}
try:
payload = obj.get_json()
except Exception as e:
t = type(e)
headers["Caravel-Exception"] = t.__name__
logging.exception(e)
if config.get("DEBUG"):
raise e
payload = str(e)
if t is NoResultsException:
payload = "No results"
else:
if config.get("DEBUG"):
raise e
payload = str(e)
status = 500
resp = Response(
payload,
status=status,
headers=generate_download_headers("json"),
headers=generate_download_headers("json", headers),
mimetype="application/json")
return resp
elif request.args.get("csv") == "true":
Expand Down
9 changes: 7 additions & 2 deletions caravel/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
from caravel import app, utils, cache
from caravel.forms import FormFactory


from caravel.utils import NoResultsException

config = app.config


Expand Down Expand Up @@ -139,8 +142,10 @@ def get_df(self, query_obj=None):
self.results = self.datasource.query(**query_obj)
self.query = self.results.query
df = self.results.df
if df is None or df.empty:
raise Exception("No data, review your incantations!")
if df is None:
raise Exception("Error retrieving data")
elif df.empty:
raise NoResultsException()
else:
if 'timestamp' in df.columns:
df.timestamp = pd.to_datetime(df.timestamp, utc=False)
Expand Down
45 changes: 0 additions & 45 deletions docs/gallery.rst

This file was deleted.

6 changes: 5 additions & 1 deletion tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import unittest

import sys
from flask import escape

import caravel
Expand Down Expand Up @@ -58,7 +59,10 @@ def test_slices(self):
slc.viz.json_endpoint,
]
for url in urls:
self.client.get(url)
try:
self.client.get(url)
except Exception:
raise ValueError(url, None, sys.exc_info()[2])

def test_csv(self):
self.client.get('/caravel/explore/table/1/?viz_type=table&granularity=ds&since=100+years&until=now&metrics=count&groupby=name&limit=50&show_brush=y&show_brush=false&show_legend=y&show_brush=false&rich_tooltip=y&show_brush=false&show_brush=false&show_brush=false&show_brush=false&y_axis_format=&x_axis_showminmax=y&show_brush=false&line_interpolation=linear&rolling_type=None&rolling_periods=&time_compare=&num_period_compare=&where=&having=&flt_col_0=gender&flt_op_0=in&flt_eq_0=&flt_col_0=gender&flt_op_0=in&flt_eq_0=&slice_id=14&slice_name=Boys&collapsed_fieldsets=&action=&datasource_name=birth_names&datasource_id=1&datasource_type=table&previous_viz_type=line&csv=true')
Expand Down