Skip to content

Commit

Permalink
Migrate OSRM settings from preferences to server.config
Browse files Browse the repository at this point in the history
Fix: #1084
  • Loading branch information
GabrielBruno24 committed Oct 23, 2024
1 parent ed91875 commit 8551222
Show file tree
Hide file tree
Showing 11 changed files with 378 additions and 221 deletions.
178 changes: 87 additions & 91 deletions examples/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,27 +18,94 @@ module.exports = {
// trRoutingCacheAllScenarios: false,
// Configuration for the trRouting services. Single is for the single calculation instance (from the UI and public API), while batch is for the batch calculation instance, for tasks
// routing: {
// transit: {
// defaultEngine: 'trRouting',
// engines: {
// trRouting: {
// single: {
// port: 4000,
// // Enable caching of connections for all scenarios in trRouting. Will use more memory
// cacheAllScenarios: false,
// debug: false,
// logs: { maxFileSizeKB: 5120, nbFiles: 3 }
// },
// batch: {
// port: 14000,
// // Enable caching of connections for all scenarios in trRouting. Will use more memory and may not be necessary for batch calculations as currently there's only one scenario per task
// cacheAllScenarios: false,
// debug: false,
// logs: { maxFileSizeKB: 5120, nbFiles: 3 }
// transit: {
// defaultEngine: 'trRouting',
// engines: {
// trRouting: {
// single: {
// port: 4000,
// // Enable caching of connections for all scenarios in trRouting. Will use more memory
// cacheAllScenarios: false,
// debug: false,
// logs: { maxFileSizeKB: 5120, nbFiles: 3 }
// },
// batch: {
// port: 14000,
// // Enable caching of connections for all scenarios in trRouting. Will use more memory and may not be necessary for batch calculations as currently there's only one scenario per task
// cacheAllScenarios: false,
// debug: false,
// logs: { maxFileSizeKB: 5120, nbFiles: 3 }
// }
// }
// }
// }
// }
// }
// },
// // Configuration for the osrm modes
// driving: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 7000, host: null, autoStart: true, enabled: true }
// }
// },
// cycling: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 8000, host: null, autoStart: true, enabled: true }
// }
// },
// walking: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 5001, host: null, autoStart: true, enabled: true }
// }
// },
// bus_suburb: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 7110, host: null, autoStart: true, enabled: true }
// }
// },
// bus_urban: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 7120, host: null, autoStart: true, enabled: true }
// }
// },
// rail: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 9000, host: null, autoStart: false, enabled: false }
// }
// },
// tram: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 9100, host: null, autoStart: false, enabled: false }
// }
// },
// tram_train: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 9200, host: null, autoStart: false, enabled: false }
// }
// },
// metro: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 9300, host: null, autoStart: false, enabled: false }
// }
// },
// monorail: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 9400, host: null, autoStart: false, enabled: false }
// }
// },
// cable_car: {
// defaultEngine: 'osrmRouting',
// engines: {
// osrmRouting: { port: 9500, host: null, autoStart: false, enabled: false }
// }
// },
// },

mapDefaultCenter: {
Expand Down Expand Up @@ -78,77 +145,6 @@ module.exports = {
},

defaultPreferences: {
osrmRouting: {
modes: {
driving: {
// !!! Be careful: use your own server, since you may be blocked on the osrm demo server after too many queries
port : 7000, // Port used to access OSRM, either locally or remotely
host : null, // If set to null, localhost will be used. Ignored if autoStart set to true
autoStart: true, // If true, a local instance of OSRM will be started
enabled : true // If true, this mode will be configured, otherwise will be left out
},
cycling: {
port : 8000,
host : null,
autoStart: true,
enabled : true
},
walking: {
port : 5001,
host : null,
autoStart: true,
enabled : true
},
bus_suburb: {
port : 7110,
host : null,
autoStart: true,
enabled : true
},
bus_urban: {
port : 7120,
host : null,
autoStart: true,
enabled : true
},
rail: {
port : 9000,
host : null,
autoStart: false,
enabled : false
},
tram: {
port : 9100,
host : null,
autoStart: false,
enabled : false
},
tram_train: {
port : 9200,
host : null,
autoStart: false,
enabled : false
},
metro: {
port : 9300,
host : null,
autoStart: false,
enabled : false
},
monorail: {
port : 9400,
host : null,
autoStart: false,
enabled : false
},
cable_car: {
port : 9500,
host : null,
autoStart: false,
enabled : false
}
}
},
transit: {
routing: {
batch: {
Expand Down
11 changes: 11 additions & 0 deletions packages/chaire-lib-backend/src/config/ServerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ class ServerConfig {
}
return engineConfiguration[instance] || { port: 4000, cacheAllScenarios: false };
};

getAllModesForEngine = (engine: string): string[] => {
const modesForEngine: string[] = [];
for (const modeName in config.routing) {
if (config.routing[modeName].engines[engine] !== undefined) {
modesForEngine.push(modeName);
}
}

return modesForEngine;
};
}

const instance = new ServerConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('get routing mode and engine configs', () => {
});

test('getRoutingModeConfig, mode does not exist', () => {
expect(ServerConfig.getRoutingModeConfig('walking')).toBeUndefined();
expect(ServerConfig.getRoutingModeConfig('walking_way_data_as_name')).toBeUndefined();
});

test('getRoutingEngineConfigForMode, mode and engine exist', () => {
Expand All @@ -52,7 +52,29 @@ describe('get routing mode and engine configs', () => {
});

test('getRoutingEngineConfigForMode, mode does not exist', () => {
expect(ServerConfig.getRoutingEngineConfigForMode('walking', 'osrm')).toBeUndefined();
expect(ServerConfig.getRoutingEngineConfigForMode('walking_way_data_as_name', 'osrmRouting')).toBeUndefined();
});

test('getAllModesForEngine, engine exists', () => {
expect(ServerConfig.getAllModesForEngine('trRouting')).toEqual(['transit']);
expect(ServerConfig.getAllModesForEngine('osrmRouting')).toEqual([
'driving',
'driving_congestion',
'cycling',
'walking',
'bus_suburb',
'bus_urban',
'bus_congestion',
'rail',
'tram',
'tram_train',
'metro',
'monorail',
'cable_car'
]);
});

test('getAllModesForEngine, engine does not exist', () => {
expect(ServerConfig.getAllModesForEngine('valhalla')).toEqual([]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ test('Expected default with env', () => {
expect(config.projectDirectory).toEqual(path.normalize(`${__dirname}/../../../../../tests/dir`));
expect(config.routing.transit.engines.trRouting!.single).toEqual({ port: 4000, cacheAllScenarios: false, debug: false, logs: { nbFiles: 3, maxFileSizeKB: 5120 } });
expect(config.routing.transit.engines.trRouting!.batch).toEqual({ port: 14000, cacheAllScenarios: false, debug: false, logs: { nbFiles: 3, maxFileSizeKB: 5120 }});
expect(config.routing.driving!.engines.osrmRouting).toEqual({ port: 7000, osrmPath: null, autoStart: true, enabled: true });
});

test('setProjectConfiguration', () => {
Expand All @@ -28,6 +29,12 @@ test('setProjectConfiguration', () => {
engines: {
trRouting: { single: { port: 5000 }, batch: { logs: { maxFileSizeKB: 10000 } } } as any
}
},
driving: {
defaultEngine: 'osrmRouting',
engines: {
osrmRouting: { port: 1234, enabled: false } as any
}
}
}
});
Expand All @@ -37,4 +44,5 @@ test('setProjectConfiguration', () => {
// Make sure the deep merge works for object configs
expect(config.routing.transit.engines.trRouting!.single).toEqual({ port: 5000, cacheAllScenarios: false, debug: false, logs: { nbFiles: 3, maxFileSizeKB: 5120 } });
expect(config.routing.transit.engines.trRouting!.batch).toEqual({ port: 14000, cacheAllScenarios: false, debug: false, logs: { nbFiles: 3, maxFileSizeKB: 10000 } });
expect(config.routing.driving!.engines.osrmRouting).toEqual({ port: 1234, osrmPath: null, autoStart: true, enabled: false });
});
Loading

0 comments on commit 8551222

Please sign in to comment.