From 8480670a656e8fbdcc2ecb11bb07f5c1668c151c Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Mon, 29 Apr 2024 11:58:51 +0100 Subject: [PATCH 1/2] Add an option to exclude downstream impacts Enforce minimum 1 MAU if downstream is included --- docs/types.md | 1 + .../carbon-estimator-form.component.html | 144 ++++++++++-------- .../carbon-estimator-form.component.ts | 6 + .../carbon-estimator-form.constants.ts | 1 + .../estimate-downstream-emissions.spec.ts | 6 +- .../estimate-downstream-emissions.ts | 2 +- .../carbon-estimation.service.spec.ts | 1 + src/app/types/carbon-estimator.ts | 2 + 8 files changed, 94 insertions(+), 69 deletions(-) diff --git a/docs/types.md b/docs/types.md index 25a27bc6..e6ca92a0 100644 --- a/docs/types.md +++ b/docs/types.md @@ -39,6 +39,7 @@ classDiagram Cloud --> "cloudLocation" WorldLocation Cloud --> "monthlyCloudBill" CostRange class Downstream { + noDownstream: boolean customerLocation: WorldLocation monthlyActiveUsers: number mobilePercentage: number diff --git a/src/app/carbon-estimator-form/carbon-estimator-form.component.html b/src/app/carbon-estimator-form/carbon-estimator-form.component.html index f6ef08ac..b537faf9 100644 --- a/src/app/carbon-estimator-form/carbon-estimator-form.component.html +++ b/src/app/carbon-estimator-form/carbon-estimator-form.component.html @@ -134,78 +134,90 @@
-
-
- - -

- The purpose of your digital services is used to determine the typical amount of time a user might spend on - them and the amount of data that may be transferred. -

-

- This can affect the amount of energy used by end user devices and how much energy from network traffic is - attributable to your organisation -

-
-
- +
+ +
- -
- - -
+ @if (!noDownstream) { +
+
+ + +

+ The purpose of your digital services is used to determine the typical amount of time a user might spend + on them and the amount of data that may be transferred. +

+

+ This can affect the amount of energy used by end user devices and how much energy from network traffic + is attributable to your organisation +

+
+
+ +
+ -
-
-
diff --git a/src/app/carbon-estimator-form/carbon-estimator-form.component.ts b/src/app/carbon-estimator-form/carbon-estimator-form.component.ts index 592d93f4..19303c38 100644 --- a/src/app/carbon-estimator-form/carbon-estimator-form.component.ts +++ b/src/app/carbon-estimator-form/carbon-estimator-form.component.ts @@ -60,6 +60,7 @@ export class CarbonEstimatorFormComponent implements OnInit { public previewServerCount = 0; public noCloudServices: boolean = defaultValues.cloud.noCloudServices; + public noDownstream: boolean = defaultValues.downstream.noDownstream; public locationDescriptions = locationArray.map(location => ({ value: location, @@ -90,6 +91,7 @@ export class CarbonEstimatorFormComponent implements OnInit { monthlyCloudBill: [defaultValues.cloud.monthlyCloudBill], }), downstream: this.formBuilder.nonNullable.group({ + noDownstream: [false], customerLocation: [defaultValues.downstream.customerLocation], monthlyActiveUsers: [defaultValues.downstream.monthlyActiveUsers], mobilePercentage: [defaultValues.downstream.mobilePercentage], @@ -123,6 +125,10 @@ export class CarbonEstimatorFormComponent implements OnInit { this.changeDetector.detectChanges(); }); + this.estimatorForm + .get('downstream.noDownstream') + ?.valueChanges.subscribe(noDownstream => (this.noDownstream = noDownstream)); + this.estimatorForm.get('cloud.cloudPercentage')?.valueChanges.subscribe(cloudPercentage => { this.cloudPercentage = cloudPercentage; this.onPremisePercentage = 100 - this.cloudPercentage; diff --git a/src/app/carbon-estimator-form/carbon-estimator-form.constants.ts b/src/app/carbon-estimator-form/carbon-estimator-form.constants.ts index fb55d57f..894d99d5 100644 --- a/src/app/carbon-estimator-form/carbon-estimator-form.constants.ts +++ b/src/app/carbon-estimator-form/carbon-estimator-form.constants.ts @@ -32,6 +32,7 @@ export const defaultValues: Required = { monthlyCloudBill: costRanges[0], }, downstream: { + noDownstream: false, customerLocation: 'global', monthlyActiveUsers: 100, mobilePercentage: 50, diff --git a/src/app/estimation/estimate-downstream-emissions.spec.ts b/src/app/estimation/estimate-downstream-emissions.spec.ts index 32e8a39b..a179a0ba 100644 --- a/src/app/estimation/estimate-downstream-emissions.spec.ts +++ b/src/app/estimation/estimate-downstream-emissions.spec.ts @@ -3,9 +3,10 @@ import { sumValues } from '../utils/number-object'; import { estimateDownstreamEmissions } from './estimate-downstream-emissions'; describe('estimateDownstreamEmissions', () => { - it('should return no emissions if monthly active users is zero', () => { + it('should return no emissions if no downstream is requested', () => { const input: Downstream = { - monthlyActiveUsers: 0, + noDownstream: true, + monthlyActiveUsers: 100, customerLocation: 'global', mobilePercentage: 0, purposeOfSite: 'average', @@ -18,6 +19,7 @@ describe('estimateDownstreamEmissions', () => { function createInput(purposeOfSite: PurposeOfSite): Downstream { return { + noDownstream: false, monthlyActiveUsers: 100, customerLocation: 'global', mobilePercentage: 0, diff --git a/src/app/estimation/estimate-downstream-emissions.ts b/src/app/estimation/estimate-downstream-emissions.ts index 2bd1f015..37de77a2 100644 --- a/src/app/estimation/estimate-downstream-emissions.ts +++ b/src/app/estimation/estimate-downstream-emissions.ts @@ -55,7 +55,7 @@ export const siteTypeInfo: Record = addAverage({ }); export function estimateDownstreamEmissions(downstream: Downstream): DownstreamEstimation { - if (downstream.monthlyActiveUsers === 0) { + if (downstream.noDownstream) { return { endUser: 0, networkTransfer: 0 }; } diff --git a/src/app/services/carbon-estimation.service.spec.ts b/src/app/services/carbon-estimation.service.spec.ts index df2052b3..a68cb06c 100644 --- a/src/app/services/carbon-estimation.service.spec.ts +++ b/src/app/services/carbon-estimation.service.spec.ts @@ -23,6 +23,7 @@ const emptyEstimatorValues: EstimatorValues = { monthlyCloudBill: { min: 0, max: 200 }, }, downstream: { + noDownstream: true, customerLocation: 'global', monthlyActiveUsers: 0, mobilePercentage: 0, diff --git a/src/app/types/carbon-estimator.ts b/src/app/types/carbon-estimator.ts index 996da1e9..881b1b4a 100644 --- a/src/app/types/carbon-estimator.ts +++ b/src/app/types/carbon-estimator.ts @@ -54,6 +54,7 @@ export type EstimatorFormValues = { monthlyCloudBill: FormControl; }>; downstream: FormGroup<{ + noDownstream: FormControl; customerLocation: FormControl; monthlyActiveUsers: FormControl; mobilePercentage: FormControl; @@ -77,6 +78,7 @@ export type Cloud = { monthlyCloudBill: CostRange; }; export type Downstream = { + noDownstream: boolean; customerLocation: WorldLocation; monthlyActiveUsers: number; mobilePercentage: number; From b87386bd098af0e979be20b58835724c0408c3f4 Mon Sep 17 00:00:00 2001 From: Matthew Griffin Date: Tue, 30 Apr 2024 13:38:17 +0100 Subject: [PATCH 2/2] Add cursor-pointer to all checkbox inputs --- .../carbon-estimator-form.component.html | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/app/carbon-estimator-form/carbon-estimator-form.component.html b/src/app/carbon-estimator-form/carbon-estimator-form.component.html index b537faf9..4bf4b128 100644 --- a/src/app/carbon-estimator-form/carbon-estimator-form.component.html +++ b/src/app/carbon-estimator-form/carbon-estimator-form.component.html @@ -44,7 +44,7 @@ @@ -81,7 +81,11 @@
- +
@@ -135,7 +139,7 @@
- +