Skip to content

Commit

Permalink
adds aveva model
Browse files Browse the repository at this point in the history
Signed-off-by: jmc <[email protected]>
  • Loading branch information
jmcook1186 committed Sep 13, 2023
1 parent 17ca5e5 commit 9ff1d3d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 59 deletions.
45 changes: 20 additions & 25 deletions examples/impls/aveva.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,39 @@ tags:
category: on-premise
initialize:
models:
- name: e-aveva # a model that takes in power observations and returns e.
kind: plugin
path: ''
verbose: false
- name: aveva # a model that takes in power observations and returns e.
kind: builtin
- name: sci-o # a model that given e, i and m calculates a carbon value (e * i) + m
kind: builtin
verbose: false
path: ''
- name: sci-e # a model that given e, i and m calculates a carbon value (e * i) + m
kind: builtin
- name: sci-m # a model that calculates m from te, tir, el, rr and rtor.
kind: builtin
verbose: false
path: ''
- name: sci # sums SCI components and converts to f.unit
kind: builtin
verbose: false
path: ''
graph:
children:
pc:
pipeline:
- aveva
- sci-e
- sci-m
- sci-o
config:
aveva:
sci-e:
sci-m:
config:
te: 350 # kgCO2eq
tir: 31536000 # 1 year in seconds
el: 157680000 # 5 years in seconds
rr: 1
tor: 1
te: 350000 # kgCO2eq
tir: 1 # 1 year in seconds
el: 5 # 5 years in seconds
rr: 1
tor: 1
sci-o:
config:
i: 474.8 #gCo2/kWh
sci:
config:
time: '' # don't do any time norm
factor: 1
observations:
timestamp: 2023-07-06T00:00
grid-ci: 475 #gCo2/kWh
observations:
- timestamp: 2023-07-06T00:00
pl: 16.009 # average over timespan
pb: 11.335 # average over timespan
t: 8322 # (hours in year * average uptime e.g. 95%)
time: 8322 # (hours in year * average uptime e.g. 95%)


39 changes: 8 additions & 31 deletions src/lib/case-studies/aveva-model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {IImpactModelInterface} from '../interfaces';
import {KeyValuePair} from '../../types/boavizta';

export class EAvevaModel implements IImpactModelInterface {
// Defined for compatibility. Not used in Aveva.
Expand Down Expand Up @@ -36,50 +35,28 @@ export class EAvevaModel implements IImpactModelInterface {
* Each Observation require:
* @param {Object[]} observations
* @param {number} observations[].time time to normalize to in hours
* @param {number} observations[].pb percentage mem usage
* @param {number} observations[].pl percentage mem usage
* @param {number} observations[].pb baseline power
* @param {number} observations[].pl measured power
*/
async calculate(observations: object | object[] | undefined): Promise<any[]> {

Check warning on line 41 in src/lib/case-studies/aveva-model.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
if (observations === undefined) {
throw new Error('Required Parameters not provided');
} else if (!Array.isArray(observations)) {
throw new Error('Observations must be an array');
}
return observations.map(observation => {
observations.map(observation => {
this.configure(this.name!, observation);
observation['e-cpu'] = this.calculateEnergy(observation);
observation['e-cpu'] =
((observation['pl'] - observation['pb']) * observation['time']) / 1000;
return observation;
});

return Promise.resolve(observations);
}
/**
* Returns model identifier
*/
modelIdentifier() {
return 'e-aveva';
}
/**
* Calculates the energy consumption for a single observation
* requires
*
* mem-util: ram usage in percentage
* timestamp: RFC3339 timestamp string
*
* multiplies memory used (GB) by a coefficient (wh/GB) and converts to kwh
*/
calculateEnergy(observation: KeyValuePair) {
if (
!('pl' in observation) ||
!('pb' in observation) ||
!('time' in observation)
) {
throw new Error(
'Required Parameters pl, pb, time not provided for observation'
);
}
const pl = observation['pl'];
const pb = observation['pb'];
const time = observation['time'];

return ((pl - pb) * time) / 1000;
return 'aveva';
}
}
9 changes: 6 additions & 3 deletions src/lib/sci-m/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,12 @@ export class SciMModel implements IImpactModelInterface {
) {
observation['te'] = observation['te'] ?? observation['total-embodied'];
observation['tir'] = observation['tir'] ?? observation['time-reserved'];
observation['el'] = observation['el'] ?? observation['expected-lifespan'];
observation['rr'] = observation['rr'] ?? observation['resources-reserved'];
observation['tor'] = observation['tor'] ?? observation['total-resources'];
observation['el'] =
observation['el'] ?? observation['expected-lifespan'];
observation['rr'] =
observation['rr'] ?? observation['resources-reserved'];
observation['tor'] =
observation['tor'] ?? observation['total-resources'];
if (typeof observation['te'] === 'string') {
te = parseFloat(observation[observation['te']]);
} else if (typeof observation['te'] === 'number') {
Expand Down
3 changes: 3 additions & 0 deletions src/util/models-universe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
EshoppenNetModel,
EMemModel,
SciAccentureModel,
EAvevaModel,
} from '../lib/case-studies';
import {SciEModel} from '../lib/sci-e';

Expand Down Expand Up @@ -63,6 +64,8 @@ export class ModelsUniverse {
return SciAccentureModel;
case 'emem':
return EMemModel;
case 'aveva':
return EAvevaModel;
default: // cover default
return BoaviztaCpuImpactModel;
}
Expand Down

0 comments on commit 9ff1d3d

Please sign in to comment.