s2-tools
Version:
A collection of geospatial tools primarily designed for WGS84, Web Mercator, and S2.
75 lines • 2.48 kB
JavaScript
import { parseCSVAsRecord } from '../../';
/**
*
* Indicates the type of service for a trip with frequencies:
* 0 or empty = Frequency-based trips
* 1 = Schedule-based trips (with identical headway)
*/
export var GTFSExactTimes;
(function (GTFSExactTimes) {
GTFSExactTimes[GTFSExactTimes["FrequencyBased"] = 0] = "FrequencyBased";
GTFSExactTimes[GTFSExactTimes["ScheduleBased"] = 1] = "ScheduleBased";
})(GTFSExactTimes || (GTFSExactTimes = {}));
/**
* # Frequency
*
* **Optional**
* Defines headway-based (or compressed schedule-based) service for specific trips.
* Each record references a single trip and indicates:
* - A start/end time window
* - A headway (seconds between departures)
* - Whether it’s frequency-based (exact_times=0) or schedule-based (exact_times=1).
*
* **Primary Key**: (`trip_id`, `start_time`)
*/
export class GTFSFrequency {
/**
* **Required**
* Identifies the trip (`trips.trip_id`) to which the specified headway of service applies.
*/
tripId;
/**
* **Required**
* Time at which the first vehicle departs from the trip’s first stop
* with the specified headway (HH:MM:SS, can exceed 24:00:00 if overnight).
*/
startTime;
/**
* **Required**
* Time at which service changes or ends (HH:MM:SS, can exceed 24:00:00 if overnight).
*/
endTime;
/**
* **Required**
* Headway in seconds between departures from the same stop for this trip,
* during [start_time, end_time).
*/
headwaySecs;
/**
* **Optional**
* Whether this is frequency-based or schedule-based service.
* - 0 or empty = Frequency-based
* - 1 = Schedule-based
*/
exactTimes;
/** @param data - the parsed GTFS CSV data */
constructor(data) {
this.tripId = data.trip_id;
this.startTime = data.start_time;
this.endTime = data.end_time;
this.headwaySecs = data.headway_secs !== undefined ? parseInt(data.headway_secs, 10) : 0;
// Default to 0 if none provided
if (data.exact_times !== undefined && data.exact_times !== '') {
this.exactTimes = parseInt(data.exact_times, 10);
}
}
}
/**
* @param input - the input string to parse from
* @returns - an array of Frequency
*/
export function parseGTFSFrequencies(input) {
const data = parseCSVAsRecord(input);
return data.map((d) => new GTFSFrequency(d));
}
//# sourceMappingURL=frequencies.js.map