Skip to content

Commit

Permalink
Merge pull request #37 from kiliankoe/fix-find-NotIdentified
Browse files Browse the repository at this point in the history
Fix find for stop names which are not found
  • Loading branch information
ronhippler committed Mar 17, 2017
2 parents 060ebdb + c69a10b commit 608e7eb
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 48 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
coverage/
.idea/
.idea/
npm-debug.log
60 changes: 31 additions & 29 deletions lib/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,40 +9,42 @@ function pointFinder(name) {
var stopName = utils.stripSpaces(name);

var options = {
url: 'https://webapi.vvo-online.de/tr/pointfinder?format=json',
qs: {
limit: 0,
query: stopName,
stopsOnly: true,
dvb: true,
assignedStops: true
}
}
url: 'https://webapi.vvo-online.de/tr/pointfinder?format=json',
qs: {
limit: 0,
query: stopName,
stopsOnly: true,
dvb: true,
assignedStops: true
}
};

return requestP(options)
.then(JSON.parse)
.then(function (data) {

// check status
if (data.Status &&
data.Status.Code === 'Ok' &&
data.Points) {

return data.Points.map(function (p) {
return p.split('|');
}).filter(function (p) {
return p[3]
}).map(function (p) {
var city = p[2] === "" ? "Dresden" : p[2]
return {
stop: p[3],
id: p[0],
city: city,
coords: utils.GK4toWGS84(p[4], p[5])
};
});
}
});
// check status
if (data.Status &&
data.Status.Code === 'Ok' &&
data.Points) {

return data.Points.map(function (p) {
return p.split('|');
}).filter(function (p) {
return p[3]
}).map(function (p) {
var city = p[2] === "" ? "Dresden" : p[2]
return {
stop: p[3],
id: p[0],
city: city,
coords: utils.GK4toWGS84(p[4], p[5])
};
});
}

return [];
});
}

var find = function find(searchString, callback) {
Expand Down
4 changes: 0 additions & 4 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ utils.stripSpaces = function stripSpaces(s) {
return s.replace(/ /g, '');
};

//utils.isDresden = function isDresden(point) {
// return 'Dresden' === point.ref.place;
//};

utils.convertCoordinates = function convertCoordinates(s) {
return s.split(',').map(parseFloat).reverse();
};
Expand Down
1 change: 1 addition & 0 deletions test/data/address-0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
""
1 change: 1 addition & 0 deletions test/data/coords-123.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
""
1 change: 0 additions & 1 deletion test/data/empty_json.json

This file was deleted.

2 changes: 1 addition & 1 deletion test/data/find-empty_json.json → test/data/find-0.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"PointStatus":"List","Status":{"Code":"Ok"},"Points":["14951027||||0|0|0||","14951067||||0|0|0||","14951014||||0|0|0||","14950996||||0|0|0||"],"ExpirationTime":"\/Date(1487410993340+0100)\/"}
{"PointStatus":"List","Status":{"Code":"Ok"},"Points":["14951027||||0|0|0||","14951067||||0|0|0||","14951014||||0|0|0||","14950996||||0|0|0||"],"ExpirationTime":"\/Date(1489782819339+0100)\/"}
1 change: 1 addition & 0 deletions test/data/find-Postpl.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"PointStatus":"List","Status":{"Code":"Ok"},"Points":["33000037|||Postplatz|5658730|4621656|0||","33000033|||Postplatz / Webergasse|5658423|4621733|0||","36040112||Aue (Sachs)|Postplatz|5606043|4549703|0||","33007557||Bautzen|Postplatz|5674144|4669959|0||","36040241||Eibenstock|Postplatz|5595521|4542641|0||","40001859||Fehrbellin|Postplatz|0|0|0||","14908883||Görlitz|Postplatz|5672771|4708965|0||","36040863||Lindenau (b Aue)|Postplatz|5606136|4542992|0||","31000979||Reichenbach (Vogtl)|Postplatz|5609693|4521544|0||","36020504||Stollberg (Erzgeb)|Postplatz|5619679|4555330|0||"],"ExpirationTime":"\/Date(1489782818934+0100)\/"}
1 change: 1 addition & 0 deletions test/data/find-Postplatz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"PointStatus":"List","Status":{"Code":"Ok"},"Points":["33000037|||Postplatz|5658730|4621656|0||","33000033|||Postplatz / Webergasse|5658423|4621733|0||","36040112||Aue (Sachs)|Postplatz|5606043|4549703|0||","33007557||Bautzen|Postplatz|5674144|4669959|0||","36040241||Eibenstock|Postplatz|5595521|4542641|0||","40001859||Fehrbellin|Postplatz|0|0|0||","14908883||Görlitz|Postplatz|5672771|4708965|0||","36040863||Lindenau (b Aue)|Postplatz|5606136|4542992|0||","31000979||Reichenbach (Vogtl)|Postplatz|5609693|4521544|0||","36020504||Stollberg (Erzgeb)|Postplatz|5619679|4555330|0||"],"ExpirationTime":"\/Date(1489777825742+0100)\/"}
1 change: 0 additions & 1 deletion test/data/find-postplatz.json

