forked from sharedstreets/mobility-metrics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b27dc34
commit 40d0e18
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
const fs = require("fs"); | ||
const turf = require("@turf/turf"); | ||
const shst = require("sharedstreets"); | ||
const tripMatch = require("./src/matchers/trip"); | ||
const changeMatch = require("./src/matchers/change"); | ||
const config = require("./test/fixtures/cli/config.json"); | ||
const cover = require("@mapbox/tile-cover"); | ||
|
||
const z = 19; | ||
const zs = { min_zoom: z, max_zoom: z }; | ||
|
||
async function bench() { | ||
config.zones.features = config.zones.features.map(zone => { | ||
zone.properties.keys = {}; | ||
cover.indexes(zone.geometry, zs).forEach(key => { | ||
zone.properties.keys[key] = 1; | ||
}); | ||
return zone; | ||
}); | ||
|
||
const envelope = turf.bboxPolygon(config.boundary).geometry; | ||
const graphOpts = { | ||
source: "osm/planet-181224", | ||
tileHierarchy: 6 | ||
}; | ||
var graph = new shst.Graph(envelope, graphOpts); | ||
await graph.buildGraph(); | ||
|
||
const trips = fs | ||
.readFileSync("./example/data/Spuun/trips.json") | ||
.toString() | ||
.split("\n") | ||
.filter(l => { | ||
return l.length; | ||
}) | ||
.map(JSON.parse); | ||
|
||
const changes = fs | ||
.readFileSync("./example/data/Spuun/changes.json") | ||
.toString() | ||
.split("\n") | ||
.filter(l => { | ||
return l.length; | ||
}) | ||
.map(JSON.parse); | ||
|
||
var start = new Date().getTime(); | ||
|
||
var count = 0 | ||
|
||
for (let trip of trips) { | ||
count++ | ||
await tripMatch(trip, config, graph); | ||
} | ||
|
||
var stop = new Date().getTime(); | ||
|
||
console.log('trip match avg: ' + ((stop - start) / count).toFixed(4) + 'ms'); | ||
count = 0 | ||
start = new Date().getTime(); | ||
|
||
for (let change of changes) { | ||
count++ | ||
await changeMatch(change, config, graph); | ||
} | ||
|
||
stop = new Date().getTime(); | ||
console.log('change match avg: ' + ((stop - start) / count).toFixed(4) + 'ms'); | ||
} | ||
|
||
bench(); |