From 59daee4d49654047db08ab0dd58c1be81935f5c9 Mon Sep 17 00:00:00 2001 From: Alec Vulfson Date: Wed, 27 Jul 2016 13:50:49 -0400 Subject: [PATCH] Ensures NYC 5 boroughs are labelled as boroughs Created a file that allows choosing a given layer for a specific ID --- data/specialCases.json | 7 +++++++ lib/streams/layerMappingStream.js | 7 ++++++- test/streams/layerMappingStreamTest.js | 23 +++++++++++++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 data/specialCases.json diff --git a/data/specialCases.json b/data/specialCases.json new file mode 100644 index 00000000..df97ea4d --- /dev/null +++ b/data/specialCases.json @@ -0,0 +1,7 @@ +{ + "5110302": "borough", + "5125771": "borough", + "5133273": "borough", + "5110266": "borough", + "5139568": "borough" +} diff --git a/lib/streams/layerMappingStream.js b/lib/streams/layerMappingStream.js index 05354797..7fbd7317 100644 --- a/lib/streams/layerMappingStream.js +++ b/lib/streams/layerMappingStream.js @@ -1,4 +1,5 @@ var through2 = require('through2'); +var specialID = require('../../data/specialCases'); function featureCodeToLayerDefault(featureCode) { switch (featureCode) { @@ -83,9 +84,13 @@ function featureCodeToLayer(featureCode, countryCode) { } } +function mapIDtoLayer(id){ + return specialID[id]; +} + function create() { return through2.obj(function(data, enc, next) { - data.layer = featureCodeToLayer(data.feature_code, data.country_code); + data.layer = mapIDtoLayer(data._id) || featureCodeToLayer(data.feature_code, data.country_code); next(null, data); }); diff --git a/test/streams/layerMappingStreamTest.js b/test/streams/layerMappingStreamTest.js index 81a1ce42..e13814e9 100644 --- a/test/streams/layerMappingStreamTest.js +++ b/test/streams/layerMappingStreamTest.js @@ -80,3 +80,26 @@ tape('layerMappingStream', function(test) { }); }); }); + +tape('IDtoLayer', function(test){ + test.test('special cases: the nyc boroughs', function(t){ + var input = [ + {_id: 5110302, feature_code: 'PPLA2'}, + {_id: 5125771, feature_code: 'PPLA2'}, + {_id: 5133273, feature_code: 'PPLA2'}, + {_id: 5110266, feature_code: 'PPLA2'}, + {_id: 5139568, feature_code: 'PPLA2'}, + {_id: 5112223, feature_code: 'PPLA'}]; + var stream = layerMappingStream.create(); + + test_stream(input,stream,function(err, results){ + var actual = results.map(function(doc){ + return doc.layer; + }); + var expected = ['borough','borough','borough','borough','borough','locality']; + + test.deepEqual(actual,expected,'special case: NYC handled'); + t.end(); + }); + }); +});