-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
113 lines (96 loc) · 3.3 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/* import wymaganych bibliotek oraz modułów*/
var cognitive = require("./cognitive.js");
var rekognitionFile = require("./rekognition.js");
var vision = require("./vision.js");
const klawSync = require('klaw-sync');
var fs = require('fs');
let _ = require("lodash");
var Excel = require('exceljs');
const workbook = new Excel.Workbook({
useStyles: true
})
/* Ustawienie nagłówków */
const headers = [
{ header: 'Plik', key: 'path', width: 40 },
{ header: 'Zwierze', key: 'name', width: 12 },
{ header: 'Prawdopodobienstwo(%)', key: 'confidence', width: 24 },
{ header: 'Czas odpowiedzi(s)', key: 'responseTime', width: 20 }
];
/*funkcja asynchroniczna realizująca tworzenie nowego arkusza kalkulacyjengo za pomocą biblioteki exceljs */
async function makeExcel(file, sheet, responses) {
const worksheet = workbook.addWorksheet(sheet);
worksheet.columns = headers;
for (let i = 0; i < responses.length; i++) {
worksheet.addRow(responses[i]);
}
worksheet.getRow(1).style.font = { size: 12, name: 'Bahnschrift SemiBold SemiConden' }
worksheet.getRow(1).eachCell((cell) => {
cell.fill = {
type: 'pattern',
pattern: 'solid',
fgColor: { argb: '993399' }
},
cell.style.font = {
color: {
argb: 'ffffff'
},
size: 14,
}
})
worksheet.eachRow((Row, rowNumber) => {
Row.alignment = {
horizontal: 'center',
}
Row.eachCell((Cell, cellNumber) => {
Cell.alignment = {
vertical: 'middle',
horizontal: 'center'
},
Cell.border = {
top: { style: 'double', color: { argb: 'black' } },
left: { style: 'double', color: { argb: 'black' } },
bottom: { style: 'double', color: { argb: 'black' } },
right: { style: 'double', color: { argb: 'black' } }
}
})
})
worksheet.views = [
{ state: 'frozen', xSplit: 1, ySplit: 1, activeCell: 'B2' },
];
await workbook.xlsx.writeFile(`./excel/${file}.xlsx`)
console.log(`Arkusz ${sheet} w pliku ${file}.xlsx został poprawnie utworzony`);
}
exports.makeExcel = makeExcel;
const directoryToExplore = "./animals/with/bear/6"; // ustawienie folderu nadrzędnego
const files = klawSync(directoryToExplore, {
nodir: true,
});
const arrayOfFiles = files.map(file => file.path); // mapowanie ścieżek danych testowych
// wywoływanie rządań asynchronicznych dla wszystkich 3 usług
async function Cognitive() {
let tab = [];
for (let i = 0; i < arrayOfFiles.length; i++) {
let x = await cognitive.cognitiveDetectLabels(arrayOfFiles[i]);
tab.push(x)
}
return tab;
}
exports.Cognitive = Cognitive;
async function Rekognition() {
let tab = [];
for (let i = 0; i < arrayOfFiles.length; i++) {
let x = await rekognitionFile.callaws(arrayOfFiles[i]);
tab.push(x)
}
return tab;
}
exports.Rekognition = Rekognition;
async function Vision() {
let tab = [];
for (let i = 0; i < arrayOfFiles.length; i++) {
let x = await vision.callVision(arrayOfFiles[i]);
tab.push(x)
}
return tab;
}
exports.Vision = Vision;