-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
executable file
·57 lines (49 loc) · 2.07 KB
/
app.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
#!/usr/bin/env node
const fs = require("fs");
const [, , ...argsList] = process.argv; // short hand for -> const argsList = process.argv.slice(2);
const { platform } = require("process");
let projectUID = argsList[0];
const { promisify } = require("util");
const readFile = promisify(fs.readFile);
const helpMenu = () => 'command "./app.js [projectUID]"';
// const pUid = "DankFXAj0a";
// projectUID = pUid;
if(!projectUID) {
console.log("Please provide projectUID!");
console.log(helpMenu());
process.exit();
}
const { csvToJson } = require("./helpers/index");
const result_path = platform === "win32" ? `${__dirname}\\files\\results\\result_${projectUID}.json` : `./files/results/result_${projectUID}.json`;
const csvPath = platform === "win32" ? `${__dirname}\\files\\csv\\${projectUID}.csv` : `./files/csv/${projectUID}.csv`;
const jsonPath = platform === "win32" ? `${__dirname}\\files\\features\\${projectUID}.json`: `./files/features/${projectUID}.json`;
const { generateRawImages } = require("./helpers/index");
const getFeatures = async(path) => JSON.parse(await readFile(path));
function parseObject(object) {
let jsonObj = {};
for (const obj of object) {
jsonObj[obj.issueUID] = {
raw_images: obj["raw_images"],
folder_name: obj["folder_name"],
markers: obj["markers"],
temperature: obj["temp"],
timestamp: obj["timestamp"],
};
}
return jsonObj;
}
csvToJson(csvPath)
.then(async jA => {
const features = await getFeatures(jsonPath);
let jsonObj = parseObject(jA);
for (let feature of features.features) {
if (jsonObj[feature.properties.uid]) {
feature.properties["raw_images"] = generateRawImages(feature.properties.projectUid, jsonObj[feature.properties.uid], "jpg");
feature.properties["temperature_difference"] = jsonObj[feature.properties.uid].temperature;
feature.properties["timestamp"] = jsonObj[feature.properties.uid].timestamp;
}
}
fs.appendFileSync(result_path, JSON.stringify(features), { flag: "w+" });
console.log(`data written to ${result_path}`);
})
.catch(console.log);