-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfixCriteriaFromStartList.js
38 lines (33 loc) · 1.59 KB
/
fixCriteriaFromStartList.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
const pceParser = require('./pceResultParser');
const json2csv = require('json2csv');
const fs = require('fs');
const startList = './export_pce/20191214_listeDepartFinale.pce';
const result = './export_pce/20191214_resultatFinaleSansCriteres.pce';
const numberOfRunsInPce = 2;
pceParser.parseResult(startList, numberOfRunsInPce, (headerStartList, startListMono, startListBi, footerStartList) => {
pceParser.parseResult(result, numberOfRunsInPce, (headerResult, resultJsonMonoFinale, resultJsonBiFinale, footerResult) => {
resultJsonMonoFinale.forEach(mono => {
const foundStart = startListMono.find(e => e.embarcationId === mono.embarcationId);
if(foundStart) {
console.log(`${mono.embarcationId} has criteria ${foundStart.criteria}`);
mono.criteria = foundStart.criteria;
} else {
console.log(`${mono.embarcationId} not found.`);
}
});
resultJsonBiFinale.forEach(bi => {
const foundStart = startListBi.find(e => e.embarcationId === bi.embarcationId);
if(foundStart) {
console.log(`${bi.embarcationId} has criteria ${foundStart.criteria}`);
bi.criteria = foundStart.criteria;
} else {
console.log(`${bi.embarcationId} not found.`);
}
});
const pceFinal = headerResult+'\n[resultats]\n'+json2csv({data:resultJsonMonoFinale, hasCSVColumnTitle:false, del:';', quotes:''})+'\n'+json2csv({data:resultJsonBiFinale, hasCSVColumnTitle:false, del:';', quotes:''})+'\n\n'+footerResult;
//console.log(pceFinal);
fs.writeFile('./output.pce', pceFinal, () => {
console.log('Done');
});
});
});