2021-12-28 10:39:15 +00:00
|
|
|
const fs = require("fs");
|
|
|
|
|
const path = require("path");
|
2022-01-04 08:28:47 +00:00
|
|
|
const sd = require("node-stdev");
|
|
|
|
|
|
|
|
|
|
global.APP_ROOT = path.resolve(__dirname);
|
2021-12-28 10:39:15 +00:00
|
|
|
|
|
|
|
|
exports.summaries = async (directory) => {
|
|
|
|
|
const files = await fs.promises.readdir(directory);
|
|
|
|
|
const results = {};
|
|
|
|
|
files.forEach((file) => {
|
|
|
|
|
if (file.endsWith(".json")) {
|
|
|
|
|
const content = require(`${APP_ROOT}/traces/reports/${file}`);
|
|
|
|
|
Object.keys(content).forEach((key) => {
|
|
|
|
|
if (!results[key]) {
|
|
|
|
|
results[key] = {};
|
|
|
|
|
}
|
|
|
|
|
if (!results[key]?.scripting) {
|
|
|
|
|
results[key].scripting = [];
|
|
|
|
|
}
|
2022-01-04 08:28:47 +00:00
|
|
|
results[key].scripting.push(
|
|
|
|
|
parseFloat(content[key].summary.scripting.toFixed(2)),
|
|
|
|
|
);
|
2021-12-28 10:39:15 +00:00
|
|
|
|
|
|
|
|
if (!results[key]?.painting) {
|
|
|
|
|
results[key].painting = [];
|
|
|
|
|
}
|
2022-01-04 08:28:47 +00:00
|
|
|
results[key].painting.push(
|
|
|
|
|
parseFloat(content[key].summary.painting.toFixed(2)),
|
|
|
|
|
);
|
2021-12-28 10:39:15 +00:00
|
|
|
|
|
|
|
|
if (!results[key]?.rendering) {
|
|
|
|
|
results[key].rendering = [];
|
|
|
|
|
}
|
2022-01-04 08:28:47 +00:00
|
|
|
results[key].rendering.push(
|
|
|
|
|
parseFloat(content[key].summary.rendering.toFixed(2)),
|
|
|
|
|
);
|
2021-12-28 10:39:15 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-01-04 08:28:47 +00:00
|
|
|
generateMarkdown(results);
|
2021-12-28 10:39:15 +00:00
|
|
|
};
|
|
|
|
|
|
2022-01-04 08:28:47 +00:00
|
|
|
const getMaxSize = (results) => {
|
|
|
|
|
let size = 0;
|
2021-12-28 10:39:15 +00:00
|
|
|
Object.keys(results).forEach((key) => {
|
|
|
|
|
const action = results[key];
|
2022-01-04 08:28:47 +00:00
|
|
|
size = Math.max(action["scripting"].length, size);
|
2021-12-28 10:39:15 +00:00
|
|
|
});
|
|
|
|
|
|
2022-01-04 08:28:47 +00:00
|
|
|
return size;
|
2021-12-28 10:39:15 +00:00
|
|
|
};
|
|
|
|
|
|
2022-01-04 08:28:47 +00:00
|
|
|
const generateMarkdown = (results) => {
|
|
|
|
|
const size = getMaxSize(results);
|
2021-12-28 10:39:15 +00:00
|
|
|
let markdown = `<details><summary>Click to view performance test results</summary>\n\n| `;
|
|
|
|
|
for (let i = 0; i < size; i++) {
|
2022-01-04 08:28:47 +00:00
|
|
|
markdown = markdown + `| Run ${i + 1} `;
|
2021-12-28 10:39:15 +00:00
|
|
|
}
|
2022-01-04 08:28:47 +00:00
|
|
|
markdown = markdown + `| Mean | SD.Sample | SD.Population`;
|
2021-12-28 10:39:15 +00:00
|
|
|
|
|
|
|
|
markdown += "|\n";
|
|
|
|
|
|
2022-01-04 08:28:47 +00:00
|
|
|
for (let i = 0; i <= size + 3; i++) {
|
2021-12-28 10:39:15 +00:00
|
|
|
markdown = markdown + `| ------------- `;
|
|
|
|
|
}
|
|
|
|
|
markdown += "|\n";
|
|
|
|
|
|
|
|
|
|
Object.keys(results).forEach((key) => {
|
|
|
|
|
const action = results[key];
|
2022-01-04 08:28:47 +00:00
|
|
|
markdown += `**${key}**`;
|
2021-12-28 10:39:15 +00:00
|
|
|
for (let i = 0; i <= size; i++) {
|
2022-01-04 08:28:47 +00:00
|
|
|
markdown += `| `;
|
2021-12-28 10:39:15 +00:00
|
|
|
}
|
|
|
|
|
markdown += "|\n";
|
2022-01-04 08:28:47 +00:00
|
|
|
|
2021-12-28 10:39:15 +00:00
|
|
|
Object.keys(action).forEach((key) => {
|
2022-01-04 08:28:47 +00:00
|
|
|
const length = action[key].length;
|
2021-12-28 10:39:15 +00:00
|
|
|
markdown += `| ${key} | `;
|
|
|
|
|
markdown += action[key].reduce((sum, val) => `${sum} | ${val} `);
|
2022-01-04 08:28:47 +00:00
|
|
|
if (length < size) {
|
|
|
|
|
for (let i = 0; i < size - action[key].length; i++) {
|
|
|
|
|
markdown += " | ";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Add average
|
|
|
|
|
const avg = parseFloat(
|
|
|
|
|
(action[key].reduce((sum, val) => sum + val, 0) / length).toFixed(2),
|
|
|
|
|
);
|
|
|
|
|
markdown += `| ${avg} | ${((sd.sample(action[key]) / avg) * 100).toFixed(
|
|
|
|
|
2,
|
|
|
|
|
)} | ${((sd.population(action[key]) / avg) * 100).toFixed(2)}`;
|
|
|
|
|
|
2021-12-28 10:39:15 +00:00
|
|
|
markdown += "| \n";
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
markdown += "</details>";
|
|
|
|
|
|
|
|
|
|
fs.writeFile(`${APP_ROOT}/traces/reports/summary.md`, markdown, (err) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
console.log("Error writing file", err);
|
|
|
|
|
} else {
|
|
|
|
|
console.log("Successfully wrote summary");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|