index.js
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var express = require('express');
var router = express.Router();
const rscript = require('js-call-r');
const csvtojson=require("csvtojson");
const json2csv = require('json2csv');
var fs = require('fs');
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('index', { title: 'Express' });
});
router.post('/getPredict',function(req,res,next){
let insp = req.body;
//csv읽어와서 json으로 변환
csvtojson()
.fromFile("normal_value_delete_version_utf8.csv")
.then((json)=>{
let normal_json = json;
//정상값에 채움.
insp.forEach((inspection)=>{
let insp_name= inspection.name;
let found = normal_json.find((value)=>{
return value.name==insp_name;
})
if(found){
found.value=inspection.value;
}
})
//csv포맷에 맞춰 출력
let csv1 = normal_json.map((val)=>val.name).join(',');
let csv2 = normal_json.map((val)=>val.value).join(',');
csv = csv1 + '\n' +csv2;
fs.writeFileSync('./inspection.csv',csv);
//스크립트 수행.
const result = rscript.callSync('/home/swc/capD/model/model.r', {path : process.cwd()+'/inspection.csv'});
res.json(result);
})
});
module.exports = router;