-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
79 lines (76 loc) · 2.69 KB
/
main.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
console.debug("");
console.debug("********************* RUN *********************");
console.debug("");
const fs = require("fs");
const path = require("path");
const _ = require("lodash");
const { runTest, additionalLengthTest } = require("./javascript/tests.js");
const { markBefores } = require("./javascript/before.js");
const { markAfters } = require("./javascript/after.js");
const { ReadAndWrite } = require("./javascript/readAndWrite.js");
const {
HK_FILE,
BD_FILE,
OUTPUT_FILE,
ANSWERS_FILE,
} = require("./javascript/variables.js");
function doubleCheckTest() {
let materialNo = "TAC11165390";
let getFiles = new ReadAndWrite(
"./data/hkor_4.xlsx",
"./data/bdor_4.xlsx",
"./data/output_4.xlsx"
);
const { getOutput, getHK, getBD } = getFiles.init(
new Date("2023-09-21"),
true
);
let { hk, bd } = markBefores(getHK, getBD, materialNo);
let getAfters = markAfters(hk, bd, materialNo);
// console.log(getAfters.hk);
getFiles.createFile(getAfters.hk, "./data/sample_4.xlsx");
let testOutput = runTest(getOutput, getAfters.hk, true);
// let filteredOutput = _.filter(getOutput, { materialNo: materialNo });
// let filteredHK = _.filter(getHK, { materialNo: materialNo });
// let filteredBD = _.filter(getBD, { materialNo: materialNo });
// below is for refreshing data, no need to run right now
// let getPath = `./testData/sept23`;
// writeData(getPath, materialNo, filteredHK, filteredBD, filteredOutput);
// refreshData(getPath, getFiles, testOutput);
}
doubleCheckTest();
function refreshData(getPath, getFiles, testOutput) {
const result = getFiles.init(new Date("2023-09-21"), true);
if (fs.existsSync(getPath)) {
fs.rmdirSync(getPath, { recursive: true });
console.log(`${getPath} is deleted!`);
}
for (let i = 0; i < testOutput.difference.length; i++) {
let obj = testOutput.difference[i];
let first = _.filter(result.getHK, { materialNo: obj.materialNo });
let second = _.filter(result.getBD, { materialNo: obj.materialNo });
let third = _.filter(result.getOutput, { materialNo: obj.materialNo });
writeData(getPath, obj.materialNo, first, second, third);
}
}
function writeData(getPath, materialNo, hk, bd, output) {
let fileContent = `
let hk = ${JSON.stringify(hk)};
let bd = ${JSON.stringify(bd)};
let output = ${JSON.stringify(output)};
module.exports = {hk, bd, output};
`;
try {
if (!fs.existsSync(getPath)) {
fs.mkdirSync(getPath, { recursive: true });
}
let file = `${getPath}/${materialNo}.js`;
if (fs.existsSync(file)) {
// File exists, remove it
fs.unlinkSync(file);
}
fs.writeFileSync(file, fileContent);
} catch (error) {
console.log("error", error);
}
}