-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: social value calculations #297
Merged
Merged
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9b250f0
feat: social value calcs
zz-hh-aa bf600d1
feat: kg co2 per kwh constant
zz-hh-aa a66acad
feat: calculate social valu
zz-hh-aa d2aae19
test: SocialValue class
zz-hh-aa c6f18fd
feat: render calculated social value figures in dashboard
zz-hh-aa 685d94e
test: fix failing moneySaved value
zz-hh-aa 773ba22
nit: tidy comments, constants and vars
zz-hh-aa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
zz-hh-aa marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { SocialValue } from "./SocialValue"; | ||
import { createTestHousehold } from "./testHelpers"; | ||
|
||
const household = createTestHousehold(); | ||
const socialValue = household.socialValue | ||
describe('Social Value', () => { | ||
}) | ||
it("can be instantiated", () => { | ||
expect(socialValue).toBeInstanceOf(SocialValue) | ||
}) | ||
|
||
it("calculates money saved", () => { | ||
expect(socialValue.moneySaved).toBeCloseTo(184266.707) | ||
}) | ||
it("calculates money to community", () => { | ||
expect(socialValue.communityWealthDecade).toBeCloseTo(5917.45) | ||
}) | ||
it("calculates energy bill savings", () => { | ||
expect(socialValue.savingsEnergyPoundsYearly).toBeCloseTo(554.4) | ||
}) | ||
it("calculates amount generated for local jobs", () => { | ||
expect(socialValue.localJobs).toBeCloseTo(3.2) | ||
}) | ||
it("calculates operational carbon savings", () => { | ||
expect(socialValue.operationalCarbonSavingsYearly).toBeCloseTo(1.465) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { Household } from "./Household" | ||
import { KG_CO2_PER_KWH, NHS_SAVINGS_PER_HEAD_PER_YEAR, FTE_SPEND } from "./constants"; | ||
|
||
type ConstructorParams = { | ||
household: Household}; | ||
zz-hh-aa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export class SocialValue { | ||
public moneySaved: number; | ||
public communityWealthDecade: number; | ||
public embodiedCarbonSavings: number; | ||
public savingsEnergyPoundsYearly: number; | ||
public savingsToNHSPerHeadYearly: number; | ||
public localJobs: number; | ||
public operationalCarbonSavingsYearly: number; | ||
|
||
constructor(params: ConstructorParams) { | ||
this.moneySaved = this.calculateMoneySavedFHLP(params); | ||
this.communityWealthDecade = this.calculateCommunityWealth(params); | ||
this.embodiedCarbonSavings = 31.89; // TODO: update figures, not placing in constants.ts because it's placeholder; static number comparing average brick & block emissions vs. timber on slab | ||
zz-hh-aa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
this.savingsEnergyPoundsYearly = this.calculateSavingsEnergyPoundsYearly(params); | ||
this.savingsToNHSPerHeadYearly = NHS_SAVINGS_PER_HEAD_PER_YEAR | ||
this.localJobs = this.calculateLocalJobsSupported(params); | ||
this.operationalCarbonSavingsYearly = this.calculateCarbonSavingsYearly(params); | ||
} | ||
|
||
private calculateMoneySavedFHLP(params: ConstructorParams) { | ||
let marketPurchaseTotal = 0; | ||
let fairholdLandPurchaseTotal = 0; | ||
const lifetime = params.household.lifetime.lifetimeData | ||
for (let i = 0; i < 10; i++) { // TODO: should this include bills? TODO: do we want to show 10 years only? using 10 here because designs showed savings over 10 year period, not lifetime | ||
marketPurchaseTotal += (lifetime[i].marketLandMortgageYearly + lifetime[i].newbuildHouseMortgageYearly) | ||
fairholdLandPurchaseTotal += (lifetime[i].fairholdLandMortgageYearly + lifetime[i].depreciatedHouseMortgageYearly) | ||
} | ||
const moneySaved = marketPurchaseTotal - fairholdLandPurchaseTotal | ||
return moneySaved; | ||
} | ||
private calculateCommunityWealth(params: ConstructorParams) { | ||
const lifetime = params.household.lifetime.lifetimeData | ||
let communityWealth = 0 | ||
for (let i = 0; i < 10; i++) { // TODO: decide on time period | ||
zz-hh-aa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
communityWealth += lifetime[i].fairholdLandRentYearly | ||
} | ||
return communityWealth; | ||
} | ||
private calculateSavingsEnergyPoundsYearly(params: ConstructorParams) { | ||
const gasBillSavings = params.household.gasDemand.billExistingBuildYearly - params.household.gasDemand.billNewBuildOrRetrofitYearly | ||
return gasBillSavings; | ||
} | ||
// private calculateLocalEconomyBoost(params) {} | ||
private calculateCarbonSavingsYearly(params: ConstructorParams) { | ||
const operationalEmissionsExistingBuild = KG_CO2_PER_KWH * params.household.gasDemand.kwhExistingBuildYearly | ||
const operationalEmissionsNewBuildOrRetrofit = KG_CO2_PER_KWH * params.household.gasDemand.kwhNewBuildOrRetrofitYearly | ||
const operationalEmissionsSavedTCo2e = (operationalEmissionsExistingBuild - operationalEmissionsNewBuildOrRetrofit) / 1000 | ||
return operationalEmissionsSavedTCo2e | ||
} | ||
|
||
private calculateLocalJobsSupported(params: ConstructorParams) { | ||
const maintenanceLevel = params.household.property.maintenanceLevel | ||
const totalSpend = params.household.property.newBuildPrice + params.household.lifetime.lifetimeData[0].maintenanceCost[maintenanceLevel] | ||
let jobsSupported = totalSpend / FTE_SPEND | ||
jobsSupported = parseFloat(jobsSupported.toFixed(1)); | ||
zz-hh-aa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return jobsSupported | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you're not familiar with it, have a look at this API - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat/NumberFormat