From 0f17b843ab206a4ab1593d4bfb2c9f5ec6b94d8f Mon Sep 17 00:00:00 2001 From: Matthew Wigginton Conway Date: Sun, 2 Oct 2016 14:15:15 -0400 Subject: [PATCH] feat(origins): Extract wait and travel time from new format origin grids. New grids include wait and in-vehicle travel time for each origin. Origin format has changed. --- lib/get-surface.js | 4 ++-- lib/origin.js | 20 ++++++++++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/get-surface.js b/lib/get-surface.js index b762207..f25d077 100644 --- a/lib/get-surface.js +++ b/lib/get-surface.js @@ -1,6 +1,6 @@ import fill from 'lodash.fill' -import {getNonTransitTime} from './origin' +import {getNonTransitTime, ITERATION_WIDTH} from './origin' /** * Get a travel time surface and accessibility results for a particular origin. @@ -43,7 +43,7 @@ export default function getSurface ({origin, query, stopTreeCache, which}) { const time = stopTreeCache.data[stcOffset++] for (let minute = 0; minute < nMinutes; minute++) { - const offset = origin.index[stopId] + minute * 2 // * 2 because path info is included as well + const offset = origin.index[stopId] + minute * ITERATION_WIDTH const travelTimeToStop = origin.data[offset] if (travelTimeToStop !== -1) { diff --git a/lib/origin.js b/lib/origin.js index 5151a9e..3abdd90 100644 --- a/lib/origin.js +++ b/lib/origin.js @@ -10,6 +10,8 @@ * @param {Number} point.y */ +export const ITERATION_WIDTH = 4 + export function create (data, point) { const origin = {} @@ -40,17 +42,23 @@ export function create (data, point) { origin.index[stop] = offset // de delta code times and paths - for (let min = 0, tvlTime = 0, path = 0; min < nMinutes; min++) { - tvlTime += origin.data[offset + min * 2] + for (let min = 0, tvlTime = 0, inVehicleTravelTime = 0, waitTime = 0, path = 0; min < nMinutes; min++) { + tvlTime += origin.data[offset + min * ITERATION_WIDTH] // don't divide -1 (unreachable) by 60 as that will yield 0 (reachable very quickly) - origin.data[offset + min * 2] = tvlTime === -1 ? -1 : tvlTime / 60 | 0 + origin.data[offset + min * ITERATION_WIDTH] = tvlTime + + inVehicleTravelTime += origin.data[offset + min * ITERATION_WIDTH + 1] + origin.data[offset + min * ITERATION_WIDTH + 1] = inVehicleTravelTime + + waitTime += origin.data[offset + min * ITERATION_WIDTH + 2] + origin.data[offset + min * ITERATION_WIDTH + 2] = waitTime - path += origin.data[offset + min * 2 + 1] - origin.data[offset + min * 2 + 1] = path + path += origin.data[offset + min * ITERATION_WIDTH + 3] + origin.data[offset + min * ITERATION_WIDTH + 1] = path } // skip the times - offset += nMinutes * 2 + offset += nMinutes * ITERATION_WIDTH // read paths let nPaths = data[offset++]