2016-09-19 17:13:44 -04:00
|
|
|
'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');
|
2016-03-04 15:11:05 -05:00
|
|
|
|
|
|
|
module.exports = function () {
|
2016-09-19 17:13:44 -04:00
|
|
|
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);
|
2016-03-04 15:11:05 -05:00
|
|
|
});
|
|
|
|
|
2016-09-19 17:13:44 -04:00
|
|
|
this.BeforeFeature((feature, callback) => {
|
2017-09-18 10:18:07 -04:00
|
|
|
this.profile = this.OSRM_PROFILE || this.DEFAULT_PROFILE;
|
2016-09-19 17:13:44 -04:00
|
|
|
this.profileFile = path.join(this.PROFILES_PATH, this.profile + '.lua');
|
|
|
|
this.setupFeatureCache(feature);
|
|
|
|
callback();
|
|
|
|
});
|
2016-03-04 15:11:05 -05:00
|
|
|
|
2016-09-19 17:13:44 -04:00
|
|
|
this.Before((scenario, callback) => {
|
|
|
|
this.osrmLoader.setLoadMethod(this.DEFAULT_LOAD_METHOD);
|
2016-03-04 15:11:05 -05:00
|
|
|
this.setGridSize(this.DEFAULT_GRID_SIZE);
|
|
|
|
this.setOrigin(this.DEFAULT_ORIGIN);
|
2016-09-19 17:13:44 -04:00
|
|
|
this.queryParams = {};
|
|
|
|
this.extractArgs = '';
|
|
|
|
this.contractArgs = '';
|
2017-03-11 03:26:12 -05:00
|
|
|
this.partitionArgs = '';
|
|
|
|
this.customizeArgs = '';
|
2016-09-19 17:13:44 -04:00
|
|
|
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';
|
2018-01-24 11:30:26 -05:00
|
|
|
console.log(this.scenarioLogFile);
|
2016-09-19 17:13:44 -04:00
|
|
|
d3.queue(1)
|
|
|
|
.defer(mkdirp, logDir)
|
|
|
|
.defer(rimraf, this.scenarioLogFile)
|
|
|
|
.awaitAll(callback);
|
2016-03-04 15:11:05 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
this.After((scenario, callback) => {
|
2016-09-19 17:13:44 -04:00
|
|
|
this.resetOptionsOutput();
|
|
|
|
callback();
|
|
|
|
});
|
|
|
|
|
|
|
|
this.AfterFeatures((features, callback) => {
|
|
|
|
callback();
|
2016-03-04 15:11:05 -05:00
|
|
|
});
|
|
|
|
};
|