@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
81 lines • 3.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.minMaxAvgAndMedian = minMaxAvgAndMedian;
exports.statsString = statsString;
exports.printFeatureStatistics = printFeatureStatistics;
exports.printFeatureStatisticsEntry = printFeatureStatisticsEntry;
const ansi_1 = require("../../util/text/ansi");
const json_1 = require("../../util/json");
const feature_1 = require("../features/feature");
const arrays_1 = require("../../util/collections/arrays");
/**
* Calculates the min, max, average and median of the given data set.
*/
function minMaxAvgAndMedian(data) {
data = data.sort((a, b) => a - b);
const sum = (0, arrays_1.arraySum)(data);
return {
sum,
min: data[0],
max: data[data.length - 1],
avg: sum / data.length,
median: data[Math.floor(data.length / 2)]
};
}
function formatStatNumber(num) {
return num === undefined ? '<?>' : Number(num.toFixed(3)).toLocaleString();
}
/**
* Formats the given statistics as a string.
*/
function statsString(data, suffix = '') {
return `[${formatStatNumber(data.min)}${suffix} .. ${formatStatNumber(data.max)}${suffix}] (avg: ${formatStatNumber(data.avg)}${suffix}, median: ${formatStatNumber(data.median)}${suffix})`;
}
/**
* Prints the given feature statistics to the console.
*/
function printFeatureStatistics(statistics, features = 'all') {
for (const feature of Object.keys(statistics.features)) {
if (features !== 'all' && !features.has(feature)) {
continue;
}
const meta = feature_1.ALL_FEATURES[feature];
console.log(`\n\n-----${meta.name}-------------`);
console.log(ansi_1.formatter.format(meta.description, { color: 7 /* Colors.White */, effect: ansi_1.ColorEffect.Foreground }));
printFeatureStatisticsEntry(statistics.features[feature]);
console.log('\n\n');
}
const linesPerFile = minMaxAvgAndMedian(statistics.meta.lines.map(l => l.length));
const lineLengths = minMaxAvgAndMedian(statistics.meta.lines.flat());
const processingTimesPerFile = minMaxAvgAndMedian(statistics.meta.processingTimeMs);
console.log(`processed ${statistics.meta.successfulParsed} files (skipped ${statistics.meta.failedRequests.length} due to errors):
\ttotal processing time: ${processingTimesPerFile.sum} ms
\t\tprocessing time range: ${statsString(processingTimesPerFile, ' ms')}
\ttotal number of lines: ${lineLengths.sum}
\t\tline range: ${statsString(linesPerFile)}
\t\tline length range: ${statsString(lineLengths, ' chars')}
`);
}
const pad = 3;
/**
* Prints a single feature statistics entry to the console.
*/
function printFeatureStatisticsEntry(info) {
let longestKey = 0;
let longestValue = 0;
const out = new Map();
for (const [key, value] of Object.entries(info)) {
if (key.length > longestKey) {
longestKey = key.length;
}
const valueString = JSON.stringify(value, json_1.jsonReplacer);
out.set(key, valueString);
if (valueString.length > longestValue) {
longestValue = valueString.length;
}
}
for (const [key, value] of out.entries()) {
console.log(`${key.padEnd(longestKey + pad)} ${value.padStart(longestValue)}`);
}
}
//# sourceMappingURL=print-stats.js.map