Skip to content

Commit

Permalink
Add Filter rank analysis
Browse files Browse the repository at this point in the history
Closes #75
  • Loading branch information
rochoa committed Jun 23, 2016
1 parent 872be44 commit 0ffd7ad
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 0.20.1

Released 2016-mm-dd
- Add Filter rank analysis #75.
- Generate cartodb_id in weighted-centroid analysis #72.
- Add Convex hull analysis #76.

Expand Down
24 changes: 24 additions & 0 deletions examples/viewer/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -1334,6 +1334,30 @@ var examples = {
center: [40.44, -3.7],
zoom: 12
},
filter_rank: {
name: 'populated places filter rank',
def: {
id: UUID,
type: 'filter-rank',
params: {
source: {
id: 'a0',
type: 'source',
params: {
query: 'select * from populated_places_simple'
}
},
column: 'pop_max',
rank: 'top',
limit: 100
}
},
dataviews: {},
filters: {},
cartocss: CARTOCSS_POINTS,
center: [40.44, -3.7],
zoom: 3
},
filterByNodeColumn: {
name: 'filter by node column',
def: {
Expand Down
1 change: 1 addition & 0 deletions lib/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var nodes = {
FilterByNodeColumn: require('./nodes/filter-by-node-column'),
FilterCategory: require('./nodes/filter-category'),
FilterRange: require('./nodes/filter-range'),
FilterRank: require('./nodes/filter-rank'),
GeoreferenceAdminRegion: require('./nodes/georeference-admin-region'),
GeoreferenceCity: require('./nodes/georeference-city'),
GeoreferenceIpAddress: require('./nodes/georeference-ip-address'),
Expand Down
35 changes: 35 additions & 0 deletions lib/node/nodes/filter-rank.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

var Node = require('../node');

var TYPE = 'filter-rank';
var PARAMS = {
source: Node.PARAM.NODE(Node.GEOMETRY.ANY),
column: Node.PARAM.STRING(),
rank: Node.PARAM.ENUM('top', 'bottom'),
limit: Node.PARAM.NUMBER(),
action: Node.PARAM.NULLABLE(Node.PARAM.ENUM('show', 'hide'), 'show')
};

var FilterRank = Node.create(TYPE, PARAMS, { cache: true });

module.exports = FilterRank;
module.exports.TYPE = TYPE;
module.exports.PARAMS = PARAMS;

var filterRankTemplate = Node.template([
'SELECT *',
'FROM ({{=it._query}}) _analysis_filter_rank',
'ORDER BY {{=it._column}} {{=it._orderDirection}}',
'{{=it._showHideAction}} {{=it._limitNumber}}'
].join('\n'));

FilterRank.prototype.sql = function() {
return filterRankTemplate({
_query: this.source.getQuery(),
_column: this.column,
_orderDirection: (this.rank === 'bottom' ? 'ASC' : 'DESC'),
_showHideAction: (this.action === 'hide' ? 'OFFSET' : 'LIMIT'),
_limitNumber: this.limit
});
};

0 comments on commit 0ffd7ad

Please sign in to comment.