Ver código fonte

Refactor clusters/ request

jmacura 4 anos atrás
pai
commit
03b033d590
2 arquivos alterados com 7 adições e 16 exclusões
  1. 2 2
      index.js
  2. 5 14
      nuts-data.js

+ 2 - 2
index.js

@@ -12,7 +12,7 @@ const _datasetsEuFilePath = 'data/datasets.csv';
 const _dataEuFilePath = 'data/data.csv';
 const _dataCzFilePath = 'data/cz/data-input-CZ_LAU2_37_cols.csv';
 //const _clusteringEuInputFilePath = 'data/clustering/input_all.csv';
-const _clusteringCzInputFilePath = 'data/cz/clusters-input-CZ_LAU2_37_cols.csv';
+//const _clusteringCzInputFilePath = 'data/cz/clusters-input-CZ_LAU2_37_cols.csv';
 const _clusteringEuModifiedFilePath = 'data/clustering/input_modified.csv';
 const _clusteringCzModifiedFilePath = 'data/cz/input_modified.csv';
 const _clustersEuFilePath = 'data/clustering/out_file.csv';
@@ -136,7 +136,7 @@ app.get('/:aoi?/clusters/', (req, res, next) => {
 app.post('/:aoi?/clusters/', async (req, res, next) => {
   const aoi = req.params.aoi || 'eu'
   const datasets = await loadDatasetsIfNeeded(req, res, aoi)
-  const dataFilePath = aoi == 'cz' ? _clusteringCzInputFilePath : _dataEuFilePath
+  const dataFilePath = aoi == 'cz' ? _dataCzFilePath : _dataEuFilePath
   const clusteringModifiedFilePath = aoi == 'cz' ? _clusteringCzModifiedFilePath : _clusteringEuModifiedFilePath
   const idString = aoi == 'cz' ? 'LAU2' : 'NUTS_ID'
   try {

+ 5 - 14
nuts-data.js

@@ -108,24 +108,15 @@ module.exports.loadClusteringInput = async function (inputFileName) {
  */
 module.exports.modifyClusteringData = async function ({datasets, data, params, idString, outputFileName}) {
     // regional ID must be copied to the output as well
-    let allowedDatasets = [idString];
-    for (const factor of params.factors) {
-        allowedDatasets = [...allowedDatasets, ...factor.datasets];
-    }
+    const allowedDatasets = [idString, ...params.datasets.map(ds => ds.id)]
     const factorMultipliers = data[0].map((dataset) => {
-        if (dataset === idString) return 1;
-        const factor = datasets.find(ds => ds.Name === dataset);
-        if (!factor) {
-            /* If the factor is unknown for this dataset, it will effectivelly turn it off */
-            console.log(`Undefined factor for dataset ${dataset}`);
-            return 0;
-        } else if (!allowedDatasets.includes(dataset)) {
-            return 0;
+        if (dataset === idString) return 1
+        if (!allowedDatasets.includes(dataset)) {
+            return 0
         } else {
-            return params.factors.find(f => f.factor === factor.Factor).weight;
+            return params.datasets.find(ds => ds.id === dataset).weight
         }
     })
-    //console.log(factorMultipliers);
     /* The actual modification logic resides here */
     const modifiedData = data.map((row, idx) => {
         return row.map((value, i) => {