From 698c8629f6b27a7715f78e81dd9b49a08b772998 Mon Sep 17 00:00:00 2001 From: jmc <33655003+jmcook1186@users.noreply.github.com> Date: Wed, 11 Oct 2023 14:20:16 +0100 Subject: [PATCH 1/3] rename cpu --> cpu-util and fix units --- src/lib/ccf/index.test.ts | 30 +++++++++++++++--------------- src/lib/ccf/index.ts | 33 +++++++++++++++------------------ 2 files changed, 30 insertions(+), 33 deletions(-) diff --git a/src/lib/ccf/index.test.ts b/src/lib/ccf/index.test.ts index b8189acf1..ed22f16f0 100644 --- a/src/lib/ccf/index.test.ts +++ b/src/lib/ccf/index.test.ts @@ -1,5 +1,5 @@ -import {describe, expect, jest, test} from '@jest/globals'; -import {CloudCarbonFootprint} from './index'; +import { describe, expect, jest, test } from '@jest/globals'; +import { CloudCarbonFootprint } from './index'; jest.setTimeout(30000); @@ -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([ { @@ -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', }, ]) @@ -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', }, ]) @@ -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', }, ]) @@ -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(); }); @@ -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(); }); @@ -178,7 +178,7 @@ describe('ccf:configure test', () => { ).resolves.toBeInstanceOf(CloudCarbonFootprint); await expect( impactModel.calculate([ - {duration: 3600, cpus: 1, datetime: '2021-01-01T00:00:00Z'}, + { duration: 3600, cpus: 1, datetime: '2021-01-01T00:00:00Z' }, ]) ).rejects.toThrowError(); }); diff --git a/src/lib/ccf/index.ts b/src/lib/ccf/index.ts index 6fba5a459..8af15c9fa 100644 --- a/src/lib/ccf/index.ts +++ b/src/lib/ccf/index.ts @@ -1,4 +1,4 @@ -import {INSTANCE_TYPE_COMPUTE_PROCESSOR_MAPPING} from '@cloud-carbon-footprint/aws/dist/lib/AWSInstanceTypes'; +import { INSTANCE_TYPE_COMPUTE_PROCESSOR_MAPPING } from '@cloud-carbon-footprint/aws/dist/lib/AWSInstanceTypes'; import Spline from 'typescript-cubic-spline'; import { @@ -7,7 +7,7 @@ import { IImpactModelInterface, } from '../interfaces'; -import {CONFIG} from '../../config'; +import { CONFIG } from '../../config'; import * as AWS_INSTANCES from './aws-instances.json'; import * as GCP_INSTANCES from './gcp-instances.json'; @@ -19,10 +19,10 @@ import * as GCP_EMBODIED from './gcp-embodied.json'; import * as AWS_EMBODIED from './aws-embodied.json'; import * as AZURE_EMBODIED from './azure-embodied.json'; -import {KeyValuePair, Interpolation} from '../../types/common'; +import { KeyValuePair, Interpolation } from '../../types/common'; -const {MODEL_IDS} = CONFIG; -const {CCF} = MODEL_IDS; +const { MODEL_IDS } = CONFIG; +const { CCF } = MODEL_IDS; export class CloudCarbonFootprint implements IImpactModelInterface { // Defined for compatibility. Not used in CCF. @@ -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 { if (observations === undefined) { @@ -158,7 +158,7 @@ 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 @@ -166,7 +166,7 @@ export class CloudCarbonFootprint implements IImpactModelInterface { private calculateEnergy(observation: KeyValuePair) { if ( !('duration' in observation) || - !('cpu' in observation) || + !('cpu-util' in observation) || !('datetime' in observation) ) { throw new Error( @@ -174,11 +174,8 @@ export class CloudCarbonFootprint implements IImpactModelInterface { ); } - // 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; @@ -253,11 +250,11 @@ export class CloudCarbonFootprint implements IImpactModelInterface { architecture = this.resolveAwsArchitecture(architecture); minWatts += this.computeInstanceUsageByArchitecture['aws'][architecture][ - 'Min Watts' + 'Min Watts' ] ?? 0; maxWatts += this.computeInstanceUsageByArchitecture['aws'][architecture][ - 'Max Watts' + 'Max Watts' ] ?? 0; count += 1; }); @@ -294,11 +291,11 @@ export class CloudCarbonFootprint implements IImpactModelInterface { consumption: { minWatts: this.computeInstanceUsageByArchitecture['gcp'][architecture][ - 'Min Watts' + 'Min Watts' ] * cpus, maxWatts: this.computeInstanceUsageByArchitecture['gcp'][architecture][ - 'Max Watts' + 'Max Watts' ] * cpus, }, maxvCPUs: parseInt( @@ -317,11 +314,11 @@ export class CloudCarbonFootprint implements IImpactModelInterface { consumption: { minWatts: this.computeInstanceUsageByArchitecture['azure'][architecture][ - 'Min Watts' + 'Min Watts' ] * cpus, maxWatts: this.computeInstanceUsageByArchitecture['azure'][architecture][ - 'Max Watts' + 'Max Watts' ] * cpus, }, name: instance['Virtual Machine'], From 127aa8d207ca04567ec3430f8f1f40f48f7ae132 Mon Sep 17 00:00:00 2001 From: jmc <33655003+jmcook1186@users.noreply.github.com> Date: Wed, 11 Oct 2023 14:27:08 +0100 Subject: [PATCH 2/3] fix units in boavizta model --- src/lib/boavizta/index.test.ts | 40 ++++++++++++++--------------- src/lib/boavizta/index.ts | 46 ++++++++++++++++------------------ 2 files changed, 42 insertions(+), 44 deletions(-) diff --git a/src/lib/boavizta/index.test.ts b/src/lib/boavizta/index.test.ts index 33cf8b33a..ed14c79ce 100644 --- a/src/lib/boavizta/index.test.ts +++ b/src/lib/boavizta/index.test.ts @@ -1,5 +1,5 @@ -import {describe, expect, jest, test} from '@jest/globals'; -import {BoaviztaCloudImpactModel, BoaviztaCpuImpactModel} from './index'; +import { describe, expect, jest, test } from '@jest/globals'; +import { BoaviztaCloudImpactModel, BoaviztaCpuImpactModel } from './index'; import axios from 'axios'; import * as PROVIDERS from '../../__mocks__/boavizta/providers.json'; import * as COUNTRIES from '../../__mocks__/boavizta/countries.json'; @@ -13,9 +13,9 @@ const mockAxios = axios as jest.Mocked; mockAxios.get.mockImplementation(url => { switch (url) { case 'https://api.boavizta.org/v1/cloud/all_providers': - return Promise.resolve({data: PROVIDERS}); + return Promise.resolve({ data: PROVIDERS }); case 'https://api.boavizta.org/v1/utils/country_code': - return Promise.resolve({data: COUNTRIES}); + return Promise.resolve({ data: COUNTRIES }); case 'https://api.boavizta.org/v1/cloud/all_instances?provider=aws': return Promise.resolve({ data: INSTANCE_TYPES['aws'], @@ -29,15 +29,15 @@ mockAxios.post.mockImplementation(url => { case 'https://api.boavizta.org/v1/component/cpu?verbose=false&allocation=LINEAR': return Promise.resolve({ data: { - gwp: {manufacture: 0.1, use: 1.0, unit: 'kgCO2eq'}, - pe: {manufacture: 0.1, use: 1.0, unit: 'MJ'}, + gwp: { manufacture: 0.1, use: 1.0, unit: 'kgCO2eq' }, + pe: { manufacture: 0.1, use: 1.0, unit: 'MJ' }, }, }); case 'https://api.boavizta.org/v1/cloud/?verbose=false&allocation=LINEAR': return Promise.resolve({ data: { - gwp: {manufacture: 0.1, use: 1.0, unit: 'kgCO2eq'}, - pe: {manufacture: 0.1, use: 1.0, unit: 'MJ'}, + gwp: { manufacture: 0.1, use: 1.0, unit: 'kgCO2eq' }, + pe: { manufacture: 0.1, use: 1.0, unit: 'MJ' }, }, }); } @@ -48,7 +48,7 @@ describe('cpu:configure test', () => { const impactModel = new BoaviztaCpuImpactModel(); await expect( - impactModel.configure('test', {allocation: 'wrong'}) + impactModel.configure('test', { allocation: 'wrong' }) ).rejects.toThrowError(); expect(impactModel.name).toBe('test'); }); @@ -68,7 +68,7 @@ describe('cpu:configure test', () => { ); // improper observations will throw a invalid observations error await expect( - impactModel.calculate([{invalid: 'observation'}]) + impactModel.calculate([{ invalid: 'observation' }]) ).rejects.toStrictEqual( Error('Invalid Input: Invalid observations parameter') ); @@ -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([ @@ -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([ @@ -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(); @@ -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( diff --git a/src/lib/boavizta/index.ts b/src/lib/boavizta/index.ts index 00a696a93..7def60af1 100644 --- a/src/lib/boavizta/index.ts +++ b/src/lib/boavizta/index.ts @@ -1,13 +1,13 @@ import axios from 'axios'; -import {IImpactModelInterface} from '../interfaces'; -import {CONFIG} from '../../config'; +import { IImpactModelInterface } from '../interfaces'; +import { CONFIG } from '../../config'; -import {BoaviztaInstanceTypes, IBoaviztaUsageSCI} from '../../types/boavizta'; -import {KeyValuePair} from '../../types/common'; +import { BoaviztaInstanceTypes, IBoaviztaUsageSCI } from '../../types/boavizta'; +import { KeyValuePair } from '../../types/common'; -const {MODEL_IDS} = CONFIG; -const {BOAVIZTA_CPU, BOAVIZTA_CLOUD} = MODEL_IDS; +const { MODEL_IDS } = CONFIG; +const { BOAVIZTA_CPU, BOAVIZTA_CLOUD } = MODEL_IDS; abstract class BoaviztaImpactModel implements IImpactModelInterface { name: string | undefined; @@ -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'] = @@ -114,7 +114,7 @@ abstract class BoaviztaImpactModel implements IImpactModelInterface { e = data['pe']['use'] / 3.6; } - return {'embodied-carbon': m, energy: e}; + return { 'embodied-carbon': m, energy: e }; } // converts the usage to the format required by Boavizta API. @@ -141,8 +141,7 @@ abstract class BoaviztaImpactModel implements IImpactModelInterface { export class BoaviztaCpuImpactModel extends BoaviztaImpactModel - implements IImpactModelInterface -{ + implements IImpactModelInterface { sharedParams: object | undefined = undefined; public name: string | undefined; public verbose = false; @@ -204,8 +203,7 @@ export class BoaviztaCpuImpactModel export class BoaviztaCloudImpactModel extends BoaviztaImpactModel - implements IImpactModelInterface -{ + implements IImpactModelInterface { public sharedParams: object | undefined = undefined; public instanceTypes: BoaviztaInstanceTypes = {}; public name: string | undefined; @@ -223,9 +221,9 @@ export class BoaviztaCloudImpactModel if (!countries.includes(location)) { throw new Error( "Improper configure: Invalid location parameter: '" + - location + - "'. Valid values are : " + - countries.join(', ') + location + + "'. Valid values are : " + + countries.join(', ') ); } } @@ -259,9 +257,9 @@ export class BoaviztaCloudImpactModel ) { throw new Error( "Improper configure: Invalid instance_type parameter: '" + - staticParamsCast.instance_type + - "'. Valid values are : " + - this.instanceTypes[provider].join(', ') + staticParamsCast.instance_type + + "'. Valid values are : " + + this.instanceTypes[provider].join(', ') ); } } else { @@ -278,9 +276,9 @@ export class BoaviztaCloudImpactModel if (!supportedProviders.includes(staticParamsCast.provider as string)) { throw new Error( "Improper configure: Invalid provider parameter: '" + - staticParamsCast.provider + - "'. Valid values are : " + - supportedProviders.join(', ') + staticParamsCast.provider + + "'. Valid values are : " + + supportedProviders.join(', ') ); } } @@ -349,6 +347,6 @@ export class BoaviztaCloudImpactModel /** * For JSII. */ -export {IImpactModelInterface} from '../interfaces'; -export {BoaviztaInstanceTypes, IBoaviztaUsageSCI} from '../../types/boavizta'; -export {KeyValuePair} from '../../types/common'; +export { IImpactModelInterface } from '../interfaces'; +export { BoaviztaInstanceTypes, IBoaviztaUsageSCI } from '../../types/boavizta'; +export { KeyValuePair } from '../../types/common'; From 2caa5ed962de888a9f0e64ab2693ec6904110848 Mon Sep 17 00:00:00 2001 From: jmc <33655003+jmcook1186@users.noreply.github.com> Date: Wed, 11 Oct 2023 14:28:04 +0100 Subject: [PATCH 3/3] lint --- src/lib/boavizta/index.test.ts | 20 ++++++++-------- src/lib/boavizta/index.ts | 44 ++++++++++++++++++---------------- src/lib/ccf/index.test.ts | 12 +++++----- src/lib/ccf/index.ts | 22 ++++++++--------- 4 files changed, 50 insertions(+), 48 deletions(-) diff --git a/src/lib/boavizta/index.test.ts b/src/lib/boavizta/index.test.ts index ed14c79ce..af892b799 100644 --- a/src/lib/boavizta/index.test.ts +++ b/src/lib/boavizta/index.test.ts @@ -1,5 +1,5 @@ -import { describe, expect, jest, test } from '@jest/globals'; -import { BoaviztaCloudImpactModel, BoaviztaCpuImpactModel } from './index'; +import {describe, expect, jest, test} from '@jest/globals'; +import {BoaviztaCloudImpactModel, BoaviztaCpuImpactModel} from './index'; import axios from 'axios'; import * as PROVIDERS from '../../__mocks__/boavizta/providers.json'; import * as COUNTRIES from '../../__mocks__/boavizta/countries.json'; @@ -13,9 +13,9 @@ const mockAxios = axios as jest.Mocked; mockAxios.get.mockImplementation(url => { switch (url) { case 'https://api.boavizta.org/v1/cloud/all_providers': - return Promise.resolve({ data: PROVIDERS }); + return Promise.resolve({data: PROVIDERS}); case 'https://api.boavizta.org/v1/utils/country_code': - return Promise.resolve({ data: COUNTRIES }); + return Promise.resolve({data: COUNTRIES}); case 'https://api.boavizta.org/v1/cloud/all_instances?provider=aws': return Promise.resolve({ data: INSTANCE_TYPES['aws'], @@ -29,15 +29,15 @@ mockAxios.post.mockImplementation(url => { case 'https://api.boavizta.org/v1/component/cpu?verbose=false&allocation=LINEAR': return Promise.resolve({ data: { - gwp: { manufacture: 0.1, use: 1.0, unit: 'kgCO2eq' }, - pe: { manufacture: 0.1, use: 1.0, unit: 'MJ' }, + gwp: {manufacture: 0.1, use: 1.0, unit: 'kgCO2eq'}, + pe: {manufacture: 0.1, use: 1.0, unit: 'MJ'}, }, }); case 'https://api.boavizta.org/v1/cloud/?verbose=false&allocation=LINEAR': return Promise.resolve({ data: { - gwp: { manufacture: 0.1, use: 1.0, unit: 'kgCO2eq' }, - pe: { manufacture: 0.1, use: 1.0, unit: 'MJ' }, + gwp: {manufacture: 0.1, use: 1.0, unit: 'kgCO2eq'}, + pe: {manufacture: 0.1, use: 1.0, unit: 'MJ'}, }, }); } @@ -48,7 +48,7 @@ describe('cpu:configure test', () => { const impactModel = new BoaviztaCpuImpactModel(); await expect( - impactModel.configure('test', { allocation: 'wrong' }) + impactModel.configure('test', {allocation: 'wrong'}) ).rejects.toThrowError(); expect(impactModel.name).toBe('test'); }); @@ -68,7 +68,7 @@ describe('cpu:configure test', () => { ); // improper observations will throw a invalid observations error await expect( - impactModel.calculate([{ invalid: 'observation' }]) + impactModel.calculate([{invalid: 'observation'}]) ).rejects.toStrictEqual( Error('Invalid Input: Invalid observations parameter') ); diff --git a/src/lib/boavizta/index.ts b/src/lib/boavizta/index.ts index 7def60af1..89df9ae59 100644 --- a/src/lib/boavizta/index.ts +++ b/src/lib/boavizta/index.ts @@ -1,13 +1,13 @@ import axios from 'axios'; -import { IImpactModelInterface } from '../interfaces'; -import { CONFIG } from '../../config'; +import {IImpactModelInterface} from '../interfaces'; +import {CONFIG} from '../../config'; -import { BoaviztaInstanceTypes, IBoaviztaUsageSCI } from '../../types/boavizta'; -import { KeyValuePair } from '../../types/common'; +import {BoaviztaInstanceTypes, IBoaviztaUsageSCI} from '../../types/boavizta'; +import {KeyValuePair} from '../../types/common'; -const { MODEL_IDS } = CONFIG; -const { BOAVIZTA_CPU, BOAVIZTA_CLOUD } = MODEL_IDS; +const {MODEL_IDS} = CONFIG; +const {BOAVIZTA_CPU, BOAVIZTA_CLOUD} = MODEL_IDS; abstract class BoaviztaImpactModel implements IImpactModelInterface { name: string | undefined; @@ -114,7 +114,7 @@ abstract class BoaviztaImpactModel implements IImpactModelInterface { e = data['pe']['use'] / 3.6; } - return { 'embodied-carbon': m, energy: e }; + return {'embodied-carbon': m, energy: e}; } // converts the usage to the format required by Boavizta API. @@ -141,7 +141,8 @@ abstract class BoaviztaImpactModel implements IImpactModelInterface { export class BoaviztaCpuImpactModel extends BoaviztaImpactModel - implements IImpactModelInterface { + implements IImpactModelInterface +{ sharedParams: object | undefined = undefined; public name: string | undefined; public verbose = false; @@ -203,7 +204,8 @@ export class BoaviztaCpuImpactModel export class BoaviztaCloudImpactModel extends BoaviztaImpactModel - implements IImpactModelInterface { + implements IImpactModelInterface +{ public sharedParams: object | undefined = undefined; public instanceTypes: BoaviztaInstanceTypes = {}; public name: string | undefined; @@ -221,9 +223,9 @@ export class BoaviztaCloudImpactModel if (!countries.includes(location)) { throw new Error( "Improper configure: Invalid location parameter: '" + - location + - "'. Valid values are : " + - countries.join(', ') + location + + "'. Valid values are : " + + countries.join(', ') ); } } @@ -257,9 +259,9 @@ export class BoaviztaCloudImpactModel ) { throw new Error( "Improper configure: Invalid instance_type parameter: '" + - staticParamsCast.instance_type + - "'. Valid values are : " + - this.instanceTypes[provider].join(', ') + staticParamsCast.instance_type + + "'. Valid values are : " + + this.instanceTypes[provider].join(', ') ); } } else { @@ -276,9 +278,9 @@ export class BoaviztaCloudImpactModel if (!supportedProviders.includes(staticParamsCast.provider as string)) { throw new Error( "Improper configure: Invalid provider parameter: '" + - staticParamsCast.provider + - "'. Valid values are : " + - supportedProviders.join(', ') + staticParamsCast.provider + + "'. Valid values are : " + + supportedProviders.join(', ') ); } } @@ -347,6 +349,6 @@ export class BoaviztaCloudImpactModel /** * For JSII. */ -export { IImpactModelInterface } from '../interfaces'; -export { BoaviztaInstanceTypes, IBoaviztaUsageSCI } from '../../types/boavizta'; -export { KeyValuePair } from '../../types/common'; +export {IImpactModelInterface} from '../interfaces'; +export {BoaviztaInstanceTypes, IBoaviztaUsageSCI} from '../../types/boavizta'; +export {KeyValuePair} from '../../types/common'; diff --git a/src/lib/ccf/index.test.ts b/src/lib/ccf/index.test.ts index ed22f16f0..9b4a857f6 100644 --- a/src/lib/ccf/index.test.ts +++ b/src/lib/ccf/index.test.ts @@ -1,5 +1,5 @@ -import { describe, expect, jest, test } from '@jest/globals'; -import { CloudCarbonFootprint } from './index'; +import {describe, expect, jest, test} from '@jest/globals'; +import {CloudCarbonFootprint} from './index'; jest.setTimeout(30000); @@ -12,7 +12,7 @@ describe('ccf:configure test', () => { }); await expect( impactModel.calculate([ - { duration: 3600, 'cpu-util': 50, datetime: '2021-01-01T00:00:00Z' }, + {duration: 3600, 'cpu-util': 50, datetime: '2021-01-01T00:00:00Z'}, ]) ).resolves.toStrictEqual([ { @@ -149,7 +149,7 @@ describe('ccf:configure test', () => { ).rejects.toThrowError(); await expect( impactModel.calculate([ - { duration: 3600, 'cpu-util': 50, datetime: '2021-01-01T00:00:00Z' }, + {duration: 3600, 'cpu-util': 50, datetime: '2021-01-01T00:00:00Z'}, ]) ).rejects.toThrowError(); }); @@ -163,7 +163,7 @@ describe('ccf:configure test', () => { ).rejects.toThrowError(); await expect( impactModel.calculate([ - { duration: 3600, 'cpu-util': 50, datetime: '2021-01-01T00:00:00Z' }, + {duration: 3600, 'cpu-util': 50, datetime: '2021-01-01T00:00:00Z'}, ]) ).rejects.toThrowError(); }); @@ -178,7 +178,7 @@ describe('ccf:configure test', () => { ).resolves.toBeInstanceOf(CloudCarbonFootprint); await expect( impactModel.calculate([ - { duration: 3600, cpus: 1, datetime: '2021-01-01T00:00:00Z' }, + {duration: 3600, cpus: 1, datetime: '2021-01-01T00:00:00Z'}, ]) ).rejects.toThrowError(); }); diff --git a/src/lib/ccf/index.ts b/src/lib/ccf/index.ts index 8af15c9fa..b21025778 100644 --- a/src/lib/ccf/index.ts +++ b/src/lib/ccf/index.ts @@ -1,4 +1,4 @@ -import { INSTANCE_TYPE_COMPUTE_PROCESSOR_MAPPING } from '@cloud-carbon-footprint/aws/dist/lib/AWSInstanceTypes'; +import {INSTANCE_TYPE_COMPUTE_PROCESSOR_MAPPING} from '@cloud-carbon-footprint/aws/dist/lib/AWSInstanceTypes'; import Spline from 'typescript-cubic-spline'; import { @@ -7,7 +7,7 @@ import { IImpactModelInterface, } from '../interfaces'; -import { CONFIG } from '../../config'; +import {CONFIG} from '../../config'; import * as AWS_INSTANCES from './aws-instances.json'; import * as GCP_INSTANCES from './gcp-instances.json'; @@ -19,10 +19,10 @@ import * as GCP_EMBODIED from './gcp-embodied.json'; import * as AWS_EMBODIED from './aws-embodied.json'; import * as AZURE_EMBODIED from './azure-embodied.json'; -import { KeyValuePair, Interpolation } from '../../types/common'; +import {KeyValuePair, Interpolation} from '../../types/common'; -const { MODEL_IDS } = CONFIG; -const { CCF } = MODEL_IDS; +const {MODEL_IDS} = CONFIG; +const {CCF} = MODEL_IDS; export class CloudCarbonFootprint implements IImpactModelInterface { // Defined for compatibility. Not used in CCF. @@ -250,11 +250,11 @@ export class CloudCarbonFootprint implements IImpactModelInterface { architecture = this.resolveAwsArchitecture(architecture); minWatts += this.computeInstanceUsageByArchitecture['aws'][architecture][ - 'Min Watts' + 'Min Watts' ] ?? 0; maxWatts += this.computeInstanceUsageByArchitecture['aws'][architecture][ - 'Max Watts' + 'Max Watts' ] ?? 0; count += 1; }); @@ -291,11 +291,11 @@ export class CloudCarbonFootprint implements IImpactModelInterface { consumption: { minWatts: this.computeInstanceUsageByArchitecture['gcp'][architecture][ - 'Min Watts' + 'Min Watts' ] * cpus, maxWatts: this.computeInstanceUsageByArchitecture['gcp'][architecture][ - 'Max Watts' + 'Max Watts' ] * cpus, }, maxvCPUs: parseInt( @@ -314,11 +314,11 @@ export class CloudCarbonFootprint implements IImpactModelInterface { consumption: { minWatts: this.computeInstanceUsageByArchitecture['azure'][architecture][ - 'Min Watts' + 'Min Watts' ] * cpus, maxWatts: this.computeInstanceUsageByArchitecture['azure'][architecture][ - 'Max Watts' + 'Max Watts' ] * cpus, }, name: instance['Virtual Machine'],