- Created a new Python script `uziom.py` for generating DXF drawings of grounding systems based on user input parameters. - Added detailed documentation in `wet_input_15.docx` and `wet_input_3.docx` for the design of grounding systems, including calculations for resistance and resistivity measurements. - Included placeholders for dynamic data insertion in the documents to facilitate project-specific customization.
67 lines
1.7 KiB
JavaScript
67 lines
1.7 KiB
JavaScript
import { spawn } from "child_process";
|
|
export default function (req, res) {
|
|
console.log("spawnin");
|
|
//console.log(req.body);
|
|
//file
|
|
let textData = req.body.profil;
|
|
let replacedData = textData.replace(" ", "o").replace(" ", "e");
|
|
console.log(replacedData);
|
|
|
|
var fs = require("fs");
|
|
fs.writeFile("P.txt", replacedData, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
});
|
|
|
|
|
|
// log stats
|
|
let ip = req.body.ip;
|
|
if (ip === undefined)
|
|
ip = req.headers["x-forwarded-for"] + " on " + req.headers["user-agent"];
|
|
let date_time = new Date();
|
|
let string =
|
|
fs.readFileSync("profile_log.txt", "utf8") +
|
|
"\n" +
|
|
"[" +
|
|
date_time +
|
|
"]" +
|
|
ip +
|
|
" : " +
|
|
replacedData
|
|
fs.writeFile("profile_log.txt", string, function (err) {
|
|
if (err) {
|
|
return console.error(err);
|
|
}
|
|
});
|
|
|
|
|
|
//py
|
|
let fileName = Math.floor(Math.random() * 9999) + 1000;
|
|
|
|
const python = spawn("python3", ["a.py", req.body.arguments.scale, req.body.arguments.elementOne, req.body.arguments.elementTwo]);
|
|
|
|
let dataToSend;
|
|
python.stdout.on("data", function (data) {
|
|
console.log("Pipe data from python script ...");
|
|
dataToSend = data.toString();
|
|
console.log(dataToSend);
|
|
});
|
|
python.stderr.on("data", (data) => {
|
|
console.error(`stderr: ${data}`);
|
|
res.send("Py Error: " + data);
|
|
});
|
|
// in close event we are sure that stream from child process is closed
|
|
python.on("close", (code) => {
|
|
console.log(`child process close all stdio with code ${code}`);
|
|
// send data to browser
|
|
console.log(dataToSend);
|
|
console.log("done");
|
|
try {
|
|
res.status(200).send({ filename: fileName, data: dataToSend });
|
|
} catch (e) {
|
|
console.log("child process end");
|
|
}
|
|
});
|
|
}
|