|
|
@@ -8,6 +8,7 @@ const app = express();
|
|
|
|
|
|
const _datasetsFilePath = 'data/datasets.csv';
|
|
|
const _dataFilePath = 'data/data.csv';
|
|
|
+const _clustersFilePath = 'data/clustering/out_file.csv';
|
|
|
var _datasets = undefined;
|
|
|
var _ruralData = undefined;
|
|
|
|
|
|
@@ -125,22 +126,52 @@ app.post('/scores', (req, res, next) => {
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+/*
|
|
|
+ Only testing purposes
|
|
|
+*/
|
|
|
app.get('/runR', (req, res, next) => {
|
|
|
//console.log(console);
|
|
|
console.log('calling R...')
|
|
|
R('./r/selected_data.r').call(
|
|
|
function(err, data) {
|
|
|
console.log('R done');
|
|
|
- if (err) console.log(err.toString('utf8'))
|
|
|
+ if (err) {
|
|
|
+ console.log(err.toString('utf8'));
|
|
|
+ data = { result: err.toString('utf8') };
|
|
|
+ }
|
|
|
else {
|
|
|
- console.log(data);
|
|
|
- data = {result: 'R call succesful'};
|
|
|
- }
|
|
|
+ console.log(data);
|
|
|
+ data = { result: 'R call succesful' };
|
|
|
+ }
|
|
|
helpers.formatResponse({ response: data }, req, res);
|
|
|
}
|
|
|
);
|
|
|
});
|
|
|
|
|
|
+/*
|
|
|
+ Calls R script, loads the resulting CSV file and returns it
|
|
|
+*/
|
|
|
+app.get('/clusters', (req, res, next) => {
|
|
|
+ //console.log(console);
|
|
|
+ console.log('calling R...')
|
|
|
+ R('./r/selected_data.r').call(
|
|
|
+ function(err, data) {
|
|
|
+ console.log('R done');
|
|
|
+ if (err) {
|
|
|
+ console.log(err.toString('utf8'));
|
|
|
+ data = { result: err.toString('utf8') };
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ console.log(data);
|
|
|
+ nutsData.loadClusters(_clustersFilePath, function(clusterData) {
|
|
|
+ data = clusterData;
|
|
|
+ helpers.formatResponse({ response: data }, req, res);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ );
|
|
|
+});
|
|
|
+
|
|
|
// start the service on the port xxxx
|
|
|
app.listen(3000, () => console.log('Rural attractivity WS listening on port 3000...'));
|
|
|
|