Skip to content

Commit

Permalink
Fix and better display of SCI values in badged and dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ArneTR committed Aug 7, 2023
1 parent 66ffcec commit 5d1c062
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion api/api_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def rescale_energy_value(value, unit):
if value > 1_000_000_000: energy_rescaled = [value/(10**12), f"G{unit_type}"]
elif value > 1_000_000_000: energy_rescaled = [value/(10**9), f"M{unit_type}"]
elif value > 1_000_000: energy_rescaled = [value/(10**6), f"k{unit_type}"]
elif value > 1_000: energy_rescaled = [value/(10**3), f"{unit_type}"]
elif value > 1_000: energy_rescaled = [value/(10**3), f"m{unit_type}"]
elif value < 0.001: energy_rescaled = [value*(10**3), f"n{unit_type}"]

else:
Expand Down
6 changes: 6 additions & 0 deletions frontend/js/helpers/converters.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
const convertValue = (value, unit) => {
// we do not allow a dynamic rescaling here, as we need all the units we feed into
// to be on the same order of magnitude

if (value == null) return [value, unit];

if(unit.startsWith('ugCO2e/')) return [(value/(10**6)).toFixed(2), unit.substr(1)]

switch (unit) {
case 'mJ':
return [(value / 1_000).toFixed(2), 'J'];
Expand Down

0 comments on commit 5d1c062

Please sign in to comment.