osrm-backend/features/support/hooks.js
Huyen Chau Nguyen 61e06fcaba
Making the turn function more flexible (#4789)
* set and store highway and access classification for the turn function
* expose highway turn classification and access turn classification and speed to the lua profile turn function
* expose whether connection road at turn is incoming or outgoing
* add lua tests for exposed information to turn function
* update docs about attributes in process_turn
* add turn_classification info to docs
* adding warning if uturn and intersection dont match
* handle u turns that do not turn into intersection[0]
* split OSM link generation in an accessible coordinate function
2018-01-24 15:39:55 -05:00

66 lines
2.2 KiB
JavaScript

'use strict';
var d3 = require('d3-queue');
var path = require('path');
var mkdirp = require('mkdirp');
var rimraf = require('rimraf');
var OSM = require('../lib/osm');
var OSRMLoader = require('../lib/osrm_loader');
module.exports = function () {
this.registerHandler('BeforeFeatures', {timeout: 30000}, (features, callback) => {
this.osrmLoader = new OSRMLoader(this);
this.OSMDB = new OSM.DB();
let queue = d3.queue(1);
queue.defer(this.initializeEnv.bind(this));
queue.defer(this.verifyOSRMIsNotRunning.bind(this));
queue.defer(this.verifyExistenceOfBinaries.bind(this));
queue.defer(this.initializeCache.bind(this));
queue.defer(this.setupFeatures.bind(this, features));
queue.awaitAll(callback);
});
this.BeforeFeature((feature, callback) => {
this.profile = this.OSRM_PROFILE || this.DEFAULT_PROFILE;
this.profileFile = path.join(this.PROFILES_PATH, this.profile + '.lua');
this.setupFeatureCache(feature);
callback();
});
this.Before((scenario, callback) => {
this.osrmLoader.setLoadMethod(this.DEFAULT_LOAD_METHOD);
this.setGridSize(this.DEFAULT_GRID_SIZE);
this.setOrigin(this.DEFAULT_ORIGIN);
this.queryParams = {};
this.extractArgs = '';
this.contractArgs = '';
this.partitionArgs = '';
this.customizeArgs = '';
this.environment = Object.assign(this.DEFAULT_ENVIRONMENT);
this.resetOSM();
this.scenarioID = this.getScenarioID(scenario);
this.setupScenarioCache(this.scenarioID);
// setup output logging
let logDir = path.join(this.LOGS_PATH, this.featureID);
this.scenarioLogFile = path.join(logDir, this.scenarioID) + '.log';
d3.queue(1)
.defer(mkdirp, logDir)
.defer(rimraf, this.scenarioLogFile)
.awaitAll(callback);
// uncomment to get path to logfile
// console.log(" Writing logging output to " + this.scenarioLogFile)
});
this.After((scenario, callback) => {
this.resetOptionsOutput();
callback();
});
this.AfterFeatures((features, callback) => {
callback();
});
};