Skip to content

Commit

Permalink
add filter by activity option to cities
Browse files Browse the repository at this point in the history
  • Loading branch information
claygregory committed Jul 5, 2017
1 parent 16d36da commit eabf531
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/commands/cities.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ exports.builder = function (yargs) {
.number('limit')
.default('limit', 12);

yargs.describe('activity', 'Filter movements to specified activity');

yargs.describe('min-points', '(advanced) Minimum number of points for clustering')
.number('min-points')
.default('min-points', 4);
Expand All @@ -27,7 +29,9 @@ exports.builder = function (yargs) {

exports.handler = function (options) {

const segments = utils.loadStoryline(options.input, options);
let segments = utils.loadStoryline(options.input, options);
if (options.activity)
segments = _.filter(segments, ['activity', options.activity]);

const controlPoints = clusterLocations(segments, options);
const sortedControlPoints = _.chain(controlPoints)
Expand All @@ -47,10 +51,12 @@ exports.handler = function (options) {

function clusterLocations(segments, options) {

const places = _.filter(segments, ['type', 'place']);
const dataset = _.chain(places)
.map(p => p.place.location)
const moves = _.filter(segments, ['type', 'move']);
const dataset = _.chain(moves)
.flatMap(m => [_.first(m.trackPoints), _.last(m.trackPoints)])
.filter()
.map(m => _.pick(m, ['lat', 'lon']))
.uniqBy(m => _.values(m).join(','))
.value();

const dbscan = new clustering.DBSCAN();
Expand Down

0 comments on commit eabf531

Please sign in to comment.