This file was deleted.

1 change: 1 addition & 0 deletions test/data/find-xyz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"PointStatus":"NotIdentified","Status":{"Code":"Ok"},"ExpirationTime":"\/Date(1489778283570+0100)\/"}
2 changes: 1 addition & 1 deletion test/data/monitor-33000037.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Name":"Postplatz","Status":{"Code":"Ok"},"Place":"Dresden","ExpirationTime":"\/Date(1487299575511+0100)\/","Departures":[{"Id":"65500150","LineName":"11","Direction":"Bühlau","Platform":{"Name":"4","Type":"Platform"},"Mot":"Tram","RealTime":"\/Date(1487301300000+0100)\/","ScheduledTime":"\/Date(1487301300000+0100)\/","State":"InTime","RouteChanges":["509223"],"Diva":{"Number":"11011","Network":"voe"}},{"Id":"65530130","LineName":"4","Direction":"Weinböhla","Platform":{"Name":"2","Type":"Platform"},"Mot":"Tram","RealTime":"\/Date(1487301300000+0100)\/","ScheduledTime":"\/Date(1487301300000+0100)\/","State":"InTime","Diva":{"Number":"11004","Network":"voe"}},{"Id":"65498281","LineName":"2","Direction":"Gorbitz","Platform":{"Name":"2","Type":"Platform"},"Mot":"Tram","RealTime":"\/Date(1487301300000+0100)\/","ScheduledTime":"\/Date(1487301300000+0100)\/","State":"InTime","Diva":{"Number":"11002","Network":"voe"}},{"Id":"65498391","LineName":"2","Direction":"Kleinzschachwitz","Platform":{"Name":"1","Type":"Platform"},"Mot":"Tram","RealTime":"\/Date(1487301300000+0100)\/","ScheduledTime":"\/Date(1487301300000+0100)\/","State":"InTime","Diva":{"Number":"11002","Network":"voe"}},{"Id":"65498845","LineName":"4","Direction":"Laubegast","Platform":{"Name":"1","Type":"Platform"},"Mot":"Tram","RealTime":"\/Date(1487301300000+0100)\/","ScheduledTime":"\/Date(1487301300000+0100)\/","State":"InTime","Diva":{"Number":"11004","Network":"voe"}}]}
{"Name":"Postplatz","Status":{"Code":"Ok"},"Place":"Dresden","ExpirationTime":"\/Date(1489699017825+0100)\/","Departures":[{"Id":"66022940","LineName":"11","Direction":"Zschertnitz","Platform":{"Name":"3","Type":"Platform"},"Mot":"Tram","RealTime":"\/Date(1489699020000+0100)\/","ScheduledTime":"\/Date(1489699020000+0100)\/","State":"InTime","Diva":{"Number":"11011","Network":"voe"}},{"Id":"66030495","LineName":"94","Direction":"Cossebaude","Platform":{"Name":"4","Type":"Platform"},"Mot":"CityBus","RealTime":"\/Date(1489699040000+0100)\/","ScheduledTime":"\/Date(1489699020000+0100)\/","State":"InTime","RouteChanges":["509154"],"Diva":{"Number":"21094","Network":"voe"}},{"Id":"66022534","LineName":"9","Direction":"Kaditz","Platform":{"Name":"4","Type":"Platform"},"Mot":"Tram","RealTime":"\/Date(1489699059000+0100)\/","ScheduledTime":"\/Date(1489699020000+0100)\/","State":"InTime","RouteChanges":[],"Diva":{"Number":"11009","Network":"voe"}},{"Id":"66020843","LineName":"2","Direction":"Gorbitz","Platform":{"Name":"2","Type":"Platform"},"Mot":"Tram","RealTime":"\/Date(1489699080000+0100)\/","ScheduledTime":"\/Date(1489699080000+0100)\/","State":"InTime","RouteChanges":[],"Diva":{"Number":"11002","Network":"voe"}},{"Id":"66023279","LineName":"12","Direction":"Striesen","Platform":{"Name":"3","Type":"Platform"},"Mot":"Tram","RealTime":"\/Date(1489699200000+0100)\/","ScheduledTime":"\/Date(1489699200000+0100)\/","State":"InTime","Diva":{"Number":"11012","Network":"voe"}}]}
1 change: 1 addition & 0 deletions test/data/monitor-xyz.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"PointStatus":"NotIdentified","Status":{"Code":"Ok"},"ExpirationTime":"\/Date(1489778283570+0100)\/"}
2 changes: 1 addition & 1 deletion test/data/pins-stop.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
["33000132|||Nürnberger Platz|5656599|4621245||1:3~7~8#2:61~63#3:333~400","33000134|||Münchner Platz|5656381|4620873||1:3~7~8","33000727|||Technische Universität (Fr.-Foerster-Platz)|5656396|4621529||2:61~63~66#3:352~360~366~424~672","33000133|||Südvorstadt|5656838|4620912||1:8","33000724|||Bernhardstraße|5656912|4620804||2:61~63#3:333","33000732|||Mommsenstraße|5656132|4621567||2:66#3:352~360~366","33000131|||Reichenbachstraße|5656979|4621548||1:3~7~8#2:66#3:333~352~360~366","33000742|||Helmholtzstraße|5655904|4621157||2:85","33000513|||Regensburger Straße|5655989|4620830||2:85","33000135|||Plauen Nöthnitzer Straße|5656119|4620472||1:3~7~8#2:85","33000728|||Staats- und Universitätsbibliothek|5656319|4622011||2:61~63","33000723|||Chemnitzer Straße|5657144|4620451||2:61~62~63#3:333","33000720|||Bamberger Straße|5656814|4620223||2:62","33000036|||Hauptbahnhof (Friedrich-List-Platz)|5657392|4621708||2:66#3:SEV","33000512|||Stadtgutstraße|5655763|4621918||2:85","33000721|||Agentur für Arbeit|5657491|4620678||2:62","33000160|||Westendstraße|5655779|4620329||2:63","33000782|||Uhlandstraße|5657186|4622121||2:66~H/S","33000722|||Zwickauer Straße|5657322|4620286||2:61~63","33000030|||Gret-Palucca-Straße|5657405|4622123||1:9~10~11#2:66"]
["33000132|||Nürnberger Platz|5656599|4621245||1:3~7~8#2:61~63#3:333~400","33000134|||Münchner Platz|5656381|4620873||1:3~7~8","33000727|||Technische Universität (Fr.-Foerster-Platz)|5656396|4621529||2:61~63~66#3:352~360~366~424~672","33000133|||Südvorstadt|5656838|4620912||1:8","33000724|||Bernhardstraße|5656912|4620804||2:61~63#3:333","33000732|||Mommsenstraße|5656132|4621567||2:66#3:352~360~366","33000131|||Reichenbachstraße|5656979|4621548||1:3~7~8#2:66#3:333~352~360~366","33000742|||Helmholtzstraße|5655904|4621157||2:85","33000513|||Regensburger Straße|5655989|4620830||2:85","33000135|||Plauen Nöthnitzer Straße|5656119|4620472||1:3~7~8#2:85","33000728|||Staats- und Universitätsbibliothek|5656319|4622011||2:61~63","33000723|||Chemnitzer Straße|5657144|4620451||2:61~62~63#3:333","33000720|||Bamberger Straße|5656814|4620223||2:62","33000036|||Hauptbahnhof (Friedrich-List-Platz)|5657392|4621708||2:66","33000512|||Stadtgutstraße|5655763|4621918||2:85","33000721|||Agentur für Arbeit|5657491|4620678||2:62","33000160|||Westendstraße|5655779|4620329||2:63","33000782|||Uhlandstraße|5657186|4622121||2:66~H/S","33000722|||Zwickauer Straße|5657322|4620286||2:61~63","33000030|||Gret-Palucca-Straße|5657405|4622123||1:9~10~11#2:66"]
34 changes: 25 additions & 9 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ describe('dvb.monitor', function () {
});

