Skip to content

Commit

Permalink
Added new JSdoc typedef for components of CO2 estimate
Browse files Browse the repository at this point in the history
Added it as a union for return types that can be total or components
  • Loading branch information
mgriffin-scottlogic committed Mar 8, 2024
1 parent d4732f1 commit d6700f5
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/co2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

/**
* @typedef {Object} CO2EstimateTraceResultPerByte
* @property {number} co2 - The CO2 estimate in grams/kilowatt-hour
* @property {number|CO2EstimateComponents} co2 - The CO2 estimate in grams or its separate components
* @property {boolean} green - Whether the domain is green or not
* @property {TraceResultVariables} variables - The variables used to calculate the CO2 estimate
* @property {TraceResultVariablesPerByte} variables - The variables used to calculate the CO2 estimate
*/

/**
* @typedef {Object} CO2EstimateTraceResultPerVisit
* @property {number} co2 - The CO2 estimate in grams/kilowatt-hour
* @property {number|CO2EstimateComponents} co2 - The CO2 estimate in grams or its separate components
* @property {boolean} green - Whether the domain is green or not
* @property {TraceResultVariables} variables - The variables used to calculate the CO2 estimate
* @property {TraceResultVariablesPerVisit} variables - The variables used to calculate the CO2 estimate
*/

/**
Expand All @@ -35,6 +35,15 @@
* @property {number} production - The production grid intensity set by the user or the default
*/

/**
* @typedef {Object} CO2EstimateComponents
* @property {number} networkCO2 - The CO2 estimate for networking in grams
* @property {number} dataCenterCO2 - The CO2 estimate for data centers in grams
* @property {number} consumerDeviceCO2 - The CO2 estimate for consumer devices in grams
* @property {number} productionCO2 - The CO2 estimate for device production in grams
* @property {number} total - The total CO2 estimate in grams
*/

import OneByte from "./1byte.js";
import SustainableWebDesign from "./sustainable-web-design.js";

Expand Down Expand Up @@ -70,7 +79,7 @@ class CO2 {
*
* @param {number} bytes
* @param {boolean} green
* @return {number} the amount of CO2 in grammes
* @return {number|CO2EstimateComponents} the amount of CO2 in grammes or its separate components
*/
perByte(bytes, green = false) {
return this.model.perByte(bytes, green, this._segment);
Expand All @@ -83,7 +92,7 @@ class CO2 {
*
* @param {number} bytes
* @param {boolean} green
* @return {number} the amount of CO2 in grammes
* @return {number|CO2EstimateComponents} the amount of CO2 in grammes or its separate components
*/
perVisit(bytes, green = false) {
if (this.model?.perVisit) {
Expand Down

0 comments on commit d6700f5

Please sign in to comment.