-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathserver.js
133 lines (98 loc) · 3.48 KB
/
server.js
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
var express = require('express');
var app = express();
var spawn = require('child_process').spawn;
var port = 8085;
var fs = require('fs');
app.set('view engine', 'ejs');
const bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({
extended: true
}));
var multipart = require('connect-multiparty');
var multipartMiddleware = multipart();
//const sqlite3 = require('sqlite3').verbose();
// open the database
//let db = new sqlite3.Database('mpserecords.sqlite');
app.use('/websrc', express.static('websrc/'))
app.use('/static', express.static('MPSE/outputs/'))
app.use('/precomputed', express.static('MPSE/precomputed/'))
app.use('/data', express.static('MPSE/datasets/'))
app.use('/MPSE', express.static('MPSE/MPSE/'))
app.get('/', function (req, res) {
res.render('home');
});
function uploader(tmp_path, target_path, res) {
fs.rename(tmp_path, target_path, function (err) {
if (err) throw err;
fs.unlink(tmp_path, function () {
if (err) throw err;
//res.write('File uploaded to: ' + target_path);
});
});
}
app.post('/run', multipartMiddleware, function (req, res) {
res.header('Content-Type', 'text/html;charset=utf-8');
let datapath = [];
if (req.body.data == "uploaded") {
var f1 = './uploaded/dist1.csv'
var f2 = './uploaded/dist2.csv'
var f3 = './uploaded/dist3.csv'
datapath = ['-d']
if (req.files.file1.size > 0) {
uploader(req.files.file1.path, f1, res);
datapath.push(f1)
}
if (req.files.file2.size > 0) {
uploader(req.files.file2.path, f2, res);
datapath.push(f2)
}
if (req.files.file3.size > 0) {
uploader(req.files.file3.path, f3, res);
datapath.push(f3)
}
}
sample_size = req.body.sample_size;
preloadeddata = req.body.preloadeddata;
projection_type = req.body.projection_type;
if (req.body.data == "preloaded") {
}
if (req.body.smart_initialization=='random')
req.body.smart_initialization="False";
else
req.body.smart_initialization="True";
var parameters = ['mpse.py', '-n', sample_size, '-vt', req.body.vistemplate, '-e', req.body.EXPERIMENT_NAME, '-an', req.body.average_neighbors, '-ps', projection_type, '-max_iters', req.body.max_iters, '-X0', req.body.smart_initialization, '-ds',preloadeddata , '-bgcolor',req.body.backgroundcolor, '-pcolor', req.body.pointcolor ];
console.log(parameters);
parameters = parameters.concat(datapath)
console.log("python3.6 " + parameters.join(" "))
mpse_process = spawn('python3.6', parameters)
mpse_process.stdout.on('data', function (data) {
console.log('stdout: ' + data);
res.write(data + "<br>", 'utf-8');
res.flush();
});
mpse_process.stderr.on('data', function (data) {
console.log('stderr: ' + data);
res.write(data, 'utf-8');
});
mpse_process.on('exit', function (code) {
console.log('child process exited with code ' + code);
res.end("" + code);
});
});
/*
app.get('/history', function (req, res) {
let sql = `SELECT expname FROM history`;
db.all(sql, [], (err, rows) => {
if (err) {
throw err;
}
rows.forEach((row) => {
console.log(row.name);
});
});
res.send("list")
}); */
// close the database connection
//db.close();
app.listen(port);
console.log('server is running on', port);