Skip to content

Commit

Permalink
Merge pull request #117 from mistercrunch/refact
Browse files Browse the repository at this point in the history
Doing some refactoring
  • Loading branch information
mistercrunch committed Jan 16, 2016
2 parents 8596390 + 085430c commit f1127a1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 46 deletions.
15 changes: 8 additions & 7 deletions panoramix/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def query(
"Datetime column not provided as part table configuration")
dttm_expr = cols[granularity].expression
if dttm_expr:
timestamp = ColumnClause(dttm_expr, is_literal=True).label('timestamp')
timestamp = literal_column(dttm_expr).label('timestamp')
else:
timestamp = literal_column(granularity).label('timestamp')
metrics_exprs = [
Expand All @@ -437,8 +437,8 @@ def query(
col = cols[s]
expr = col.expression
if expr:
outer = ColumnClause(expr, is_literal=True).label(s)
inner = ColumnClause(expr, is_literal=True).label('__' + s)
outer = literal_column(expr).label(s)
inner = literal_column(expr).label('__' + s)
else:
outer = column(s).label(s)
inner = column(s).label('__' + s)
Expand All @@ -462,15 +462,16 @@ def query(
if not columns:
qry = qry.group_by(*groupby_exprs)

tf = '%Y-%m-%d %H:%M:%S.%f'
time_filter = [
timestamp >= from_dttm.isoformat(),
timestamp <= to_dttm.isoformat(),
timestamp >= from_dttm.strftime(tf),
timestamp <= to_dttm.strftime(tf),
]
inner_time_filter = copy(time_filter)
if inner_from_dttm:
inner_time_filter[0] = timestamp >= inner_from_dttm.isoformat()
inner_time_filter[0] = timestamp >= inner_from_dttm.strftime(tf)
if inner_to_dttm:
inner_time_filter[1] = timestamp <= inner_to_dttm.isoformat()
inner_time_filter[1] = timestamp <= inner_to_dttm.strftime(tf)
where_clause_and = []
having_clause_and = []
for col, op, eq in filter:
Expand Down
25 changes: 24 additions & 1 deletion panoramix/static/panoramix.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@ var px = (function() {
var visualizations = {};
var dashboard = undefined;

function UTC(dttm){
return v = new Date(dttm.getUTCFullYear(), dttm.getUTCMonth(), dttm.getUTCDate(), dttm.getUTCHours(), dttm.getUTCMinutes(), dttm.getUTCSeconds());
}
var tickMultiFormat = d3.time.format.multi([
[".%L", function(d) { return d.getMilliseconds(); }], // If there are millisections, show only them
[":%S", function(d) { return d.getSeconds(); }], // If there are seconds, show only them
["%a %b %d, %I:%M %p", function(d) { return d.getMinutes()!=0; }], // If there are non-zero minutes, show Date, Hour:Minute [AM/PM]
["%a %b %d, %I %p", function(d) { return d.getHours() != 0; }], // If there are hours that are multiples of 3, show date and AM/PM
["%a %b %d, %Y", function(d) { return d.getDate() != 1; }], // If not the first of the month, do "month day, year."
["%B %Y", function(d) { return d.getMonth() != 0 && d.getDate() == 1; }], // If the first of the month, do "month day, year."
["%Y", function(d) { return true; }] // fall back on month, year
]);
function formatDate(dttm) {
var d = UTC(new Date(dttm));
//d = new Date(d.getTime() - 1 * 60 * 60 * 1000);
return tickMultiFormat(d);
}
colors = [
"#FF5A5F", "#007A87", "#7B0051", "#00D1C1", "#8CE071", "#FFB400",
"#FFAA91", "#B4A76C", "#9CA299", "#565A5C"
];

var Slice = function(data, dashboard){
var timer;
var token = $('#' + data.token);
Expand Down Expand Up @@ -119,7 +141,6 @@ var px = (function() {
addFilter: function(slice_id, filters) {
this.filters[slice_id] = filters;
this.refreshExcept(slice_id);
console.log(this.filters);
},
readFilters: function() {
// Returns a list of human readable active filters
Expand Down Expand Up @@ -424,5 +445,7 @@ var px = (function() {
druidify: druidify,
initExploreView: initExploreView,
initDashboardView: initDashboardView,
formatDate: formatDate,
colors: colors,
}
})();
3 changes: 2 additions & 1 deletion panoramix/static/widgets/viz_bignumber.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ px.registerViz('big_number', function(slice) {
var x_axis = d3.svg.axis()
.scale(scale_x)
.orient('bottom')
.ticks(4);
.ticks(4)
.tickFormat(px.formatDate);
g.call(x_axis);
g.attr('transform', 'translate(0,' + (height - margin) + ')');

Expand Down
31 changes: 5 additions & 26 deletions panoramix/static/widgets/viz_nvd3.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,6 @@ function viz_nvd3(slice) {
var chart = undefined;
var data = {};

function UTC(dttm){
return v = new Date(dttm.getUTCFullYear(), dttm.getUTCMonth(), dttm.getUTCDate(), dttm.getUTCHours(), dttm.getUTCMinutes(), dttm.getUTCSeconds());
}
var tickMultiFormat = d3.time.format.multi([
[".%L", function(d) { return d.getMilliseconds(); }], // If there are millisections, show only them
[":%S", function(d) { return d.getSeconds(); }], // If there are seconds, show only them
["%a %b %d, %I:%M %p", function(d) { return d.getMinutes()!=0; }], // If there are non-zero minutes, show Date, Hour:Minute [AM/PM]
["%a %b %d, %I %p", function(d) { return d.getHours() != 0; }], // If there are hours that are multiples of 3, show date and AM/PM
["%a %b %d, %Y", function(d) { return d.getDate() != 1; }], // If not the first of the month, do "month day, year."
["%B %Y", function(d) { return d.getMonth() != 0 && d.getDate() == 1; }], // If the first of the month, do "month day, year."
["%Y", function(d) { return true; }] // fall back on month, year
]);
function formatDate(dttm) {
var d = UTC(new Date(dttm));
//d = new Date(d.getTime() - 1 * 60 * 60 * 1000);
return tickMultiFormat(d);
}
colors = [
"#FF5A5F", "#007A87", "#7B0051", "#00D1C1", "#8CE071", "#FFB400",
"#FFAA91", "#B4A76C", "#9CA299", "#565A5C"
];
var refresh = function() {
$.getJSON(slice.jsonEndpoint(), function(payload) {
var fd = payload.form_data;
Expand All @@ -36,7 +15,7 @@ function viz_nvd3(slice) {
chart.lines2.xScale(d3.time.scale.utc());
chart.x2Axis
.showMaxMin(fd.x_axis_showminmax)
.tickFormat(formatDate)
.tickFormat(px.formatDate)
.staggerLabels(true);
} else {
chart = nv.models.lineChart()
Expand All @@ -47,7 +26,7 @@ function viz_nvd3(slice) {
chart.interpolate(fd.line_interpolation);
chart.xAxis
.showMaxMin(fd.x_axis_showminmax)
.tickFormat(formatDate)
.tickFormat(px.formatDate)
.staggerLabels(true);
chart.showLegend(fd.show_legend);
chart.yAxis.tickFormat(d3.format('.3s'));
Expand All @@ -66,7 +45,7 @@ function viz_nvd3(slice) {
.groupSpacing(0.1);
chart.xAxis
.showMaxMin(false)
.tickFormat(formatDate)
.tickFormat(px.formatDate)
.staggerLabels(true);
chart.showLegend(fd.show_legend);
chart.stacked(fd.bar_stacked);
Expand Down Expand Up @@ -104,7 +83,7 @@ function viz_nvd3(slice) {
chart.xScale(d3.time.scale.utc());
chart.xAxis
.showMaxMin(false)
.tickFormat(formatDate)
.tickFormat(px.formatDate)
.staggerLabels(true);
chart.showLegend(fd.show_legend);
chart.yAxis.tickFormat(d3.format('.3p'));
Expand Down Expand Up @@ -137,7 +116,7 @@ function viz_nvd3(slice) {
chart.xScale(d3.time.scale.utc());
chart.xAxis
.showMaxMin(false)
.tickFormat(formatDate)
.tickFormat(px.formatDate)
.staggerLabels(true);
chart.showLegend(fd.show_legend);
chart.yAxis.tickFormat(d3.format('.3s'));
Expand Down
1 change: 1 addition & 0 deletions panoramix/templates/panoramix/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{% endblock %}

{% block tail_js %}
<script src="/static/lib/d3.min.js"></script>
<script src="/static/panoramix.js"></script>
<script src="/static/lib/jquery-ui/jquery-ui.min.js"></script>
<script src="/static/lib/select2.sortable.js"></script>
Expand Down
13 changes: 2 additions & 11 deletions panoramix/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ class TableViz(BaseViz):
]
is_timeseries = False
js_files = [
'lib/d3.min.js',
'lib/dataTables/jquery.dataTables.min.js',
'lib/dataTables/dataTables.bootstrap.js',
'widgets/viz_table.js',
Expand Down Expand Up @@ -437,7 +436,6 @@ class WordCloudViz(BaseViz):
)
},)
js_files = [
'lib/d3.min.js',
'lib/d3.layout.cloud.js',
'widgets/viz_wordcloud.js',
]
Expand All @@ -463,7 +461,6 @@ class NVD3Viz(BaseViz):
verbose_name = "Base NVD3 Viz"
is_timeseries = False
js_files = [
'lib/d3.min.js',
'lib/nvd3/nv.d3.min.js',
'widgets/viz_nvd3.js',
]
Expand Down Expand Up @@ -547,7 +544,6 @@ class BigNumberViz(BaseViz):
verbose_name = "Big Number"
is_timeseries = True
js_files = [
'lib/d3.min.js',
'widgets/viz_bignumber.js',
]
css_files = [
Expand All @@ -562,6 +558,7 @@ class BigNumberViz(BaseViz):
'metric',
'compare_lag',
'compare_suffix',
'y_axis_format',
)
},)

Expand All @@ -584,15 +581,14 @@ def get_json_data(self):
form_data = self.form_data
df = self.get_df()
df = df.sort(columns=df.columns[0])
df['timestamp'] = df[[0]].astype(np.int64) // 10**9
compare_lag = form_data.get("compare_lag", "")
compare_lag = int(compare_lag) if compare_lag and compare_lag.isdigit() else 0
d = {
'data': df.values.tolist(),
'compare_lag': compare_lag,
'compare_suffix': form_data.get('compare_suffix', ''),
}
return json.dumps(d)
return dumps(d)


class NVD3TimeSeriesViz(NVD3Viz):
Expand Down Expand Up @@ -865,7 +861,6 @@ class SunburstViz(BaseViz):
verbose_name = "Sunburst"
is_timeseries = False
js_files = [
'lib/d3.min.js',
'widgets/viz_sunburst.js']
css_files = ['widgets/viz_sunburst.css']
fieldsets = (
Expand Down Expand Up @@ -931,7 +926,6 @@ class SankeyViz(BaseViz):
verbose_name = "Sankey"
is_timeseries = False
js_files = [
'lib/d3.min.js',
'lib/d3-sankey.js',
'widgets/viz_sankey.js']
css_files = ['widgets/viz_sankey.css']
Expand Down Expand Up @@ -973,7 +967,6 @@ class DirectedForceViz(BaseViz):
verbose_name = "Directed Force Layout"
is_timeseries = False
js_files = [
'lib/d3.min.js',
'widgets/viz_directed_force.js']
css_files = ['widgets/viz_directed_force.css']
fieldsets = (
Expand Down Expand Up @@ -1019,7 +1012,6 @@ class WorldMapViz(BaseViz):
verbose_name = "World Map"
is_timeseries = False
js_files = [
'lib/d3.min.js',
'lib/topojson.min.js',
'lib/datamaps.all.js',
'widgets/viz_world_map.js']
Expand Down Expand Up @@ -1098,7 +1090,6 @@ class FilterBoxViz(BaseViz):
verbose_name = "Filters"
is_timeseries = False
js_files = [
'lib/d3.min.js',
'widgets/viz_filter_box.js']
css_files = [
'widgets/viz_filter_box.css']
Expand Down

0 comments on commit f1127a1

Please sign in to comment.