Skip to content

Commit

Permalink
add functional_unit_duration to sci logic
Browse files Browse the repository at this point in the history
Signed-off-by: jmc <[email protected]>
  • Loading branch information
jmcook1186 committed Sep 21, 2023
1 parent f7280a0 commit 752f9cb
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 63 deletions.
15 changes: 9 additions & 6 deletions examples/impls/accenture.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ graph:
sci-o:
grid-ci: 350.861
sci:
functional_unit_duration: ''
functional_unit: requests
functional_unit_duration: 1
functional_duration_time: ''
functional_unit: requests # factor to convert per time to per f.unit
children:
vm1:
observations:
Expand Down Expand Up @@ -120,8 +121,9 @@ graph:
sci-o:
grid-ci: 350.861
sci:
functional_unit_duration: '' # signal to convert /s -> /hr
functional_unit: requests # functional_unit to convert per time to per f.unit
functional_unit_duration: 1
functional_duration_time: ''
functional_unit: requests # factor to convert per time to per f.unit
observations:
- timestamp: 2023-07-06T00:00
duration: 2419200 # seconds in a month (7 days * 4 weeks)
Expand All @@ -140,8 +142,9 @@ graph:
sci-o:
grid-ci: 350.861
sci:
functional_unit_duration: '' # signal to convert /s -> /hr
functional_unit: requests # functional_unit to convert per time to per f.unit
functional_unit_duration: 1
functional_duration_time: ''
functional_unit: requests # factor to convert per time to per f.unit
observations:
- timestamp: 2023-07-06T00:00
duration: 2419200 # seconds in a month (7 days * 4 weeks)
Expand Down
5 changes: 3 additions & 2 deletions examples/impls/aveva.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ graph:
sci-o:
grid-ci: 474.8 #gCo2/kWh
sci:
functional_unit_duration: ''
functional_unit: ''
functional_unit_duration: 1
functional_duration_time: ''
functional_unit: requests # factor to convert per time to per f.unit
observations:
- timestamp: 2023-07-06T00:00
pl: 16.009 # average over timespan
Expand Down
3 changes: 2 additions & 1 deletion examples/impls/dow_msft.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ graph:
sci-o:
grid-ci: 554 # gCO2e/kWh
sci:
functional_unit_duration: '' # signal to convert /s -> /hr
functional_unit_duration: 1
functional_duration_time: ''
functional_unit: requests # factor to convert per time to per f.unit
children:
tiger-database-cpu:
Expand Down
5 changes: 3 additions & 2 deletions examples/impls/farm-insights.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ graph:
- sci # take in carbon from sci-o and embodied carbon (m) and return sum in correct time unit (here /yr)
config:
sci:
time: year
factor: 1
functional_unit_duration: 1 # in secs
functional_duration_time: ''
functional_unit: requests # factor to convert per time to per f.unit
observations:
e: 3.47222222222e-07 # 0.03 kwh/day in kwh/s
i: 713 # g/kwh
Expand Down
20 changes: 12 additions & 8 deletions examples/impls/msft-eshoppen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ graph:
n-hours: 1
n-chips: 1
sci:
functional_unit_duration: '' # signal to convert /s -> /hr
functional_unit: '' # factor to convert per time to per f.unit ()
functional_unit_duration: 1
functional_duration_time: ''
functional_unit: requests # factor to convert per time to per f.unit
observations:
- timestamp: 2023-07-06T00:00 # [KEYWORD] [NO-SUBFIELDS] time when measurement occurred
duration: 3600 # Secs
Expand Down Expand Up @@ -92,8 +93,9 @@ graph:
n-hours: 1
n-chips: 1
sci:
functional_unit_duration: '' # signal to convert /s -> /hr
functional_unit: '' # factor to convert per time to per f.unit ()
functional_unit_duration: 1
functional_duration_time: ''
functional_unit: requests # factor to convert per time to per f.unit
observations:
- timestamp: 2023-07-06T00:00 # [KEYWORD] [NO-SUBFIELDS] time when measurement occurred
duration: 3600
Expand Down Expand Up @@ -122,8 +124,9 @@ graph:
tdp: 150 # W
tdp-coeff: 0.32
sci:
functional_unit_duration: '' # signal to convert /s -> /hr
functional_unit: '' # factor to convert per time to per f.unit ()
functional_unit_duration: 1
functional_duration_time: ''
functional_unit: requests # factor to convert per time to per f.unit
observations:
- timestamp: 2023-07-06T00:00 # [KEYWORD] [NO-SUBFIELDS] time when measurement occurred
duration: 3600
Expand All @@ -146,8 +149,9 @@ graph:
e-net:
net-energy: 0.001 #kwh/GB
sci:
functional_unit_duration: '' # signal to convert /s -> /hr
functional_unit: '' # factor to convert per time to per f.unit ()
functional_unit_duration: 1
functional_duration_time: ''
functional_unit: requests # factor to convert per time to per f.unit
sci-o:
grid-ci: 951
observations:
Expand Down
5 changes: 3 additions & 2 deletions examples/impls/msft-green-ai.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ graph:
grid-ci: 1 # data not provided in case study
embodied-carbon: 0
sci:
functional_unit_duration: '' # signal to convert /s -> /hr
functional_unit: '' # factor to convert per time to per f.unit ()
functional_unit_duration: 1
functional_duration_time: ''
functional_unit: requests # factor to convert per time to per f.unit
observations:
- timestamp: 2023-07-06T00:00
duration: 1205 # 22.27 min runtime in seconds
Expand Down
20 changes: 12 additions & 8 deletions examples/impls/ntt-data-on-premise.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ graph:
sci-o:
grid-ci: 457 # gCO2/kwh
sci:
functional_unit_duration: ''
functional_unit: requests
functional_unit_duration: 1
functional_duration_time: ''
functional_unit: requests # factor to convert per time to per f.unit
observations:
- timestamp: 2023-07-06T00:00
duration: 3600
Expand All @@ -66,8 +67,9 @@ graph:
sci-o:
grid_ci: 457 # gCO2/kwh
sci:
functional_unit_duration: ''
functional_unit: requests
functional_unit_duration: 1
functional_duration_time: ''
functional_unit: requests # factor to convert per time to per f.unit
children:
switch-1:
observations:
Expand Down Expand Up @@ -146,8 +148,9 @@ graph:
sci-o:
grid-ci: 457 # gCO2/kwh
sci:
functional_unit_duration: ''
functional_unit: requests
functional_unit_duration: 1
functional_duration_time: ''
functional_unit: requests # factor to convert per time to per f.unit
children:
app-server1:
observations:
Expand Down Expand Up @@ -178,8 +181,9 @@ graph:
sci-o:
grid-ci: 457 # gCO2/kwh
sci:
functional_unit_duration: ''
functional_unit: requests
functional_unit_duration: 1
functional_duration_time: ''
functional_unit: requests # factor to convert per time to per f.unit
children:
web-server1:
observations:
Expand Down
60 changes: 31 additions & 29 deletions src/lib/sci/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ jest.setTimeout(30000);
describe('sci:configure test', () => {
test('initialize and test', async () => {
const model = await new SciModel().configure('name', {
functional_unit_duration: 'minutes',
functional_unit_time: 'minutes',
functional_unit: 'users',
functional_unit_duration: 1,
});
expect(model).toBeInstanceOf(SciModel);
await expect(
Expand Down Expand Up @@ -41,40 +42,41 @@ describe('sci:configure test', () => {
sci: 1.2003,
},
]);
}),
test('initialize and test', async () => {
const model = await new SciModel().configure('name', {
functional_unit_duration: 'days',
functionalUnit: '',
});
expect(model).toBeInstanceOf(SciModel);
await expect(
model.calculate([
{
'operational-carbon': 0.02,
'embodied-carbon': 5,
},
])
).resolves.toStrictEqual([
});
test('initialize and test', async () => {
const model = await new SciModel().configure('name', {
functional_unit_time: 'days',
functional_unit: '',
functional_unit_duration: 3600,
});
expect(model).toBeInstanceOf(SciModel);
await expect(
model.calculate([
{
'operational-carbon': 0.02,
'embodied-carbon': 5,
sci: 433728,
},
]);
await expect(
model.calculate([
{
'operational-carbon': 20,
'embodied-carbon': 0.005,
},
])
).resolves.toStrictEqual([
])
).resolves.toStrictEqual([
{
'operational-carbon': 0.02,
'embodied-carbon': 5,
sci: 120.47999999999999,
},
]);
await expect(
model.calculate([
{
'operational-carbon': 20,
'embodied-carbon': 0.005,
sci: 1728432,
},
]);
});
])
).resolves.toStrictEqual([
{
'operational-carbon': 20,
'embodied-carbon': 0.005,
sci: 480.12,
},
]);
});
});
22 changes: 17 additions & 5 deletions src/lib/sci/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class SciModel implements IImpactModelInterface {
name: string | undefined;
time: string | unknown;
functionalUnit = 'none';
functionalUnitDuration = 1;

authenticate(authParams: object): void {
this.authParams = authParams;
Expand All @@ -36,9 +37,9 @@ export class SciModel implements IImpactModelInterface {

let sci_secs = 0;
if ('carbon' in observation) {
sci_secs = observation['carbon'];
sci_secs = observation['carbon'] / this.functionalUnitDuration;
} else {
sci_secs = operational + embodied; // sci in time units of /s
sci_secs = (operational + embodied) / this.functionalUnitDuration; // sci in time units of /s
}

let sci_timed: number = sci_secs;
Expand Down Expand Up @@ -114,12 +115,23 @@ export class SciModel implements IImpactModelInterface {
this.staticParams = staticParams;
this.name = name;

if ('functional_unit_duration' in staticParams) {
this.time = staticParams?.functional_unit_duration;
if ('functional_unit_time' in staticParams) {
this.time = staticParams?.functional_unit_time;
}
if (
'functional_unit_duration' in staticParams &&
typeof staticParams.functional_unit_duration === 'number'
) {
this.functionalUnitDuration = staticParams?.functional_unit_duration;
} else {
throw new Error(
'Functional unit duration is not a valid number: provide number of seconds represented by observation'
);
}
if (
'functional_unit' in staticParams &&
typeof staticParams.functional_unit === 'string'
typeof staticParams.functional_unit === 'string' &&
staticParams.functional_unit !== ''
) {
this.functionalUnit = staticParams?.functional_unit;
} else {
Expand Down

0 comments on commit 752f9cb

Please sign in to comment.