Fixes start and end timestamps to show a valid date

This commit is contained in:
Javier Arce 2013-11-08 16:14:12 +01:00
parent b627d93efa
commit c57472da78

View File

@ -264,8 +264,8 @@
getKeySpan: function() { getKeySpan: function() {
return { return {
start: this.options.start, start: this.options.start * 1000,
end: this.options.end, end: this.options.end * 1000,
step: this.options.step, step: this.options.step,
steps: this.options.steps steps: this.options.steps
}; };
@ -316,7 +316,7 @@
_fetchKeySpan: function() { _fetchKeySpan: function() {
var self = this; var self = this;
var max_col, min_col, max_tmpl, min_tmpl; var max_col, min_col, max_tmpl, min_tmpl;
var query = format("with s as (select EXTRACT(EPOCH FROM max(updated_at)) as max FROM CDB_TableMetadata m WHERE m.tabname::name = any ( CDB_QueryTables('{sql}'))) select {column}, s.max as last_updated " + var query = format("with s as (select EXTRACT(EPOCH FROM max(updated_at)) as max FROM CDB_TableMetadata m WHERE m.tabname::name = any ( CDB_QueryTables('{sql}'))) select {column}, s.max as last_updated " +
"from s, ({sql}) __torque_wrap_sql limit 1", { "from s, ({sql}) __torque_wrap_sql limit 1", {
column: this.options.column, column: this.options.column,
sql: self.getSQL() sql: self.getSQL()
@ -342,17 +342,17 @@
min_col = format(min_tmpl, { column: self.options.column }); min_col = format(min_tmpl, { column: self.options.column });
/*var sql_stats = "" + /*var sql_stats = "" +
"WITH summary_groups as ( " + "WITH summary_groups as ( " +
"WITH summary as ( " + "WITH summary as ( " +
"select (row_number() over (order by __time_col asc nulls last)+1)/2 as rownum, __time_col " + "select (row_number() over (order by __time_col asc nulls last)+1)/2 as rownum, __time_col " +
"from (select *, {column} as __time_col from ({sql}) __s) __torque_wrap_sql " + "from (select *, {column} as __time_col from ({sql}) __s) __torque_wrap_sql " +
"order by __time_col asc " + "order by __time_col asc " +
") " + ") " +
"SELECT " + "SELECT " +
"max(__time_col) OVER(PARTITION BY rownum) - " + "max(__time_col) OVER(PARTITION BY rownum) - " +
"min(__time_col) OVER(PARTITION BY rownum) diff " + "min(__time_col) OVER(PARTITION BY rownum) diff " +
"FROM summary " + "FROM summary " +
"), subq as ( " + "), subq as ( " +
" SELECT " + " SELECT " +
"st_xmax(st_envelope(st_collect(the_geom))) xmax, " + "st_xmax(st_envelope(st_collect(the_geom))) xmax, " +
"st_ymax(st_envelope(st_collect(the_geom))) ymax, " + "st_ymax(st_envelope(st_collect(the_geom))) ymax, " +
@ -361,11 +361,11 @@
"{max_col} max, " + "{max_col} max, " +
"{min_col} min FROM ({sql}) __torque_wrap_sql " + "{min_col} min FROM ({sql}) __torque_wrap_sql " +
")" + ")" +
"SELECT " + "SELECT " +
"xmax, xmin, ymax, ymin, a.max as max_date, a.min as min_date, " + "xmax, xmin, ymax, ymin, a.max as max_date, a.min as min_date, " +
"avg(diff) as diffavg," + "avg(diff) as diffavg," +
"(a.max - a.min)/avg(diff) as num_steps " + "(a.max - a.min)/avg(diff) as num_steps " +
"FROM summary_groups, subq a " + "FROM summary_groups, subq a " +
"WHERE diff > 0 group by xmax, xmin, ymax, ymin, max_date, min_date"; "WHERE diff > 0 group by xmax, xmin, ymax, ymin, max_date, min_date";
*/ */
var sql_stats = " SELECT " + var sql_stats = " SELECT " +
@ -393,9 +393,9 @@
self.options.data_steps = data.num_steps >> 0; self.options.data_steps = data.num_steps >> 0;
// step can't be 0 // step can't be 0
self.options.step = self.options.step || 1; self.options.step = self.options.step || 1;
self.options.bounds = [ self.options.bounds = [
[data.ymin, data.xmin], [data.ymin, data.xmin],
[data.ymax, data.xmax] [data.ymax, data.xmax]
]; ];
self._setReady(true); self._setReady(true);
}, { parseJSON: true }); }, { parseJSON: true });