Skip to content

Commit

Permalink
refactor: 🎨 Put emission related settings together
Browse files Browse the repository at this point in the history
All emission related frontend settings are bunched together for better readability
  • Loading branch information
mahendrapaipuri committed Oct 11, 2023
1 parent 3feabdc commit a2e7cb7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 23 deletions.
49 changes: 31 additions & 18 deletions schema/plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,15 @@
},
"$ref": "#/definitions/gpu"
},
"emissionsRefreshRate": {
"title": "Update interval for eCO2 emissions factor (ms)",
"description": "eCO2 emission factor will be updated at this interval. Do not use too small intervals as these sort of APIs are rate limited.",
"default": 1800000,
"type": "number"
},
"countryCode": {
"title": "Emissions data of country",
"description": "Emissions data of this country will be used",
"default": "fr",
"enum": ["fr"],
"type": "string"
},
"emissionsFactor": {
"title": "Emission factor in gCO2.eq/kWh",
"description": "eCO2 emission factor will be used if Emission data for the selected country is not available.",
"default": 475,
"type": "number"
"emissions": {
"title": "Emissions Estimation Settings",
"description": "Settings for the estimating eCO2 emissions",
"default": {
"countryCode": "",
"refreshRate": 1800000,
"factor": 475
},
"$ref": "#/definitions/emissions"
}
},
"additionalProperties": false,
Expand All @@ -65,6 +56,28 @@
"description": "Label for the GPU power indicator"
}
}
},
"emissions": {
"type": "object",
"properties": {
"countryCode": {
"title": "Country code",
"description": "ISO code of the country of which emission factor will be used",
"enum": ["", "fr"],
"default": "",
"type": "string"
},
"refreshRate": {
"title": "Refresh rate (ms)",
"description": "eCO2 emission factor will be updated at this interval. Do not use too small intervals as these sort of APIs are rate limited.",
"type": "number"
},
"factor": {
"title": "Emission factor (g/kWh)",
"description": "eCO2 emission factor will be used if Emission data for the selected country is not available.",
"type": "number"
}
}
}
},
"type": "object"
Expand Down
2 changes: 1 addition & 1 deletion src/emissionsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ namespace France {
/**
* Get eCo2 Emissions coefficient in g/kWh for a given country
*
* @param countryCode Country code of a country e.g. fr, uk, us, de.
* @param countryCode ISO code of the country e.g. fr, uk, us, de.
*/
async function getEmissions(countryCode: string): Promise<number> {
if (countryCode === 'fr') {
Expand Down
18 changes: 14 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ interface IResourceSettings extends JSONObject {
label: string;
}

/**
* An interface for emissions settings.
*/
interface IEmissionsSettings extends JSONObject {
countryCode: string;
refreshRate: number;
factor: number;
}

/**
* Initialization data for the jupyterlab-system-monitor extension.
*/
Expand Down Expand Up @@ -87,20 +96,21 @@ const extension: JupyterFrontEndPlugin<void> = {
);
refreshRate = DEFAULT_RAPL_REFRESH_RATE;
}
emissionsRefreshRate = settings.get('emissionsRefreshRate')
.composite as number;
const emissionsSettings = settings.get('emissions')
.composite as IEmissionsSettings;
countryCode = emissionsSettings.countryCode;
emissionsRefreshRate = emissionsSettings.refreshRate;
emissionFactor = emissionsSettings.factor;
if (emissionsRefreshRate < DEFAULT_EMISSIONS_REFRESH_RATE) {
console.log(
`Emissions update interval is floored at ${DEFAULT_EMISSIONS_REFRESH_RATE} ms`
);
emissionsRefreshRate = DEFAULT_EMISSIONS_REFRESH_RATE;
}
emissionFactor = settings.get('emissionsFactor').composite as number;
const cpuSettings = settings.get('cpu').composite as IResourceSettings;
cpuPowerLabel = cpuSettings.label;
const gpuSettings = settings.get('gpu').composite as IResourceSettings;
gpuPowerLabel = gpuSettings.label;
countryCode = settings.get('countryCode').composite as string;
}

const emissionsModel = new EmissionFactor.Model({
Expand Down

0 comments on commit a2e7cb7

Please sign in to comment.