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");
|
2022-02-16 14:25:33 +00:00
|
|
|
|
2022-02-02 18:55:10 +00:00
|
|
|
var median = require("median");
|
2022-01-04 08:28:47 +00:00
|
|
|
|
2021-12-28 10:39:15 +00:00
|
|
|
exports.summaries = async (directory) => {
|
2022-02-16 14:25:33 +00:00
|
|
|
const results = await parseReports(
|
|
|
|
|
directory,
|
|
|
|
|
["scripting", "painting", "rendering"],
|
|
|
|
|
[],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
generateMarkdown(results);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const parseReports = async (
|
|
|
|
|
directory,
|
|
|
|
|
summaryFields = [],
|
|
|
|
|
warningFields = [],
|
|
|
|
|
) => {
|
2021-12-28 10:39:15 +00:00
|
|
|
const files = await fs.promises.readdir(directory);
|
|
|
|
|
const results = {};
|
|
|
|
|
files.forEach((file) => {
|
|
|
|
|
if (file.endsWith(".json")) {
|
2022-02-16 14:25:33 +00:00
|
|
|
const content = require(`${directory}/${file}`);
|
2021-12-28 10:39:15 +00:00
|
|
|
Object.keys(content).forEach((key) => {
|
|
|
|
|
if (!results[key]) {
|
|
|
|
|
results[key] = {};
|
|
|
|
|
}
|
2022-02-16 14:25:33 +00:00
|
|
|
summaryFields.forEach((summaryField) => {
|
|
|
|
|
if (!results[key][summaryField]) {
|
|
|
|
|
results[key][summaryField] = [];
|
|
|
|
|
}
|
|
|
|
|
results[key][summaryField].push(
|
|
|
|
|
parseFloat(content[key].summary[summaryField].toFixed(2)),
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
warningFields.forEach((warningField) => {
|
|
|
|
|
if (!results[key][warningField]) {
|
|
|
|
|
results[key][warningField] = [];
|
|
|
|
|
}
|
|
|
|
|
results[key][warningField].push(
|
|
|
|
|
parseFloat(content[key].warnings[warningField]),
|
|
|
|
|
);
|
|
|
|
|
});
|
2021-12-28 10:39:15 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
2022-02-16 14:25:33 +00:00
|
|
|
return 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-02-02 18:55:10 +00:00
|
|
|
markdown = markdown + `| Median | Mean | SD.Sample | SD.Population`;
|
2021-12-28 10:39:15 +00:00
|
|
|
|
|
|
|
|
markdown += "|\n";
|
|
|
|
|
|
2022-02-02 18:55:10 +00:00
|
|
|
for (let i = 0; i <= size + 4; 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}**`;
|
2022-02-02 18:55:10 +00:00
|
|
|
for (let i = 0; i <= size + 4; 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 += " | ";
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-02 18:55:10 +00:00
|
|
|
// Add median
|
|
|
|
|
markdown += `| ${median(action[key])}`;
|
2022-01-04 08:28:47 +00:00
|
|
|
// 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");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
};
|
2022-02-16 14:25:33 +00:00
|
|
|
|
|
|
|
|
exports.parseReports = parseReports;
|