Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes naming and unit errors in CCF and Boavizta models #193

Merged
merged 3 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/lib/boavizta/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('cpu:initialize with params', () => {
{
timestamp: '2021-01-01T00:00:00Z',
duration: 3600,
'cpu-util': 0.5,
'cpu-util': 50,
},
])
).resolves.toStrictEqual([
Expand Down Expand Up @@ -136,7 +136,7 @@ describe('cloud:initialize with params', () => {
{
timestamp: '2021-01-01T00:00:00Z',
duration: 15,
'cpu-util': 0.34,
'cpu-util': 34,
},
])
).resolves.toStrictEqual([
Expand Down Expand Up @@ -164,22 +164,22 @@ describe('cloud:initialize with params', () => {
{
timestamp: '2021-01-01T00:00:00Z',
duration: 15,
'cpu-util': 0.34,
'cpu-util': 34,
},
{
timestamp: '2021-01-01T00:00:15Z',
duration: 15,
'cpu-util': 0.12,
'cpu-util': 12,
},
{
timestamp: '2021-01-01T00:00:30Z',
duration: 15,
'cpu-util': 0.01,
'cpu-util': 1,
},
{
timestamp: '2021-01-01T00:00:45Z',
duration: 15,
'cpu-util': 0.78,
'cpu-util': 78,
},
])
).rejects.toThrowError();
Expand All @@ -203,22 +203,22 @@ describe('cloud:initialize with params', () => {
{
timestamp: '2021-01-01T00:00:00Z',
duration: 15,
'cpu-util': 0.34,
'cpu-util': 34,
},
{
timestamp: '2021-01-01T00:00:15Z',
duration: 15,
'cpu-util': 0.12,
'cpu-util': 12,
},
{
timestamp: '2021-01-01T00:00:30Z',
duration: 15,
'cpu-util': 0.01,
'cpu-util': 1,
},
{
timestamp: '2021-01-01T00:00:45Z',
duration: 15,
'cpu-util': 0.78,
'cpu-util': 78,
},
])
).rejects.toStrictEqual(
Expand Down
2 changes: 1 addition & 1 deletion src/lib/boavizta/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ abstract class BoaviztaImpactModel implements IImpactModelInterface {
// metric is between 0 and 1, convert to percentage
let usageInput: KeyValuePair = {
hours_use_time: duration / 3600.0,
time_workload: metric * 100.0,
time_workload: metric,
};
// convert expected lifespan from seconds to years
usageInput['years_life_time'] =
Expand Down
24 changes: 12 additions & 12 deletions src/lib/ccf/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('ccf:configure test', () => {
});
await expect(
impactModel.calculate([
{duration: 3600, cpu: 0.5, datetime: '2021-01-01T00:00:00Z'},
{duration: 3600, 'cpu-util': 50, datetime: '2021-01-01T00:00:00Z'},
])
).resolves.toStrictEqual([
{
Expand All @@ -31,17 +31,17 @@ describe('ccf:configure test', () => {
impactModel.calculate([
{
duration: 3600,
cpu: 0.1,
'cpu-util': 10,
datetime: '2021-01-01T00:00:00Z',
},
{
duration: 3600,
cpu: 0.5,
'cpu-util': 50,
datetime: '2021-01-01T00:00:00Z',
},
{
duration: 3600,
cpu: 1,
'cpu-util': 100,
datetime: '2021-01-01T00:00:00Z',
},
])
Expand Down Expand Up @@ -70,17 +70,17 @@ describe('ccf:configure test', () => {
impactModel.calculate([
{
duration: 3600,
cpu: 0.1,
'cpu-util': 10,
datetime: '2021-01-01T00:00:00Z',
},
{
duration: 3600,
cpu: 0.5,
'cpu-util': 50,
datetime: '2021-01-01T00:00:00Z',
},
{
duration: 3600,
cpu: 1,
'cpu-util': 100,
datetime: '2021-01-01T00:00:00Z',
},
])
Expand Down Expand Up @@ -109,17 +109,17 @@ describe('ccf:configure test', () => {
impactModel.calculate([
{
duration: 3600,
cpu: 0.1,
'cpu-util': 10,
datetime: '2021-01-01T00:00:00Z',
},
{
duration: 3600,
cpu: 0.5,
'cpu-util': 50,
datetime: '2021-01-01T00:00:00Z',
},
{
duration: 3600,
cpu: 1,
'cpu-util': 100,
datetime: '2021-01-01T00:00:00Z',
},
])
Expand Down Expand Up @@ -149,7 +149,7 @@ describe('ccf:configure test', () => {
).rejects.toThrowError();
await expect(
impactModel.calculate([
{duration: 3600, cpu: 0.5, datetime: '2021-01-01T00:00:00Z'},
{duration: 3600, 'cpu-util': 50, datetime: '2021-01-01T00:00:00Z'},
])
).rejects.toThrowError();
});
Expand All @@ -163,7 +163,7 @@ describe('ccf:configure test', () => {
).rejects.toThrowError();
await expect(
impactModel.calculate([
{duration: 3600, cpu: 0.5, datetime: '2021-01-01T00:00:00Z'},
{duration: 3600, 'cpu-util': 50, datetime: '2021-01-01T00:00:00Z'},
])
).rejects.toThrowError();
});
Expand Down
11 changes: 4 additions & 7 deletions src/lib/ccf/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class CloudCarbonFootprint implements IImpactModelInterface {
* @param {Object[]} observations ISO 8601 datetime string
* @param {string} observations[].datetime ISO 8601 datetime string
* @param {number} observations[].duration observation duration in seconds
* @param {number} observations[].cpu percentage cpu usage
* @param {number} observations[].cpu-util percentage cpu usage
*/
async calculate(observations: object | object[] | undefined): Promise<any[]> {
if (observations === undefined) {
Expand Down Expand Up @@ -158,27 +158,24 @@ export class CloudCarbonFootprint implements IImpactModelInterface {
* requires
*
* duration: duration of the observation in seconds
* cpu: cpu usage in percentage
* cpu-util: cpu usage in percentage
* datetime: ISO 8601 datetime string
*
* Uses a spline method for AWS and linear interpolation for GCP and Azure
*/
private calculateEnergy(observation: KeyValuePair) {
if (
!('duration' in observation) ||
!('cpu' in observation) ||
!('cpu-util' in observation) ||
!('datetime' in observation)
) {
throw new Error(
'Required Parameters duration,cpu,datetime not provided for observation'
);
}

// duration is in seconds
const duration = observation['duration'];

// convert cpu usage to percentage
const cpu = observation['cpu'] * 100.0;
const cpu = observation['cpu-util'];

// get the wattage for the instance type
let wattage;
Expand Down