describe('dvb.monitor "Postplatz"', function () {
mockRequest(['find-postplatz.json', 'monitor-33000037.json']);
mockRequest(['find-Postplatz.json', 'monitor-33000037.json']);

it('should return an array with elements', function (done) {
dvb.monitor('Postplatz', 10, 5)
Expand Down Expand Up @@ -134,11 +134,11 @@ describe('dvb.monitor', function () {
});
});

describe('dvb.monitor "xxx"', function () {
mockRequest('empty_json.json');
describe('dvb.monitor "xyz"', function () {
mockRequest('monitor-xyz.json');

it('should return an empty array', function (done) {
dvb.monitor('xxx', 0, 5)
dvb.monitor('xyz', 0, 5)
.then(function (data) {
assert(Array.isArray(data));
assert.equal(data.length, 0);
Expand Down Expand Up @@ -227,7 +227,7 @@ describe('dvb.route', function () {
});

describe('dvb.route "0 -> 0"', function () {
mockRequest('empty_json.json');
mockRequest('empty.json');

it('should return null', function (done) {
dvb.route('0', '0', new Date(), 'foo')
Expand All @@ -244,7 +244,7 @@ describe('dvb.route', function () {

describe('dvb.find', function () {
describe('dvb.find "Postplatz"', function () {
mockRequest('find-postplatz.json');
mockRequest('find-Postpl.json');

function assertStop(stop) {
assert(stop.stop);
Expand Down Expand Up @@ -287,7 +287,7 @@ describe('dvb.find', function () {
});

describe('dvb.find "0"', function () {
mockRequest('find-empty_json.json');
mockRequest('find-0.json');

it('should return an empty array', function (done) {
dvb.find('0')
Expand All @@ -300,6 +300,22 @@ describe('dvb.find', function () {
done(err);
});
});
});

describe('dvb.find "xyz"', function () {
mockRequest('find-xyz.json');

it('should return an empty array', function (done) {
dvb.find('xyz')
.then(function (data) {
assert(Array.isArray(data));
assert.equal(data.length, 0);
done();
})
.catch(function (err) {
done(err);
});
});
})
});

Expand Down Expand Up @@ -439,7 +455,7 @@ describe('dvb.address', function () {
});

describe('dvb.address "0, 0"', function () {
mockRequest('empty.json');
mockRequest('address-0.json');

it('should return null', function (done) {
dvb.address(0, 0)
Expand Down Expand Up @@ -481,7 +497,7 @@ describe('dvb.coords', function () {
});

describe('dvb.coords "123"', function () {
mockRequest('empty.json');
mockRequest('coords-123.json');

it('should return null', function (done) {
dvb.coords("123")
Expand Down

0 comments on commit 608e7eb

Please sign in to comment.