Skip to content

Commit

Permalink
Merge pull request #252 from WorldBank-Transport/develop
Browse files Browse the repository at this point in the history
Deploy v0.8.3
  • Loading branch information
olafveerman authored Apr 3, 2019
2 parents 583e3ad + a745711 commit acfc0b7
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 15 deletions.
7 changes: 7 additions & 0 deletions app/db/structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,8 @@ export function createResultsTable () {
table.foreign('project_aa_id')
.references('projects_aa.id')
.onDelete('CASCADE');

table.index(['project_id', 'scenario_id']);
});
}

Expand All @@ -241,6 +243,8 @@ export function createResultsPoiTable () {
.onDelete('CASCADE');
table.string('type');
table.integer('time');

table.index('type');
});
}

Expand All @@ -254,6 +258,7 @@ export function createProjectsOriginsTable () {
.onDelete('CASCADE');
table.string('name');
table.json('coordinates');

table.index('project_id');
});
}
Expand All @@ -269,7 +274,9 @@ export function createProjectsOriginsIndicatorsTable () {
table.string('key');
table.string('label');
table.integer('value');

table.index('origin_id');
table.index('key');
});
}

Expand Down
2 changes: 1 addition & 1 deletion app/routes/scenarios--results.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ async function checkPopInd (projId, popInd) {
}

function prepGeoResponse (results) {
let maxPop = Math.max.apply(Math, results.map(o => o.pop_value));
const maxPop = results.reduce((acc, o) => Math.max(acc, o.pop_value), 0);

return results.map(o => {
return {
Expand Down
8 changes: 5 additions & 3 deletions app/services/project-setup/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export class ProjectEventEmitter extends EventEmitter {
/**
* Resolves a promise once all the events fired once.
* The promise is resolved with an object keyed by the event name containing
* the result of each event.
* the result of each event. The results of each event will be an array, even
* if the emit method was called just with one argument.
* As soon as the method is called, it checks if the events were already emitted
* and if so, resolves them immediately preventing "waiting for Godot"
*
Expand Down Expand Up @@ -61,8 +62,9 @@ export class ProjectEventEmitter extends EventEmitter {
results[e] = this.emitted[e];
if (++completed === events.length) resolve(results);
} else {
this.once(e, (result = null) => {
results[e] = result;
// Setup a once listener that gets all the passed arguments.
this.once(e, (...args) => {
results[e] = args;
if (++completed === events.length) resolve(results);
});
}
Expand Down
4 changes: 2 additions & 2 deletions app/services/project-setup/poi.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ export default async function (projId, scId, {op, emitter, logger, appLogger}) {
// If importing from OSM we need to wait for the admin bounds.
const result = await emitter.waitForEvents('admin-bounds:data');
logger && logger.log('poi is waiting for events (admin-bounds:data)... done');
const adminBoundsFc = result['admin-bounds:data'];
const [adminBoundsFc] = result['admin-bounds:data'];
poisData = await importOSMPOIs(projId, scId, overpass.fcBbox(adminBoundsFc), source.data.osmPoiTypes, op, logger);
}

// Wait for the road network to know if edition is enabled or not.
logger && logger.log('poi is waiting for events (road-network:active-editing)...');
const result = await emitter.waitForEvents('road-network:active-editing');
logger && logger.log('poi is waiting for events (road-network:active-editing)... done');
const allowImport = result['road-network:active-editing'];
const [allowImport] = result['road-network:active-editing'];

if (allowImport) {
// Merge all feature collection together.
Expand Down
2 changes: 1 addition & 1 deletion app/services/project-setup/project-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ export async function concludeProjectSetup (e) {
try {
await op.finish('error', {error: err.message});
} catch (e) { /* no-action */ }
callback(err.message);
callback(err);
}
}
2 changes: 1 addition & 1 deletion app/services/project-setup/road-network.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export default async function (projId, scId, {op, emitter, logger, appLogger}) {
// If importing from OSM we need to wait for the admin bounds.
const result = await emitter.waitForEvents('admin-bounds:data');
logger && logger.log('road-network is waiting for events (admin-bounds:data)... done');
const adminBoundsFc = result['admin-bounds:data'];
const [adminBoundsFc] = result['admin-bounds:data'];
fileData = await importOSMRoadNetwork(projId, scId, overpass.fcBbox(adminBoundsFc), op, logger);
}

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ram-backend",
"version": "0.8.2",
"version": "0.8.3",
"description": "The backend for RAM, a World Bank project to assess rural road accessibility",
"repository": {
"type": "git",
Expand Down
14 changes: 10 additions & 4 deletions test/test-scenarios-results.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';
import { assert } from 'chai';
import _ from 'lodash';

import initServer from '../app/services/server';
import { setupStructure as setupDdStructure } from '../app/db/structure';
Expand Down Expand Up @@ -37,7 +38,9 @@ describe('Scenario results', function () {
url: '/projects/2000/scenarios/2000/results/geo?poiType=school&popInd=population'
}).then(res => {
assert.equal(res.statusCode, 200, 'Status code is 200');
let origins = res.result;
// It is not important fot the query result to be sorted, but we need
// to ensure order for the tests.
let origins = _.sortBy(res.result, 'i');
assert.equal(origins.length, 3);
assert.deepEqual(origins[0], {
'n': 'Paripiranga',
Expand All @@ -55,17 +58,20 @@ describe('Scenario results', function () {
url: '/projects/2000/scenarios/2000/results/geo?poiType=church&popInd=population'
}).then(res => {
assert.equal(res.statusCode, 200, 'Status code is 200');
let origins = res.result;
// It is not important fot the query result to be sorted, but we need
// to ensure order for the tests.
let origins = _.sortBy(res.result, 'i');
assert.equal(origins.length, 2);
assert.equal(origins[1].e, 350000);
});
});
it.skip('should return an error for unknown POI types', function () {
it('should return an error for unknown POI types', function () {
return instance.injectThen({
method: 'GET',
url: '/projects/2000/scenarios/2000/results/geo?poiType=mockery&popInd=population'
}).then(res => {
assert.equal(res.statusCode, 500, 'Internal Server Error');
assert.equal(res.statusCode, 400, 'Status code is 400');
assert.equal(res.result.message, '"poiType" must be one of [church, school]');
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions test/test-services-project-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ describe('Finish Project Setup', function () {
scId: 3000,
callback: (err) => {
if (err) {
done(new Error('The script ended in error ' + err));
done(err);
} else {
validate();
}
Expand Down Expand Up @@ -185,7 +185,7 @@ describe('Finish Project Setup', function () {
.where('operation_id', op.getId())
.orderBy('created_at', 'desc')
.then(logs => {
assert.equal(err, 'Invalid administrative boundaries file');
assert.equal(err.message, 'Invalid administrative boundaries file');
assert.equal(logs[0].code, 'error');
assert.equal(logs[0].data.error, 'Invalid administrative boundaries file');
})
Expand Down

0 comments on commit acfc0b7

Please sign in to comment.