forked from ElsevierSoftwareX/SOFTX_2019_1_5_6
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jdssat-server.js
122 lines (95 loc) · 3.48 KB
/
jdssat-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
const express = require('express')
const jdssat = require('./jdssat')
const app = express()
const port = 3000
app.get('/', (req, res) => res.send('server is up and running'))
app.listen(port, function() {
console.log(`app listening on port ${port}!`)
})
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
})
app.get('/api/treatments/:crop/:experiments', (request, response) => {
let crop = request.params.crop;
let experiments = request.params.experiments;
let experimentsObj = JSON.parse(experiments);
jdssatInstance = new jdssat();
jdssatInstance.initialize();
let treatments = jdssatInstance.treatments(crop, experimentsObj);
response.end(JSON.stringify(treatments));
})
app.get('/api/experiments/:crop', (request, response) => {
let crop = request.params.crop;
console.log(crop);
jdssatInstance = new jdssat();
jdssatInstance.initialize();
let experiments = jdssatInstance.experiments(crop);
response.end(JSON.stringify(experiments));
})
app.get('/api/data/:crop', (request, response) => {
let crop = request.params.crop;
console.log(crop);
jdssatInstance = new jdssat();
jdssatInstance.initialize();
let experiments = jdssatInstance.getDataFiles(crop);
response.end(JSON.stringify(experiments));
})
app.get('/api/outfiles/:crop', (request, response) => {
let crop = request.params.crop;
console.log(crop);
jdssatInstance = new jdssat();
jdssatInstance.initialize();
let outFiles = jdssatInstance.outFiles(crop);
response.end(JSON.stringify(outFiles));
})
app.get('/api/runSimulation/:crop/:experiments', (request, response) => {
let crop = request.params.crop;
let experiments = request.params.experiments;
let experimentsObj = JSON.parse(experiments);
jdssatInstance = new jdssat();
jdssatInstance.initialize();
jdssatInstance.runSimulation(crop, experimentsObj);
response.end("simulations are completed");
})
app.get('/api/out/:crop/:file', (request, response) => {
let crop = request.params.crop;
let outfile = request.params.file;
jdssatInstance = new jdssat();
jdssatInstance.initialize();
let fileContent = jdssatInstance.readOutFile(crop, outfile);
response.end(JSON.stringify(fileContent));
})
app.get('/api/cde', (request, response) => {
jdssatInstance = new jdssat();
jdssatInstance.initialize();
let cdeVariables = jdssatInstance.cde();
response.end(JSON.stringify(cdeVariables));
})
app.get('/api/tool/', (request, response) => {
//let tool = request.params.tool;
let tool = request.query.tool;
console.log(tool);
jdssatInstance = new jdssat();
jdssatInstance.initialize();
jdssatInstance.openExternalTool(tool);
response.end(JSON.stringify("ok"));
})
app.get('/api/config/', (request, response) => {
let config = request.query.config;
console.log(config);
jdssatInstance = new jdssat();
jdssatInstance.initialize();
if (config === "path") {
let path = jdssatInstance.path();
response.end(JSON.stringify(path));
} else if (config === "version") {
let version = jdssatInstance.version();
response.end(JSON.stringify(version));
} else if (config === "platform") {
let platform = jdssatInstance.platform();
response.end(JSON.stringify(platform));
}
response.end(JSON.stringify("not found"));
})