Fix bug fot not cummulative expires examples

This commit is contained in:
Matias Saguir 2013-01-15 18:45:43 -03:00
parent 224172d693
commit 827c5af4ed

View File

@ -156,8 +156,35 @@ TimePlayer.prototype.get_time_data = function (tile, coord, zoom) {
// se contains the deforestation for each entry in sd // se contains the deforestation for each entry in sd
// take se and sd as a matrix [se|sd] // take se and sd as a matrix [se|sd]
var numTiles = 1 << zoom; var numTiles = 1 << zoom;
var sql = ""
var sql = "WITH hgrid AS ( " + if ( this.options.cumulative_expires == true) {
sql = "WITH hgrid AS ( " +
" SELECT CDB_RectangleGrid( " +
" CDB_XYZ_Extent({0}, {1}, {2}), ".format(coord.x, coord.y, zoom) +
" CDB_XYZ_Resolution({0}) * {1}, ".format(zoom, this.resolution) +
" CDB_XYZ_Resolution({0}) * {1} ".format(zoom, this.resolution) +
" ) as cell " +
" ) " +
" SELECT " +
" x, y, array_agg(c) vals, array_agg(d) dates , array_agg(de) dates_end" +
" FROM ( " +
" SELECT " +
" round(CAST (st_xmax(hgrid.cell) AS numeric),4) x, " +
" round(CAST (st_ymax(hgrid.cell) AS numeric),4) y, " +
" {0} c, ".format(this.countby) +
" floor((date_part('epoch',{0})- {1})/{2}) d, ".format(this.t_column, this.MIN_DATE, this.step) +
" floor((date_part('epoch',{0})- {1})/{2}) de ".format(this.options.expiration_column, this.MIN_DATE, this.step) +
" FROM " +
" hgrid, {0} i ".format(this.table) +
" WHERE " +
" ST_Intersects(i.the_geom_webmercator, hgrid.cell) " +
" GROUP BY " +
" hgrid.cell, " +
" floor((date_part('epoch',{0})- {1})/{2}), ".format(this.t_column, this.MIN_DATE, this.step) +
" floor((date_part('epoch',{0})- {1})/{2})".format(this.options.expiration_column, this.MIN_DATE, this.step) +
" ) f GROUP BY x, y";
} else {
sql = "WITH hgrid AS ( " +
" SELECT CDB_RectangleGrid( " + " SELECT CDB_RectangleGrid( " +
" CDB_XYZ_Extent({0}, {1}, {2}), ".format(coord.x, coord.y, zoom) + " CDB_XYZ_Extent({0}, {1}, {2}), ".format(coord.x, coord.y, zoom) +
" CDB_XYZ_Resolution({0}) * {1}, ".format(zoom, this.resolution) + " CDB_XYZ_Resolution({0}) * {1}, ".format(zoom, this.resolution) +
@ -165,23 +192,19 @@ TimePlayer.prototype.get_time_data = function (tile, coord, zoom) {
" ) as cell " + " ) as cell " +
" ) " + " ) " +
" SELECT " + " SELECT " +
" x, y, array_agg(c) vals, array_agg(d) dates , array_agg(de) dates_end" + " x, y, array_agg(c) vals, array_agg(d) dates " +
" FROM ( " + " FROM ( " +
" SELECT " + " SELECT " +
" round(CAST (st_xmax(hgrid.cell) AS numeric),4) x, " + " round(CAST (st_xmax(hgrid.cell) AS numeric),4) x, round(CAST (st_ymax(hgrid.cell) AS numeric),4) y, " +
" round(CAST (st_ymax(hgrid.cell) AS numeric),4) y, " + " {0} c, floor((date_part('epoch',{1})- {2})/{3}) d ".format(this.countby, this.t_column, this.MIN_DATE, this.step) +
" {0} c, ".format(this.countby) +
" floor((date_part('epoch',{0})- {1})/{2}) d, ".format(this.t_column, this.MIN_DATE, this.step) +
" floor((date_part('epoch',{0})- {1})/{2}) de ".format(this.options.expiration_column, this.MIN_DATE, this.step) +
" FROM " + " FROM " +
" hgrid, {0} i ".format(this.table) + " hgrid, {0} i ".format(this.table) +
" WHERE " + " WHERE " +
" ST_Intersects(i.the_geom_webmercator, hgrid.cell) " + " ST_Intersects(i.the_geom_webmercator, hgrid.cell) " +
" GROUP BY " + " GROUP BY " +
" hgrid.cell, " + " hgrid.cell, floor((date_part('epoch',{0})- {1})/{2})".format(this.t_column, this.MIN_DATE, this.step) +
" floor((date_part('epoch',{0})- {1})/{2}), ".format(this.t_column, this.MIN_DATE, this.step) +
" floor((date_part('epoch',{0})- {1})/{2})".format(this.options.expiration_column, this.MIN_DATE, this.step) +
" ) f GROUP BY x, y"; " ) f GROUP BY x, y";
}
var prof = Profiler.get('tile fetch'); var prof = Profiler.get('tile fetch');
prof.start(); prof.start();