lib/operations.js
function updateInterpolatedTimes (cfg, callback) {
  const db = cfg.db
  const lastTimepoint = cfg.lastTimepoint
  const nextTimepoint = cfg.nextTimepoint
  const timeDiff = nextTimepoint.arrival_time - lastTimepoint.departure_time
  let literal
  // sqlite null is a string
  if (nextTimepoint.shape_dist_traveled && nextTimepoint.shape_dist_traveled !== 'NULL') {
    // calculate interpolation based off of distance ratios
    const distanceTraveled = nextTimepoint.shape_dist_traveled - lastTimepoint.shape_dist_traveled
    literal = `${lastTimepoint.departure_time} +
      ${timeDiff} *
      (shape_dist_traveled - ${lastTimepoint.shape_dist_traveled}) /
      ${distanceTraveled}`
  } else {
    // calculate interpolation based off of stop sequence ratios
    const numStopsPassed = nextTimepoint.stop_sequence - lastTimepoint.stop_sequence
    literal = `${lastTimepoint.departure_time} +
      ${timeDiff} *
      (stop_sequence - ${lastTimepoint.stop_sequence}) /
      ${numStopsPassed}`
  }
  const updateLiteral = db.sequelize.literal(literal)
  db.stop_time
    .update(
      {
        arrival_time: updateLiteral,
        departure_time: updateLiteral
      },
      {
        where: {
          trip_id: lastTimepoint.trip_id,
          stop_sequence: {
            $gt: lastTimepoint.stop_sequence,
            $lt: nextTimepoint.stop_sequence
          }
        }
      }
    )
    .then(() => {
      callback()
    })
    .catch(callback)
}
function updateInterpolatedTimes (cfg, callback) {
  const db = cfg.db
  const lastTimepoint = cfg.lastTimepoint
  const nextTimepoint = cfg.nextTimepoint
  const timeDiff = nextTimepoint.arrival_time - lastTimepoint.departure_time
  let literal
  // sqlite null is a string
  if (nextTimepoint.shape_dist_traveled && nextTimepoint.shape_dist_traveled !== 'NULL') {
    // calculate interpolation based off of distance ratios
    const distanceTraveled = nextTimepoint.shape_dist_traveled - lastTimepoint.shape_dist_traveled
    literal = `${lastTimepoint.departure_time} +
      ${timeDiff} *
      (shape_dist_traveled - ${lastTimepoint.shape_dist_traveled}) /
      ${distanceTraveled}`
  } else {
    // calculate interpolation based off of stop sequence ratios
    const numStopsPassed = nextTimepoint.stop_sequence - lastTimepoint.stop_sequence
    literal = `${lastTimepoint.departure_time} +
      ${timeDiff} *
      (stop_sequence - ${lastTimepoint.stop_sequence}) /
      ${numStopsPassed}`
  }
  const updateLiteral = db.sequelize.literal(literal)
  db.stop_time
    .update(
      {
        arrival_time: updateLiteral,
        departure_time: updateLiteral
      },
      {
        where: {
          trip_id: lastTimepoint.trip_id,
          stop_sequence: {
            $gt: lastTimepoint.stop_sequence,
            $lt: nextTimepoint.stop_sequence
          }
        }
      }
    )
    .then(() => {
      callback()
    })
    .catch(callback)
}
function updateInterpolatedTimes ( cfg , callback ) { const db = cfg . db const lastTimepoint = cfg . lastTimepoint const nextTimepoint = cfg . nextTimepoint const timeDiff = nextTimepoint . arrival_time - lastTimepoint . departure_time let literal // sqlite null is a string if ( nextTimepoint . shape_dist_traveled && nextTimepoint . shape_dist_traveled !== 'NULL' ) { // calculate interpolation based off of distance ratios const distanceTraveled = nextTimepoint . shape_dist_traveled - lastTimepoint . shape_dist_traveled literal = ` ${ lastTimepoint . departure_time } ${ timeDiff } ${ lastTimepoint . shape_dist_traveled } ${ distanceTraveled } ` } else { // calculate interpolation based off of stop sequence ratios const numStopsPassed = nextTimepoint . stop_sequence - lastTimepoint . stop_sequence literal = ` ${ lastTimepoint . departure_time } ${ timeDiff } ${ lastTimepoint . stop_sequence } ${ numStopsPassed } ` } const updateLiteral = db . sequelize . literal ( literal ) db . stop_time . update ( { arrival_time : updateLiteral , departure_time : updateLiteral } , { where : { trip_id : lastTimepoint . trip_id , stop_sequence : { $gt : lastTimepoint . stop_sequence , $lt : nextTimepoint . stop_sequence } } } ) . then ( ( ) => { callback ( ) } ) . catch ( callback ) }
Make an update query to the db to set the interpolated times in
a particular range of a particular trip
Make an update query to the db to set the interpolated times in a particular range of a particular trip