Skip to content

Commit 3475a82

Browse files
authored
Implement Total Sum of Simulated Years and Energy Metrics in Performance section of an experiment (#278)
* Added simulated time, footprint for each fob, new sustainability section and refactor the help information * Add units and check for nulls for energy and footprint * Deleted fixed decimals from PUE * Delete venv from .gitignore * Change 'SIM_platform_info' to be the same as the return of the api. And added information about configuration CF and PUE. * Moved the function formatTime from ExperimentPerformance.jsx to src/components/context and generalized it. Changed the labels of the energy and footprint metrics and enhanced the their explanation in ExperimentPerformance.jsx. Corrected some sintax errors. * Correct explanation footprint in ExperimentPerformance.jsx
1 parent 6865f95 commit 3475a82

File tree

4 files changed

+348
-80
lines changed

4 files changed

+348
-80
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,4 @@ next-env.d.ts
4646
# misc
4747
.nyc_output/
4848

49-
docs/build/
49+
docs/build/

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/context/utils.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,40 @@ export const calculateStatistics = (jobs) => {
294294
cpuConsumptionPercentage: formatNumberMoney(cpuConsumptionPercentage),
295295
};
296296
};
297+
298+
export const CONVERSIONS_YEARS = [
299+
{ label: 'year', hours: 8760 },
300+
{ label: 'month', hours: 730 },
301+
{ label: 'week', hours: 168 },
302+
{ label: 'day', hours: 24 },
303+
{ label: 'hour', hours: 1 }
304+
];
305+
306+
export const formatTime = (years) => {
307+
if (typeof years !== "number" || isNaN(years)) return "-";
308+
else if (years === 0) return "0 hours";
309+
310+
let totalHours = years * CONVERSIONS_YEARS[0].hours;
311+
const results = [];
312+
313+
for (let i = 0; i < CONVERSIONS_YEARS.length; i++) {
314+
const unit = CONVERSIONS_YEARS[i];
315+
const count = Math.floor(totalHours / unit.hours);
316+
if (count > 0) {
317+
results.push({ unit: unit.label, count });
318+
}
319+
totalHours %= unit.hours;
320+
if (totalHours === 0) {
321+
break;
322+
}
323+
}
324+
325+
const parts = results.map(item => `${item.count} ${item.unit}${item.count !== 1 ? 's' : ''}`);
326+
let message = "";
327+
if (parts.length > 1) {
328+
message += parts.slice(0, parts.length - 1).join(', ') + " and " + parts[parts.length - 1];
329+
} else {
330+
message += parts[0];
331+
}
332+
return message;
333+
};

0 commit comments

Comments
 (0)