Initializes the routing engine with transit data.
-List of all transit trips.
-Graph of walking connections between stops.
-Minimum transfer times for each stop.
-Calculates optimal journeys for a specific departure time.
-The starting Stop ID.
-The destination Stop ID.
-The exact departure time.
-A list of optimal Journey objects.
-Finds the best journeys within a time window, filtering for Pareto optimality across all departures.
-The starting Stop ID.
-The destination Stop ID.
-The start of the departure window.
-The duration of the window to search (e.g. 3600s).
-A deduplicated list of the best journeys found in the time range.
-Executes the McRAPTOR algorithm to find all non-dominated paths to the destination.
-The starting Stop ID.
-The destination Stop ID.
-The time of departure.
-A Bag containing Pareto-optimal labels for the destination.
-Sets the penalty multiplier for walking (default is 1).
-The multiplier for walking duration cost.
-A container for Labels at a specific stop that maintains a Pareto frontier. -Only keeps labels that are not dominated by any other label in the bag.
-Attempts to add a label to the bag.
-True if the label was added (it was non-dominated), False otherwise.
-Checks if the bag is empty.
-Merges another bag's labels into this one.
-True if the merge resulted in any changes to this bag.
-Represents a state or arrival at a specific stop in the routing graph. -Used to trace back the path and store performance metrics.
-Time of arrival at this stop.
-Cumulative walking distance in meters.
-Number of transfers taken so far.
-The previous label in the chain (used for backtracking).
-The trip taken to reach this state (if applicable).
-The transfer used to reach this state (if applicable).
-The ID of the current stop.
-Time when the passenger boarded the vehicle.
-Index of the current stop in the trip's sequence.
-Time of arrival at this stop.
-Time when the passenger boarded the vehicle.
-The previous label in the chain (used for backtracking).
-The ID of the current stop.
-Index of the current stop in the trip's sequence.
-The transfer used to reach this state (if applicable).
-Number of transfers taken so far.
-The trip taken to reach this state (if applicable).
-Cumulative walking distance in meters.
-Returns aggregated data for the frontend, including route configs and metadata.
-Express request
-Express response
-JSON object with routes (array of route details) and metadata.
Returns static route metadata including names, images, and colors.
-Express request
-Express response
-JSON object containing routeIdToName, routeImages, metadata, and routeColors.
Returns a list of all selectable routes with their names and colors.
-Express request
-Express response
-JSON object with a bustime-response containing a list of routes.
Express request, SwapTokenBody in the body
Express response, error message as string if error occurs
-Upon responding with 200, future calls to /setReminder, /unsetReminder, and /activeReminders -will need the new token
-Finds the nearest k stops to a given coordinate.
-Sorts every prediction list contained in x by arrival timestamp
Plans a journey between two coordinates using the McRaptor algorithm.
-Origin latitude
-Origin longitude
-Destination latitude
-Destination longitude
-Start time in seconds since midnight
-Optional parameters for walking penalty and search range
-factory
-Updates the cached graph.
-Calculates the great-circle distance between two points using the Haversine formula.
-Latitude of point A.
-Longitude of point A.
-Latitude of point B.
-Longitude of point B.
-Distance in meters.
-Loads and parses the GraphML map file into a usable graph structure.
-An object containing the map of Nodes and the Adjacency List (graph).
-Maps a list of bus stops to their nearest nodes on the street graph. -This optimizes future lookups by caching the StopID -> NodeID relationship.
-A map of StopID to {lat, lon}.
-Ensures walking paths between all provided stops are calculated and cached. -Fetches missing paths in parallel and updates the disk cache.
-Set of stop IDs to verify.
-Map of Stop ID to coordinates.
-Retrieves a cached walking path between two stops.
-Origin Stop ID.
-Destination Stop ID.
-Cached walking data or undefined.
-Optimized method to get walking distances from an origin to ALL known bus stops. -Optionally includes a direct walk to a specific destination point. -Uses a single Dijkstra pass with early termination and LRU Cache.
-Origin latitude.
-Origin longitude.
-OptionaldestLat: number(Optional) Destination latitude for direct walk.
-OptionaldestLon: number(Optional) Destination longitude for direct walk.
-Calculates a detailed walking path between two coordinates using A*. -Includes path geometry for rendering.
-Latitude of origin.
-Longitude of origin.
-Latitude of destination.
-Longitude of destination.
-
-
-
-
-
-
-
- Backend service for the Magic Bus application. Handles real-time bus tracking, route management, and multi-modal journey planning (bus + walking) using the McRaptor algorithm. -
-First, obtain an API key for the Magic Bus backend from the official Magic Bus Website.
-Then, define the MBUS_API_KEY environment variable with your API key.
To install dependencies, run npm i
Create a Firebase project if you haven't already, and set FIREBASE_PROJECT_ID to its id. Follow the steps
-here to create a service
-account key file. Place this file into secrets/ and point GOOGLE_APPLICATION_CREDENTIALS to it.
-(you can do this temporarily with export GOOGLE_APPLICATION_CREDENTIALS="./secrets/your-filename.json")
Some additional resources for iOS here. Make -sure that the firebase project is configured with the same app id as xcode.
-To run the backend, run npm start.
By default, the service runs on port 3000. To define a port for the service to run on, define an environment variable called PORT before running the backend.
This project uses TSDoc for code documentation. -To compile the static documentation:
-npm run docs
-
-
-The documentation is served at http://localhost:3000/docs or this link.
This project uses Vitest for fast unit and integration testing.
-npm testnpm run stress-testAn example of passing the tests is below.
-
-Before submitting a pull request to main, please make sure you pass all the tests and can compile docs. If you believe some of the tests faulty or no longer needed after your commit, please contact Andrew Yu or Ryan Lu on Slack.
-Represents a complete transit journey consisting of multiple legs.
-Represents a single segment of a journey, either a transit trip or a walking transfer.
-Abstract representation of a connection between two stops.
-Represents a scheduled stop event within a trip (GTFS StopTime).
-Whether passengers can alight from the vehicle here.
-OptionalheursticOptional pre-calculated cost for routing heuristics.
-OptionalisIf the stop is predicted or not.
-Whether passengers can board the vehicle here.
-OptionalrtReal-time status string (if available).
-The ID of the stop.
-A specific segment of a scheduled trip with fixed times.
-A walking connection between two stops with a defined duration.
-Result of a batch query from a single origin node to multiple destinations.
-The straight-line distance from the origin coordinates to the street node.
-The ID of the street node closest to the origin coordinates.
-A map of NodeID -> Distance (in meters) for all reachable nodes.
-Standard response for a single point-to-point walking query.
-Defines the optimization metrics used to compare different journey options.
-A span of time measured in seconds.
-Unique identifier for a transit stop (e.g., "NRW").
-Time represented as seconds since midnight. -Values may exceed 86400 (24 hours) for trips extending into the next day.
-Unique identifier for a GTFS trip.
-Waiting for the bus indicated by vid to be at the stop indicated by stpid. Logic for what notification to send
-is complicated by arrival times sometimes skipping DUE, see ReminderSubscriptons.process for details.
Waiting for a prediction of the right event to have a arrival timestamp that is at or after mustBeAfter and an
-arrival time less than thresh. A bus is xx minutes from the stop notification is then sent. To handle delayed and
-disappeared notifications, a candidateVid is set to the soonest arriving bus that arrives after mustbeAfter.
stores the bus that'll likely trigger the threshold notification, being only a candidate this can change -as things are updated and such a change won't trigger a disappeared notification
-minutes
-unix epoch milliseconds
-minutes
-Represents a bus prediction.
-Represents a node in the street graph derived from GraphML.
-ConstExpress router for the MBus API v3. -Handles routes for static data, state debugging, journey planning, and startup info.
-ConstRaw static metadata from JSON.
-ConstConstThe current transit graph used for routing.
-ConstPredictions indexed by stop ID.
-ConstPredictions indexed by vehicle ID.
-ConstPredictions indexed by ride stop ID.
-ConstPredictions indexed by ride vehicle ID.
-ConstCache of route patterns and static data for the ride.
-ConstCache of route patterns and static data.
-Cache of stop locations (lat/lon).
-ConstCurrent positions of all buses.
-ConstCurrent positions of all ride buses.
-ConstMap of ride stop IDs to their human-readable names.
-ConstCache of timing differences between stops for extrapolation.
-ConstMap of stop IDs to their human-readable names.
-ConstMap of trip IDs to route names.
-ConstSet of currently valid ride route IDs.
-ConstSet of currently valid route IDs.
-
Implementation of the McRAPTOR (Multi-Criteria Round-Based Public Transit Routing) algorithm. -Optimizes for arrival time, walking distance, and number of transfers.
-