From 827c5af4ed3dfb3d7de94a537d363fbc3aac13c4 Mon Sep 17 00:00:00 2001 From: Matias Saguir Date: Tue, 15 Jan 2013 18:45:43 -0300 Subject: [PATCH] Fix bug fot not cummulative expires examples --- src/grid_layer.js | 45 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/grid_layer.js b/src/grid_layer.js index 1e6f48e..1f99ee4 100644 --- a/src/grid_layer.js +++ b/src/grid_layer.js @@ -156,8 +156,35 @@ TimePlayer.prototype.get_time_data = function (tile, coord, zoom) { // se contains the deforestation for each entry in sd // take se and sd as a matrix [se|sd] var numTiles = 1 << zoom; - - var sql = "WITH hgrid AS ( " + + var sql = "" + 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( " + " CDB_XYZ_Extent({0}, {1}, {2}), ".format(coord.x, coord.y, zoom) + " CDB_XYZ_Resolution({0}) * {1}, ".format(zoom, this.resolution) + @@ -165,23 +192,19 @@ TimePlayer.prototype.get_time_data = function (tile, coord, zoom) { " ) as cell " + " ) " + " 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 ( " + " 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) + + " round(CAST (st_xmax(hgrid.cell) AS numeric),4) x, 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) + " 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) + + " hgrid.cell, floor((date_part('epoch',{0})- {1})/{2})".format(this.t_column, this.MIN_DATE, this.step) + " ) f GROUP BY x, y"; + } var prof = Profiler.get('tile fetch'); prof.start();