modules/query/StopTimesTable.js
function getStopTimeByTripStop(db, tripId, stopId, date, callback) {

  // Cache Cache for StopTimes
  let cacheKey = db.id + "-" + tripId + "-" + stopId + "-" + date;
  let cache = cache_stoptimesByTripStop.get(cacheKey);
  if ( cache !== null ) {
    return callback(null, cache);
  }

  // Build the select statement
  let select = "SELECT " +
    "gtfs_stop_times.arrival_time, departure_time, stop_sequence, pickup_type, drop_off_type, stop_headsign, shape_dist_traveled, timepoint, " +
    "gtfs_stops.stop_id, stop_name, stop_desc, stop_lat, stop_lon, stop_url, " +
    "gtfs_stops.zone_id AS gtfs_zone_id, stop_code, wheelchair_boarding, location_type, parent_station, stop_timezone, " +
    "rt_stops_extra.status_id, display_name, transfer_weight, rt_stops_extra.zone_id AS rt_zone_id " +
    "FROM gtfs_stop_times " +
    "INNER JOIN gtfs_stops ON gtfs_stop_times.stop_id=gtfs_stops.stop_id " +
    "INNER JOIN rt_stops_extra ON gtfs_stops.stop_id=rt_stops_extra.stop_id " +
    "WHERE gtfs_stop_times.trip_id='" + tripId + "' " +
    "AND gtfs_stop_times.stop_id='" + stopId + "';";

  // Query the database
  db.get(select, function(err, result) {

    // Database Query Error
    if ( err ) {
      return callback(err);
    }

    // Stop Not Found
    if ( result === undefined ) {
      return callback(null, undefined);
    }

    // Use the stop_name by default unless display_name is set
    let stop_name = result.stop_name;
    if ( result.display_name !== undefined && result.display_name !== null && result.display_name !== "" ) {
      stop_name = result.display_name;
    }

    // Get zone_id from rt_stops_extra if not defined if gtfs_stops
    let zone_id = result.gtfs_zone_id;
    if ( zone_id === null || zone_id === undefined ) {
      zone_id = result.rt_zone_id;
    }

    // Build Stop
    let stop = new Stop(
      result.stop_id,
      stop_name,
      result.stop_lat,
      result.stop_lon,
      {
        code: result.stop_code,
        description: result.stop_desc,
        zoneId: zone_id,
        url: result.stop_url,
        locationType: result.location_type,
        parentStation: result.parent_station,
        timezone: result.stop_timezone,
        wheelchairBoarding: result.wheelchair_boarding,
        statusId: result.status_id,
        transferWeight: result.transfer_weight
      }
    );

    // Build StopTime
    let stopTime = new StopTime(
      stop,
      result.arrival_time,
      result.departure_time,
      result.stop_sequence,
      {
        headsign: result.stop_headsign,
        pickupType: result.pickup_type,
        dropOffType: result.drop_off_type,
        shapeDistanceTraveled: result.shape_dist_traveled,
        timepoint: result.timepoint,
        date: date
      }
    );

    // Add StopTimes to Cache
    cache_stoptimesByTripStop.put(cacheKey, stopTime);

    // Return the StopTimes with the callback
    return callback(null, stopTime);

  });

}
function getStopTimeByTripStop(db, tripId, stopId, date, callback) {

  // Cache Cache for StopTimes
  let cacheKey = db.id + "-" + tripId + "-" + stopId + "-" + date;
  let cache = cache_stoptimesByTripStop.get(cacheKey);
  if ( cache !== null ) {
    return callback(null, cache);
  }

  // Build the select statement
  let select = "SELECT " +
    "gtfs_stop_times.arrival_time, departure_time, stop_sequence, pickup_type, drop_off_type, stop_headsign, shape_dist_traveled, timepoint, " +
    "gtfs_stops.stop_id, stop_name, stop_desc, stop_lat, stop_lon, stop_url, " +
    "gtfs_stops.zone_id AS gtfs_zone_id, stop_code, wheelchair_boarding, location_type, parent_station, stop_timezone, " +
    "rt_stops_extra.status_id, display_name, transfer_weight, rt_stops_extra.zone_id AS rt_zone_id " +
    "FROM gtfs_stop_times " +
    "INNER JOIN gtfs_stops ON gtfs_stop_times.stop_id=gtfs_stops.stop_id " +
    "INNER JOIN rt_stops_extra ON gtfs_stops.stop_id=rt_stops_extra.stop_id " +
    "WHERE gtfs_stop_times.trip_id='" + tripId + "' " +
    "AND gtfs_stop_times.stop_id='" + stopId + "';";

  // Query the database
  db.get(select, function(err, result) {

    // Database Query Error
    if ( err ) {
      return callback(err);
    }

    // Stop Not Found
    if ( result === undefined ) {
      return callback(null, undefined);
    }

    // Use the stop_name by default unless display_name is set
    let stop_name = result.stop_name;
    if ( result.display_name !== undefined && result.display_name !== null && result.display_name !== "" ) {
      stop_name = result.display_name;
    }

    // Get zone_id from rt_stops_extra if not defined if gtfs_stops
    let zone_id = result.gtfs_zone_id;
    if ( zone_id === null || zone_id === undefined ) {
      zone_id = result.rt_zone_id;
    }

    // Build Stop
    let stop = new Stop(
      result.stop_id,
      stop_name,
      result.stop_lat,
      result.stop_lon,
      {
        code: result.stop_code,
        description: result.stop_desc,
        zoneId: zone_id,
        url: result.stop_url,
        locationType: result.location_type,
        parentStation: result.parent_station,
        timezone: result.stop_timezone,
        wheelchairBoarding: result.wheelchair_boarding,
        statusId: result.status_id,
        transferWeight: result.transfer_weight
      }
    );

    // Build StopTime
    let stopTime = new StopTime(
      stop,
      result.arrival_time,
      result.departure_time,
      result.stop_sequence,
      {
        headsign: result.stop_headsign,
        pickupType: result.pickup_type,
        dropOffType: result.drop_off_type,
        shapeDistanceTraveled: result.shape_dist_traveled,
        timepoint: result.timepoint,
        date: date
      }
    );

    // Add StopTimes to Cache
    cache_stoptimesByTripStop.put(cacheKey, stopTime);

    // Return the StopTimes with the callback
    return callback(null, stopTime);

  });

}
function getStopTimeByTripStop ( db , tripId , stopId , date , callback ) { // Cache Cache for StopTimes let cacheKey = db . id + "-" + tripId + "-" + stopId + "-" + date ; let cache = cache_stoptimesByTripStop . get ( cacheKey ) ; if ( cache !== null ) { return callback ( null , cache ) ; } // Build the select statement let select = "SELECT " + "gtfs_stop_times.arrival_time, departure_time, stop_sequence, pickup_type, drop_off_type, stop_headsign, shape_dist_traveled, timepoint, " + "gtfs_stops.stop_id, stop_name, stop_desc, stop_lat, stop_lon, stop_url, " + "gtfs_stops.zone_id AS gtfs_zone_id, stop_code, wheelchair_boarding, location_type, parent_station, stop_timezone, " + "rt_stops_extra.status_id, display_name, transfer_weight, rt_stops_extra.zone_id AS rt_zone_id " + "FROM gtfs_stop_times " + "INNER JOIN gtfs_stops ON gtfs_stop_times.stop_id=gtfs_stops.stop_id " + "INNER JOIN rt_stops_extra ON gtfs_stops.stop_id=rt_stops_extra.stop_id " + "WHERE gtfs_stop_times.trip_id='" + tripId + "' " + "AND gtfs_stop_times.stop_id='" + stopId + "';" ; // Query the database db . get ( select , function ( err , result ) { // Database Query Error if ( err ) { return callback ( err ) ; } // Stop Not Found if ( result === undefined ) { return callback ( null , undefined ) ; } // Use the stop_name by default unless display_name is set let stop_name = result . stop_name ; if ( result . display_name !== undefined && result . display_name !== null && result . display_name !== "" ) { stop_name = result . display_name ; } // Get zone_id from rt_stops_extra if not defined if gtfs_stops let zone_id = result . gtfs_zone_id ; if ( zone_id === null || zone_id === undefined ) { zone_id = result . rt_zone_id ; } // Build Stop let stop = new Stop ( result . stop_id , stop_name , result . stop_lat , result . stop_lon , { code : result . stop_code , description : result . stop_desc , zoneId : zone_id , url : result . stop_url , locationType : result . location_type , parentStation : result . parent_station , timezone : result . stop_timezone , wheelchairBoarding : result . wheelchair_boarding , statusId : result . status_id , transferWeight : result . transfer_weight } ) ; // Build StopTime let stopTime = new StopTime ( stop , result . arrival_time , result . departure_time , result . stop_sequence , { headsign : result . stop_headsign , pickupType : result . pickup_type , dropOffType : result . drop_off_type , shapeDistanceTraveled : result . shape_dist_traveled , timepoint : result . timepoint , date : date } ) ; // Add StopTimes to Cache cache_stoptimesByTripStop . put ( cacheKey , stopTime ) ; // Return the StopTimes with the callback return callback ( null , stopTime ) ; } ) ; }
Get the StopTime for the specified Trip and the
specified Stop from the passed database

@param {RightTrackDB} db The Right Track DB to query
@param {string} tripId Trip ID
@param {string} stopId Stop ID
@param {int} date The date (yyyymmdd) the the Trip operates on
@param {function} callback Callback function
@param {Error} callback.error Database Query Error
@param {StopTime} [callback.stoptime] The selected StopTime
Get the StopTime for the specified Trip and the specified Stop from the passed database