Skip to content

Commit

Permalink
feat(origins): Extract wait and travel time from new format origin gr…
Browse files Browse the repository at this point in the history
…ids.

New grids include wait and in-vehicle travel time for each origin.

Origin format has changed.
  • Loading branch information
mattwigway committed Oct 2, 2016
1 parent 08363e8 commit 0f17b84
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
4 changes: 2 additions & 2 deletions lib/get-surface.js
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 14 additions & 6 deletions lib/origin.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* @param {Number} point.y
*/

export const ITERATION_WIDTH = 4

export function create (data, point) {
const origin = {}

Expand Down Expand Up @@ -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++]
Expand Down

0 comments on commit 0f17b84

Please sign in to comment.