Right Track Database Builder

This project is used to compile a Right Track Database: a SQLite database
containing GTFS transit data and additional Right Track data tables for a
single transit agency. This database is used in the various Right Track
projects, such as the right-track-server
and is required for any data queries performed by the right-track-core
library.

Installation

This project can be installed via npm:

npm install -g right-track-db-build

When installed globally, npm will link the executable right-track-db-build
into your $PATH.

Dependencies

In order to compile a database for a specific transit agency, a Right Track
Agency module (such as right-track-agency-mnr)
will also need to be installed. The agency module provides information on
where/how to obtain the agency's GTFS data as well as additional database
compilation instructions. The compiled database (and an archive of compiled
databases) will be kept in the Right Track Agency's module.

The agencies are provided to the right-track-db-build script via the
--agency command line flag.

NOTE: There are no Right Track Agency modules listed as dependencies
in this project's package.json file. The Agency modules will have
to be installed separately and referenced manually using the --agency
CLI flag.

Usage

Example: Update GTFS data and compile a database for Metro North Railroad:

Additional Scripts

Agency Scripts

Each Agency can provide scripts that override the default update script,
run after the update procedure, and run after the compilation process.

Update Script

If this script is present, it will override the default update check script.

The default update script makes a HEAD request to the URL in the agency's
config property (build.updateURL). If the Last-Modified Header is newer
than the saved date/time (or the saved date/time does not exist) then
the GTFS zip file from the URL will be downloaded and unzipped into the
./db-build/gtfs/ directory of the agency module.

This script can be used to provide a different update and install
procedure. The script should check if a newer GTFS source file
is available. If an update is available, it should download and
install the GTFS files into the agency module's ./db-build/gtfs/
directory.

Peak Calculator Script

If this script is present, it will determine if a Trip should be considered
a peak trip (ie, operates during agency-specified rush hours and has higher
than usual fares). By default the DB-Build script will mark all Trips as
not peak (value of 0). This script should return a peak status value
for the specified Trip with one of these possible values:

0 - the Trip is never considered a Peak trip

1 - the Trip is always considered a Peak trip when it runs (excluding
Holidays that do not have Peak trips)

2 - the Trip may be considered a Peak trip, if the date of the Trip
is a weekday (excluding Holidays that do not have Peak trips)

When the right-track-core library creates a Trip instance, it will consult
the rt_holidays table, if present. If a Trip is being created for a date
that is considered a Holiday and the holiday has a peak value of false, then
all Trips running on that date will be considered Off-Peak.

Location: {{AGENCY_MODULE}}/db-build/src/peak.js

Parameters:

{Object} db - The SQLite Database instance of the database currently being built

{string} tripId - The GTFS Trip ID of the Trip to determine the peak status of

{function} callback - The callback function to return to the build script

{int} peak - The peak status of the Trip

Post-Compile Script

If this script is present, it will run after the database compilation process
and before the database installation.

This script can be used to make any agency-specific changes to the compiled
Right Track database before it is installed.