Skip to content

Tile format for histograms #229

@stuartlynn

Description

@stuartlynn

Currently I am using the SQL to do requests for Histogram tiles. The code can be seen here: It builds up a series of arrays of the histogram data and bins and then concatenates these together in the response. The SQL it generates looks like

WITH cte as( 
  select * from stuartlynn.mapsense 
  WHERE stuartlynn.mapsense.the_geom_webmercator && CDB_XYZ_Extent(6,4, 3) ),

cat_id_hist as ( 
  select array_agg(b.bins) as bins, array_agg(b.vals) as vals 
  from (
     select cte.cat_id as bins, count(*) vals 
     from cte group by cat_id
  ) as b), 

requests_hist as( 
    select array_agg(b.bins) as bins, array_agg(b.vals) as vals 
    from(
      select width_bucket(requests,0,20,20) bins ,count(*) vals 
      from cte  group by 1 order by 1
    ) as b)

select cat_id_hist.bins as cat_id_bins, cat_id_hist.vals as cat_id_vals,requests_hist.bins as requests_bins, requests_hist.vals as requests_vals
 from cat_id_hist, requests_hist

Where cat_id is for a category request and requests is for a histogram of a numerical variable. This is an example of the response from the query:

https://gist.github.com/stuartlynn/76e41e9c07ab01d92ee2

It returns a row with two arrays for each variable, one for the bins and the other for the values. In a json response though we probably want to have these formatted as something like:

{
  "mappings":{
      "cat_id":{
         "ids": [1, 33, 4],
         "labels": ["car", "bus", "van"]
      }
  },
  "requests":{
     "bins": [1,2,4],
     "values": [22, 33.3, 44.2] 
  },
  "cat_id":{
    "bins":[1,33,4],
    "values": [4,8, 23]
  }
}

Where the mappings relate the category values to their labels.

@javisantana

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions