Skip to content

Commit

Permalink
reformat sci-o to mnatch sci-e
Browse files Browse the repository at this point in the history
Signed-off-by: jmc <[email protected]>
  • Loading branch information
jmcook1186 committed Sep 18, 2023
1 parent d4989f2 commit a9fc9be
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/lib/sci-o/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,33 @@ export class SciOModel implements IImpactModelInterface {
this.authParams = authParams;
}

/**
* Calculate the total emissions for a list of observations.
*
* Each Observation require:
* @param {Object[]} observations
* @param {string} observations[].timestamp RFC3339 timestamp string
*/
async calculate(observations: object | object[] | undefined): Promise<any[]> {
if (!Array.isArray(observations)) {
throw new Error('observations should be an array');
if (observations === undefined) {
throw new Error('Required Parameters not provided');
} else if (!Array.isArray(observations)) {
throw new Error('Observations must be an array');
}

const tunedObservations = observations.map((observation: KeyValuePair) => {
return observations.map((observation: KeyValuePair) => {
if (!('grid-ci' in observation)) {
throw new Error('observation missing `grid-ci`');
}
if (!('energy' in observation)) {
throw new Error('observation missing `energy`');
}
this.configure(this.name!, observation);
const grid_ci = parseFloat(observation['grid-ci']);
const energy = parseFloat(observation['energy']);
observation['operational-carbon'] = grid_ci * energy;
return observation;
});

return tunedObservations;
}

async configure(
Expand Down

0 comments on commit a9fc9be

Please sign in to comment.