Giter Site home page Giter Site logo

derhuerst / vbb-stations-autocomplete Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 1.0 418 KB

Search for stations in the Berlin Brandenburg public transport service (VBB).

Home Page: https://github.com/derhuerst/vbb-stations-autocomplete

License: ISC License

JavaScript 100.00%
vbb transport bvg berlin transit

vbb-stations-autocomplete's Introduction

vbb-stations-autocomplete

vbb-stations-autocomplete provides a stations search for the Berlin Brandenburg public transport service (VBB). It pulls its data from vbb-stations.

Note: Because there are ~ 13k stations, this module contains ~ 800k of data (~ 240k gzipped).

npm version ISC-licensed support me via GitHub Sponsors chat with me on Twitter

Installing

npm install vbb-stations-autocomplete

Usage

autocomplete(query, results = 3, fuzzy = false, completion = true)
const autocomplete = require('vbb-stations-autocomplete')
autocomplete('Seestr', 3)

This returns stations in a reduced form of the Friendly Public Transport Format. To get all details, pass each id into vbb-stations.

[
	{
		id: '900000009103', // U Seestr.
		relevance: 2.0817557,
		score: 40.8276194
	}, {
		id: '900000009105', // Seestr./Amrumer Str.
		relevance: 1.0408778,
		score: 15.7013362
	}, {
		id: '900000019103', // Seestr./Beusselstr.
		relevance: 1.3878371,
		score: 12.3226614
	}
]

If you set fuzzy to true, words with a Levenshtein distance <= 3 will be taken into account. This is a lot slower though:

test performance
non-fuzzy – U mehringdamm 325 ops/sec
fuzzy – U mehrigndamm 73 ops/sec

Setting completion to false speeds things up a lot:

test performance
completion – U friedr 306 ops/sec
no completion – U friedr 5076 ops/sec

Contributing

If you have a question, found a bug or want to propose a feature, have a look at the issues page.

vbb-stations-autocomplete's People

Contributors

dabendorf avatar derhuerst avatar greenkeeper[bot] avatar karlkristopher avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

karlkristopher

vbb-stations-autocomplete's Issues

gives duplicate results

const allStations = require('vbb-stations/simple')
const autocomplete = require('vbb-stations-autocomplete')

const byId = Object.create(null)
for (const station of allStations) byId[station.id] = station

const withName = (s) => {
	const {name} = byId[s.id] || {}
	return {...s, name}
}
console.log(autocomplete('alex', 10, false, true).map(withName))
[
	{
		id: '900000100003',
		relevance: 1.0000253852333332,
		score: 19.145270936838475,
		weight: 14033,
		type: 'station',
		name: 'S+U Alexanderplatz',
		location: { type: 'location', latitude: 52.521512, longitude: 13.411267 }
	},
	{
		id: '900000012156',
		relevance: 1.2106024714894736,
		score: 12.230837892118485,
		weight: 1031.25,
		type: 'station',
		name: 'Alexandrinenstr.',
		location: { type: 'location', latitude: 52.505154, longitude: 13.405322 }
	},
	{
		id: '900000100518',
		relevance: 1.250228467,
		score: 12.04842823265298,
		weight: 895,
		type: 'station',
		name: 'Alexanderstr.',
		location: { type: 'location', latitude: 52.517745, longitude: 13.418129 }
	},
	{
		id: '900000100003',
		relevance: 0.4288252809047619,
		score: 10.343413554764968,
		weight: 14033,
		type: 'station',
		name: 'S+U Alexanderplatz',
		location: { type: 'location', latitude: 52.521512, longitude: 13.411267 }
	},
	{
		id: '900000100005',
		relevance: 0.4288252809047619,
		score: 6.846936505115713,
		weight: 4070.5,
		type: 'station',
		name: 'U Alexanderplatz [Tram]',
		location: { type: 'location', latitude: 52.52239, longitude: 13.414492 }
	},
	{
		id: '900000100704',
		relevance: 0.32161896067857143,
		score: 6.404383904550258,
		weight: 7896,
		type: 'station',
		name: 'S+U Alexanderplatz [U5]',
		location: { type: 'location', latitude: 52.521607, longitude: 13.413111 }
	},
	{
		id: '900000100703',
		relevance: 0.32161896067857143,
		score: 5.407513125522895,
		weight: 4753,
		type: 'station',
		name: 'S+U Alexanderplatz [U2]',
		location: { type: 'location', latitude: 52.522078, longitude: 13.413598 }
	},
	{
		id: '900000100026',
		relevance: 0.32161896067857143,
		score: 5.120441727198608,
		weight: 4035.5,
		type: 'station',
		name: 'S+U Alexanderplatz/Gontardstr.',
		location: { type: 'location', latitude: 52.521063, longitude: 13.411252 }
	},
	{
		id: '900000100031',
		relevance: 0.32161896067857143,
		score: 4.94964618079964,
		weight: 3645,
		type: 'station',
		name: 'S+U Alexanderplatz/Memhardstr.',
		location: { type: 'location', latitude: 52.523098, longitude: 13.410964 }
	},
	{
		id: '900000100705',
		relevance: 0.32161896067857143,
		score: 4.39481065114198,
		weight: 2551.5,
		type: 'station',
		name: 'S+U Alexanderplatz [U8]',
		location: { type: 'location', latitude: 52.521619, longitude: 13.412125 }
	}
]

An in-range update of cli-autocomplete is breaking the build 🚨

The devDependency cli-autocomplete was updated from 0.4.1 to 0.4.2.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

cli-autocomplete is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

Commits

The new version differs by 2 commits.

  • 1deb3cf example :memo:, gitignore lockfile, 0.4.2
  • 2c9d428 minor bugfix :bug:

See the full diff

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

An in-range update of vbb-stations is breaking the build 🚨

The devDependency vbb-stations was updated from 7.0.0 to 7.1.0.

🚨 View failing branch.

This version is covered by your current version range and after updating it in your project the build failed.

vbb-stations is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.

Status Details
  • continuous-integration/travis-ci/push: The Travis CI build failed (Details).

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.