modules/search/search.js
function _processTrips(db, options, origin, destination, enter, trips, segments, callback) {

  // Display function logs
  _info();

  // Results to Return
  let RESULTS = [];


  // Set up counters
  let done = 0;
  let count = trips.length;


  // Finish when there are no trips to process
  if ( trips.length === 0 ) {
    _finish();
  }

  // Process each of the Trips
  for ( let i = 0; i < trips.length; i++ ) {
    _processTrip(db, options, origin, destination, enter, trips[i], segments, function(err, results) {

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

      // Add Results to final list
      RESULTS = RESULTS.concat(results);

      // Finish
      _finish();

    })
  }


  /**
   * Finished Processing the Trips
   * @private
   */
  function _finish() {
    done++;
    if ( count === 0 || done === count ) {
      return callback(null, RESULTS);
    }
  }

  /**
   * Display function logging info
   * @private
   */
  function _info() {
    if ( LOG ) {
      let p = "";
      for ( let i = 0; i < segments.length * 2; i++ ) {
        p = p + " ";
      }

      let tripIds = [];
      for ( let i = 0; i < trips.length; i++ ) {
        tripIds.push(trips[i].id);
      }
      _log(p + "Trips From " + enter.name + ": " + trips.length + " ('" + tripIds.join("', '") + "')");

      _log(p + "   Segments: " + segments.length);
      _printSegments(segments, p + "   ");
    }
  }

}
function _processTrips(db, options, origin, destination, enter, trips, segments, callback) {

  // Display function logs
  _info();

  // Results to Return
  let RESULTS = [];


  // Set up counters
  let done = 0;
  let count = trips.length;


  // Finish when there are no trips to process
  if ( trips.length === 0 ) {
    _finish();
  }

  // Process each of the Trips
  for ( let i = 0; i < trips.length; i++ ) {
    _processTrip(db, options, origin, destination, enter, trips[i], segments, function(err, results) {

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

      // Add Results to final list
      RESULTS = RESULTS.concat(results);

      // Finish
      _finish();

    })
  }


  /**
   * Finished Processing the Trips
   * @private
   */
  function _finish() {
    done++;
    if ( count === 0 || done === count ) {
      return callback(null, RESULTS);
    }
  }

  /**
   * Display function logging info
   * @private
   */
  function _info() {
    if ( LOG ) {
      let p = "";
      for ( let i = 0; i < segments.length * 2; i++ ) {
        p = p + " ";
      }

      let tripIds = [];
      for ( let i = 0; i < trips.length; i++ ) {
        tripIds.push(trips[i].id);
      }
      _log(p + "Trips From " + enter.name + ": " + trips.length + " ('" + tripIds.join("', '") + "')");

      _log(p + "   Segments: " + segments.length);
      _printSegments(segments, p + "   ");
    }
  }

}
function _processTrips ( db , options , origin , destination , enter , trips , segments , callback ) { // Display function logs _info ( ) ; // Results to Return let RESULTS = [ ] ; // Set up counters let done = 0 ; let count = trips . length ; // Finish when there are no trips to process if ( trips . length === 0 ) { _finish ( ) ; } // Process each of the Trips for ( let i = 0 ; i < trips . length ; i ++ ) { _processTrip ( db , options , origin , destination , enter , trips [ i ] , segments , function ( err , results ) { // Database Query Error if ( err ) { return callback ( err ) ; } // Add Results to final list RESULTS = RESULTS . concat ( results ) ; // Finish _finish ( ) ; } ) } /**
   * Finished Processing the Trips
   * @private
   */ function _finish ( ) { done ++ ; if ( count === 0 || done === count ) { return callback ( null , RESULTS ) ; } } /**
   * Display function logging info
   * @private
   */ function _info ( ) { if ( LOG ) { let p = "" ; for ( let i = 0 ; i < segments . length * 2 ; i ++ ) { p = p + " " ; } let tripIds = [ ] ; for ( let i = 0 ; i < trips . length ; i ++ ) { tripIds . push ( trips [ i ] . id ) ; } _log ( p + "Trips From " + enter . name + ": " + trips . length + " ('" + tripIds . join ( "', '" ) + "')" ) ; _log ( p + "   Segments: " + segments . length ) ; _printSegments ( segments , p + "   " ) ; } } }
Process a group of Trips from the reference Stop
@param {RightTrackDB} db The Right Track DB to query
@param {Object} options Trip Search Options
@param {Stop} origin Trip Search Origin Stop
@param {Stop} destination Trip Search Destination Stop
@param {Stop} enter Reference/Entry Stop
@param {Trip[]} trips List of Trips to process
@param {TripSearchResultSegment[]} segments Previously added Trip Search Result Segments
@param {function} callback Callback function(err, results)
@private
Process a group of Trips from the reference Stop