From 615281601c2aebf1dde10f496bca017e4cad1cc0 Mon Sep 17 00:00:00 2001 From: Christoph Kluge Date: Tue, 1 Oct 2024 14:58:19 +0200 Subject: [PATCH] fix wrong flag labelling, change to kWh energy calculation --- internal/repository/job.go | 13 +++++++------ web/frontend/src/job/EnergySummary.svelte | 8 ++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/internal/repository/job.go b/internal/repository/job.go index 16390f2..d408341 100644 --- a/internal/repository/job.go +++ b/internal/repository/job.go @@ -603,12 +603,13 @@ func (r *JobRepository) UpdateEnergy( for _, fp := range sc.EnergyFootprint { if i, err := archive.MetricIndex(sc.MetricConfig, fp); err == nil { - // FIXME: Check for unit conversions - // Energy: Watts * Time // Power: Energy / Time -> Correct labelling here? - if sc.MetricConfig[i].Energy == "power" { - // Unit: ( W * s ) / 3600 = Wh ; Rounded to 2 nearest digits - energy = math.Round(((LoadJobStat(jobMeta, fp, "avg")*float64(jobMeta.Duration))/3600)*100) / 100 - } else if sc.MetricConfig[i].Energy == "energy" { + // Note: For DB data, calculate and save as kWh + // Energy: Power (in Watts) * Time (in Seconds) + if sc.MetricConfig[i].Energy == "energy" { + // Unit: ( W * s ) / 3600 / 1000 = kWh ; Rounded to 2 nearest digits + energy = math.Round(((LoadJobStat(jobMeta, fp, "avg")*float64(jobMeta.Duration))/3600/1000)*100) / 100 + // Power: Use directly as sum (Or as: [Energy (in Ws) / Time (in s)] + } else if sc.MetricConfig[i].Energy == "power" { // This assumes the metric is of aggregation type sum } } else { diff --git a/web/frontend/src/job/EnergySummary.svelte b/web/frontend/src/job/EnergySummary.svelte index 099cb57..6b8e318 100644 --- a/web/frontend/src/job/EnergySummary.svelte +++ b/web/frontend/src/job/EnergySummary.svelte @@ -29,8 +29,8 @@ let carbonMass; $: if (carbonPerkWh) { - // (( Wh / 1000 )* g/kWh) / 1000 = kg || Rounded to 2 Digits via [ round(x * 100) / 100 ] - carbonMass = round( (((jobEnergy ? jobEnergy : 0.0) / 1000 ) * carbonPerkWh) / 10 ) / 100; + // ( kWh * g/kWh) / 1000 = kg || Rounded to 2 Digits via [ round(x * 100) / 100 ] + carbonMass = round( ((jobEnergy ? jobEnergy : 0.0) * carbonPerkWh) / 10 ) / 100; } @@ -54,7 +54,7 @@
-
{efp.hardware}: {efp.value} Wh ({efp.metric})
+
{efp.hardware}: {efp.value} kWh ({efp.metric})

-
Total Energy: {jobEnergy? jobEnergy : 0} Wh
+
Total Energy: {jobEnergy? jobEnergy : 0} kWh
{#if carbonPerkWh}