Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions src/tasks/displayAnalysisResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,29 @@ const formatTotal = (total, unit) => {
return `${computeTotalMetric(total)} ${unit}`;
};

const toBytes = (metrics) =>
Object.fromEntries(
Object.entries(metrics).map(([key, value]) => [
key,
Math.round(value * 1024 ** 3),
])
);
const toPrecision = (metrics, precision) =>
Object.fromEntries(
Object.entries(metrics).map(([key, value]) => [key, value.toPrecision(precision)])
);
const withUnits = (metrics) =>
Object.fromEntries(
Object.entries(metrics).map(([key, value], i) => [
key + (i < 3 ? ' (s)' : ' (B)'),
value,
])
);
const withWh = (metrics) =>
Object.fromEntries(
Object.entries(metrics).map(([key, value]) => [`${key} (Wh)`, value])
);

const displayAnalysisResults = (result, isFree) => {
console.info('\nAnalysis complete !\n');
console.info('Result summary:');
Expand All @@ -35,6 +58,25 @@ const displayAnalysisResults = (result, isFree) => {

if (scenario.status === STATUS.FINISHED) {
console.info(`✅ ${scenario.name} completed`);

console.info('\nMEASUREMENTS');
const measurements = Object.fromEntries(
scenario.containers.map(({ name, score }) => [
name,
withUnits(toPrecision({ ...score.s, ...toBytes(score.gb) }, 3)),
])
);
console.table(measurements);

console.info('\nESTIMATES');
const estimates = Object.fromEntries(
scenario.containers.map(({ name, score }) => [
name,
withWh(toPrecision(score.wh, 2)),
])
);
console.table(estimates);

if (scenario.threshold) {
console.info(
`The estimated footprint at ${totalCo2} eq. co2 ± ${precision}% (${totalMWh}) is under the limit configured at ${scenario.threshold} g eq. co2.`
Expand Down