Skip to content

Commit

Permalink
Allow expanded names in sci-m models
Browse files Browse the repository at this point in the history
Signed-off-by: Gnanakeethan Balasubramaniam <[email protected]>
  • Loading branch information
gnanakeethan committed Sep 13, 2023
1 parent 5d447fc commit 17ca5e5
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/lib/sci-m/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,35 @@ export class SciMModel implements IImpactModelInterface {
let el = 0.0;
let rr = 0.0;
let tor = 0.0;
if (!('te' in observation)) {
if (!('te' in observation || 'total-embodied' in observation)) {
throw new Error('te: total-embodied is missing. Provide in gCO2e');
}
if (!('tir' in observation)) {
if (!('tir' in observation || 'time-reserved' in observation)) {
throw new Error('tir: time-reserved is missing. Provide in seconds');
}
if (!('el' in observation)) {
if (!('el' in observation || 'expected-lifespan' in observation)) {
throw new Error('el: expected-lifespan is missing. Provide in seconds');
}
if (!('rr' in observation)) {
if (!('rr' in observation || 'resources-reserved' in observation)) {
throw new Error(
'rr: resources-reserved is missing. Provide as a count'
);
}
if (!('tor' in observation)) {
if (!('tor' in observation || 'total-resources' in observation)) {
throw new Error('tor: total-resources is missing. Provide as a count');
}
if (
'te' in observation &&
'tir' in observation &&
'el' in observation &&
'rr' in observation &&
'tor' in observation
('te' in observation || 'total-embodied' in observation) &&
('tir' in observation || 'time-reserved' in observation) &&
('el' in observation || 'expected-lifespan') &&
('rr' in observation || 'resources-reserved') &&
('tor' in observation || 'total-resources' in observation)
) {
observation['te'] = observation['te'] ?? observation['total-embodied'];
observation['tir'] = observation['tir'] ?? observation['time-reserved'];
observation['el'] = observation['el'] ?? observation['expected-lifespan'];

Check failure on line 54 in src/lib/sci-m/index.ts

View workflow job for this annotation

GitHub Actions / build

Insert `⏎·········`
observation['rr'] = observation['rr'] ?? observation['resources-reserved'];

Check failure on line 55 in src/lib/sci-m/index.ts

View workflow job for this annotation

GitHub Actions / build

Insert `⏎·········`
observation['tor'] = observation['tor'] ?? observation['total-resources'];

Check failure on line 56 in src/lib/sci-m/index.ts

View workflow job for this annotation

GitHub Actions / build

Insert `⏎·········`
if (typeof observation['te'] === 'string') {
te = parseFloat(observation[observation['te']]);
} else if (typeof observation['te'] === 'number') {
Expand Down

0 comments on commit 17ca5e5

Please sign in to comment.