-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathml.js
More file actions
99 lines (90 loc) · 2.83 KB
/
Copy pathml.js
File metadata and controls
99 lines (90 loc) · 2.83 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
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
const { spawn, exec } = require("child_process");
exports.findPath = (start, end) => {
return new Promise((resolve, reject) => {
const process = spawn("python", [
"./pathFinder/findPath.py",
start,
end,
10,
"MONDAY",
"Sunny",
]);
const out = [];
process.stdout.on("data", (data) => {
let result = data.toString("utf8");
console.log("In Model Calling");
//! debug
result = result.split("|");
console.log(result);
out.push({
bfsRoute: result[1],
Dist: result[2],
dijktraRoute: result[4],
});
console.log("In Model Calling still..");
});
const err = [];
process.stderr.on("data", (error) => {
console.log(`Error: ${error}`);
err.push(error.toString());
});
process.on("exit", (code, signal) => {
console.log(
`Child Process (findPaths.py) close all stdio with code ${code} & signal ${signal}`
);
resolve(out);
});
});
};
exports.getCrowd = (station, time, day, weather) => {
return new Promise((resolve, reject) => {
const process = spawn("python", [
"./pathFinder/getCrowd.py",
station,
parseInt(time),
day,
weather,
]);
const out = [];
process.stdout.on("data", (data) => {
let result = data.toString("utf8");
out.push(result);
});
const err = [];
process.stderr.on("data", (error) => {
console.log(`Error: ${err}`);
err.push(error.toString());
});
process.on("exit", (code, signal) => {
console.log(
`Child Process (getCrowd.py) close all stdio with code ${code} & signal ${signal}`
);
resolve(out);
});
});
};
exports.findPathExp = (start, end) => {
return new Promise((resolve, reject) => {
exec(
`python ./pathFinder/findPath.py "${start}" "${end}" 10 MONDAY Sunny`,
(err, stdout, stderr) => {
console.log("In Model Calling");
const out = [];
if (err) {
console.error(err);
return;
}
let result = stdout.toString("utf8");
result = result.split("\r\n");
console.log(result);
out.push({
bfsRoute: result[1],
Dist: result[3],
dijktraRoute: result[5],
});
console.log("In Model Calling still..");
resolve(out);
}
);
});
};