Skip to content

A Javascript based API for calculating the shortest path between two metro stations.

License

Notifications You must be signed in to change notification settings

Mansehej/DelhiMetroAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Delhi Metro API

A Javascript based API for calculating the shortest path between two metro stations.

Data Sources

Data about stations per line is downloaded from Wikipedia tables (https://en.wikipedia.org/wiki/Red_Line_(Delhi_Metro)), etc. for each line.

Working

The metro lines are implemented in a Graph Data Structure in Javascript. Each station is considered as a node and time between stations is alloted as the weights between two nodes. An additional parameter "Metro line" is given to each edge. Dijkstra's algorithm is used to find the route with the least time between two stations. Changes of the Metro Line parameters are used to calculate interchanges and include the interchange time.

Hierarchy

functions/functions/route.js contains the code importing the lines with stations and calculating the shortest route. The folder functions/functions/lines contains the json files of the stations of all metro lines.

Lines Implemented

The following lines have been implemented (in order):
->Blue : 2.02 minutes
->Blue Branch : 1.875 minutes
->Magenta : 2.36 minutes
->Yellow : 2.22 minutes
->Red : 2.03 minutes
->Green : 2.49 minutes
->Green Branch : 1.33 minutes
->Violet : 2.24 minutes
->Pink : 2.69 minutes
->Pink Branch : 2.43 minutes
->Orange (Airport Express Line) : 5.2 minutes
->Aqua : 2.86 minutes
->Grey : 2.10 minutes
->Rapid Metro : 5.2 minutes

Features

->Get shortest complete path from Source Station to Destination Station
->Get list of Interchange Stations in order
->Get Metro Lines Changed
->Get Total Travel Time
->Get Final Station of Metro Line in direction of destination/next interchange

Status Codes

Status codes are returned in the response in JSON format as 'status':statusCode. The value of different status codes are:
Result succesfully generated: 200
Same source and destination: 204
Undefined source or destination: 400
Invalid source: 4061
Invalid destination: 4062
Invalid source and destination: 406
Please note that these status codes are returned in the JSON response and not as HTTP status codes

API Calling

The API is hosted on Google Firebase, and can be called at:
https://us-central1-delhimetroapi.cloudfunctions.net/route-get with a GET query and parameters as from (source station) and to (destination station).
For example, the API call for a route between Dwarka and Palam would be: https://us-central1-delhimetroapi.cloudfunctions.net/route-get?from=Dwarka&to=Palam.
The stations to be passed in the parameters must start with a capital letter. The stations must be passed as they are written in the /StationList.txt file.

About

A Javascript based API for calculating the shortest path between two metro stations.

Resources

License

Stars

Watchers

Forks

Packages

No packages published