|
|
@@ -24,6 +24,7 @@ const _ontologyFilePath = 'data/rural_attractiveness.owl.json';
|
|
|
var _datasetsEU = undefined;
|
|
|
var _datasetsCZ = undefined;
|
|
|
var _datasetsAfrica = undefined;
|
|
|
+var _ontology = undefined;
|
|
|
var _ruralDataEU = undefined;
|
|
|
var _ruralDataCZ = undefined;
|
|
|
var _ruralDataAfrica = undefined;
|
|
|
@@ -48,10 +49,10 @@ app.get('/refresh', async (req, res, next) => {
|
|
|
try {
|
|
|
_datasetsEU = await nutsData.loadDatasets(_dataEuFilePath)
|
|
|
_datasetsCZ = await nutsData.loadDatasets(_dataCzFilePath)
|
|
|
- //console.log('Datasets loaded succesfully');
|
|
|
+ //console.log('Datasets loaded successfully');
|
|
|
_ruralDataEU = await nutsData.loadRuralData(_dataEuFilePath)
|
|
|
_ruralDataCZ = await nutsData.loadRuralData(_dataCzFilePath)
|
|
|
- //console.log('Rural data loaded succesfully');
|
|
|
+ //console.log('Rural data loaded successfully');
|
|
|
} catch (e) {
|
|
|
res.send(e.toString() || e)
|
|
|
}
|
|
|
@@ -93,7 +94,7 @@ app.get('/:aoi?/scores', async (req, res, next) => {
|
|
|
});
|
|
|
|
|
|
/* Computes and returns attractivity data for all the NUTS regions based on the
|
|
|
- incomming datasets and factor weights. */
|
|
|
+ incoming datasets and factor weights. */
|
|
|
app.post('/:aoi?/scores', async (req, res, next) => {
|
|
|
//console.log("query: " + JSON.stringify(req.body.factors, null, 4));
|
|
|
const aoi = req.params.aoi || 'eu'
|
|
|
@@ -193,27 +194,22 @@ app.post('/:aoi?/clusters/', async (req, res, next) => {
|
|
|
* This ensures that both backend and frontend are using the same version of the ontology
|
|
|
*/
|
|
|
app.get('/ontology/', async (req, res, next) => {
|
|
|
- const onto = await nutsData.loadOntology(_ontologyFilePath)
|
|
|
- helpers.formatResponse(onto, req, res)
|
|
|
+ if (!_ontology) {
|
|
|
+ _ontology = await nutsData.loadOntology(_ontologyFilePath)
|
|
|
+ }
|
|
|
+ helpers.formatResponse(_ontology, req, res)
|
|
|
});
|
|
|
|
|
|
-//FIXME: use ontology to read datasets metadata // CURRENTLY BROKEN
|
|
|
+/*
|
|
|
+ * Render georeport for a given region. Currently only available for EU/EEA
|
|
|
+*/
|
|
|
app.get('/georeport/:nuts', async (req, res, next) => {
|
|
|
- if (!_datasetsEU) { // datasets must be loaded prior to data loading
|
|
|
- try {
|
|
|
- _datasetsEU = await nutsData.loadDatasets(_dataEuFilePath)
|
|
|
- } catch (e) {
|
|
|
- res.send(e.toString() || e)
|
|
|
- }
|
|
|
+ await loadDatasetsIfNeeded(req, res, 'eu')
|
|
|
+ await loadRuralDataIfNeeded(req, res, 'eu')
|
|
|
+ if (!_ontology) {
|
|
|
+ _ontology = await nutsData.loadOntology(_ontologyFilePath)
|
|
|
}
|
|
|
- if (!_ruralDataEU) {
|
|
|
- try {
|
|
|
- _ruralDataEU = await nutsData.loadRuralData(_dataEuFilePath)
|
|
|
- } catch (e) {
|
|
|
- res.send(e.toString() || e)
|
|
|
- }
|
|
|
- }
|
|
|
- renderPugReport(req.params.nuts, req, res);
|
|
|
+ renderPugReport(req.params.nuts, req, res)
|
|
|
});
|
|
|
|
|
|
// start the service on the port xxxx
|
|
|
@@ -221,24 +217,21 @@ app.listen(3000, () => console.log('Rural attractivity WS listening on port 3000
|
|
|
|
|
|
|
|
|
function renderPugReport(nuts, req, res) {
|
|
|
- let found = false;
|
|
|
+ const dsMetadata = nutsData.parseDatasetsMetadata(_ontology)
|
|
|
|
|
|
+ let found = false;
|
|
|
_ruralDataEU.forEach(region => {
|
|
|
if (region.nuts == nuts) {
|
|
|
-
|
|
|
let nutsGeoJson = helpers.loadJSON('static/NUTS3_4326.json');
|
|
|
- let filterednutsGeoJson = where(nutsGeoJson.features, { "properties": { "NUTS_ID": nuts } });
|
|
|
+ let filteredNutsGeoJson = where(nutsGeoJson.features, { "properties": { "NUTS_ID": nuts } });
|
|
|
let pilots = helpers.loadJSON('static/pilots.json');
|
|
|
-
|
|
|
region.metadata = {
|
|
|
- name: filterednutsGeoJson[0].properties.NUTS_NAME,
|
|
|
+ name: filteredNutsGeoJson[0].properties.NUTS_NAME,
|
|
|
code: nuts,
|
|
|
- centroid: helpers.getCentroid(filterednutsGeoJson[0].geometry),
|
|
|
+ centroid: helpers.getCentroid(filteredNutsGeoJson[0].geometry),
|
|
|
pilot: helpers.getPilotRegion(nuts, pilots)
|
|
|
};
|
|
|
-
|
|
|
- //FIXME: don't imput _datasets here but already pre-processed metadata object
|
|
|
- res.render('nuts', { region: region, datasets: _datasetsEU });
|
|
|
+ res.render('nuts', { region: region, datasets: dsMetadata });
|
|
|
found = true;
|
|
|
}
|
|
|
});
|