-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: creating restoration.project.ts
- Loading branch information
Showing
8 changed files
with
230 additions
and
15 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import { ACTIVITY } from '@shared/entities/activity.enum'; | ||
import { | ||
RestorationProjectConfig, | ||
DEFAULT_STUFF, | ||
} from '@api/modules/custom-projects/project-config.interface'; | ||
import { BaseDataView } from '@shared/entities/base-data.view'; | ||
import { CostInputs } from '@api/modules/custom-projects/cost-inputs.interface'; | ||
import { ModelAssumptions } from '@shared/entities/model-assumptions.entity'; | ||
import { RESTORATION_ACTIVITY_SUBTYPE } from '@shared/entities/projects.entity'; | ||
|
||
export class RestorationProject { | ||
name: string; | ||
activity: ACTIVITY.RESTORATION; | ||
ecosystem: string; | ||
countryCode: string; | ||
costInputs: CostInputs; | ||
modelAssumptions?: ModelAssumptions; | ||
startingPointScaling: number = | ||
DEFAULT_STUFF.RESTORATION_STARTING_POINT_SCALING; | ||
projectSizeHa: number; | ||
plantingSuccessRate: number; | ||
carbonPrice: number; | ||
carbonRevenuesToCover: string; | ||
carbonRevenuesWillNotCover: string; | ||
discountRate: number = DEFAULT_STUFF.DISCOUNT_RATE; | ||
verificationFrequency: number = DEFAULT_STUFF.VERIFICATION_FREQUENCY; | ||
carbonPriceIncrease: number = DEFAULT_STUFF.CARBON_PRICE_INCREASE; | ||
restorationRate: number = DEFAULT_STUFF.RESTORATION_RATE; | ||
buffer: number = DEFAULT_STUFF.BUFFER; | ||
soilOrganicCarbonReleaseLength: number = | ||
DEFAULT_STUFF.SOIL_ORGANIC_CARBON_RELEASE_LENGTH; | ||
restorationProjectLength: number = DEFAULT_STUFF.RESTORATION_PROJECT_LENGTH; | ||
sequestrationRateUsed?: string; | ||
projectSpecificSequestrationRate?: number; | ||
restorationActivity?: string; | ||
sequestrationRate: number; | ||
|
||
constructor(projectConfig: RestorationProjectConfig) { | ||
this.name = projectConfig.name; | ||
this.ecosystem = projectConfig.ecosystem; | ||
this.countryCode = projectConfig.countryCode; | ||
this.projectSizeHa = Number(projectConfig.projectSizeHa); | ||
this.carbonPrice = Number(projectConfig.carbonPrice) || 30; | ||
this.plantingSuccessRate = projectConfig.plantingSuccessRate; | ||
this.carbonRevenuesToCover = projectConfig.carbonRevenuesToCover || 'Opex'; | ||
this.carbonRevenuesWillNotCover = | ||
this.carbonRevenuesToCover === 'Opex' ? 'Capex' : 'None'; | ||
this.restorationActivity = projectConfig.activitySubtype; | ||
this.initializeCostInputs(projectConfig.inputData); | ||
this.setImplementationLabor(projectConfig.inputData); | ||
this.setSequestrationRate(projectConfig.inputData); | ||
this.setPlantingSuccessRate(); | ||
} | ||
|
||
private initializeCostInputs(baseData: BaseDataView): void { | ||
this.costInputs = { | ||
feasibilityAnalysis: Number(baseData.feasibilityAnalysis), | ||
conservationPlanningAndAdmin: Number( | ||
baseData.conservationPlanningAndAdmin, | ||
), | ||
dataCollectionAndFieldCost: Number(baseData.dataCollectionAndFieldCost), | ||
communityRepresentation: Number(baseData.communityRepresentation), | ||
blueCarbonProjectPlanning: Number(baseData.blueCarbonProjectPlanning), | ||
establishingCarbonRights: Number(baseData.establishingCarbonRights), | ||
validation: Number(baseData.validation), | ||
monitoring: Number(baseData.monitoring), | ||
maintenance: Number(baseData.maintenance), | ||
maintenanceDuration: Number(baseData.maintenanceDuration), | ||
communityBenefitSharingFund: Number(baseData.communityBenefitSharingFund), | ||
carbonStandardFees: Number(baseData.carbonStandardFees), | ||
baselineReassessment: Number(baseData.baselineReassessment), | ||
mrv: Number(baseData.mrv), | ||
longTermProjectOperating: Number(baseData.longTermProjectOperatingCost), | ||
financingCost: Number(baseData.financingCost), | ||
// This is set in the constructor | ||
implementationLabor: 0, | ||
projectSizeHa: Number(baseData.projectSizeHa), | ||
projectDevelopmentType: baseData.otherCommunityCashFlow, | ||
tier1SequestrationRate: baseData.tier1SequestrationRate, | ||
tier2SequestrationRate: baseData.tier2SequestrationRate, | ||
}; | ||
} | ||
|
||
setImplementationLabor(baseData: BaseDataView): void { | ||
switch (this.restorationActivity) { | ||
case RESTORATION_ACTIVITY_SUBTYPE.HYBRID: | ||
this.costInputs.implementationLabor = | ||
baseData.implementationLaborHybrid; | ||
break; | ||
case RESTORATION_ACTIVITY_SUBTYPE.PLANTING: | ||
this.costInputs.implementationLabor = | ||
baseData.implementationLaborPlanting; | ||
break; | ||
case RESTORATION_ACTIVITY_SUBTYPE.HYDROLOGY: | ||
this.costInputs.implementationLabor = | ||
baseData.implementationLaborHydrology; | ||
break; | ||
} | ||
} | ||
|
||
public setSequestrationRate(baseData: BaseDataView): void { | ||
if (this.activity !== ACTIVITY.RESTORATION) { | ||
throw new Error( | ||
'Sequestration rate can only be calculated for restoration projects.', | ||
); | ||
} | ||
|
||
if (this.sequestrationRateUsed === 'Tier 1 - IPCC default value') { | ||
this.sequestrationRate = Number(baseData.tier1SequestrationRate); | ||
} else if ( | ||
this.sequestrationRateUsed === 'Tier 2 - Country-specific rate' | ||
) { | ||
if (this.ecosystem === 'Mangrove') { | ||
this.sequestrationRate = Number(baseData.tier2SequestrationRate); | ||
} else { | ||
throw new Error( | ||
'Country-specific sequestration rate is not available for this ecosystem.', | ||
); | ||
} | ||
} else if ( | ||
this.sequestrationRateUsed === 'Tier 3 - Project-specific rate' | ||
) { | ||
if (this.projectSpecificSequestrationRate !== undefined) { | ||
this.sequestrationRate = this.projectSpecificSequestrationRate; | ||
} else { | ||
throw new Error( | ||
'Project-specific sequestration rate must be provided when "Tier 3 - Project-specific rate" is selected.', | ||
); | ||
} | ||
} else { | ||
throw new Error('Invalid sequestration rate option selected.'); | ||
} | ||
} | ||
|
||
// TODO: This is not actually setting any value, check with data | ||
public setPlantingSuccessRate(): void { | ||
if (this.activity !== ACTIVITY.RESTORATION) { | ||
throw new Error( | ||
'Planting success rate can only be set for restoration projects.', | ||
); | ||
} | ||
|
||
if ( | ||
this.restorationActivity === RESTORATION_ACTIVITY_SUBTYPE.PLANTING && | ||
this.plantingSuccessRate === undefined | ||
) { | ||
throw new Error( | ||
'Planting success rate must be provided when "Planting" is selected as the restoration activity.', | ||
); | ||
} | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from data.src.restored_code.blue_carbon_project import BlueCarbonProject | ||
|
||
# Example usage for a restoration project | ||
Project = BlueCarbonProject( | ||
activity="Conservation", # ['Restoration', 'Conservation'] | ||
ecosystem="Mangrove", # ['Mangrove', 'Seagrass', 'Salt marsh'] | ||
country="Indonesia", # [ | ||
#'United States', 'Indonesia', 'Australia', 'Caribbean', 'Kenya', 'Mexico', | ||
# 'Colombia', 'India', 'China'] | ||
master_table=master_table, | ||
base_size=base_size, | ||
base_increase=base_increase, | ||
carbon_price=20, # Default value 30 | ||
carbon_revenues_to_cover="Opex", # ['Opex', 'capex+Opex'] | ||
project_size_ha=10000, | ||
# restoration_activity='Planting', # ['Planting', 'Hybrid', 'Hydrology'] | ||
# sequestration_rate_used='Tier 1 - IPCC default value', # ['Tier 1 - IPCC default value', | ||
# 'Tier 2 - Country-specific rate', 'Tier 3 - Project-specific rate'] | ||
# project_specific_sequestration_rate=None, | ||
# planting_success_rate=0.8, # Default value 0.8 | ||
loss_rate_used="project-specific", # ['National average', 'project-specific'] | ||
project_specific_loss_rate=-0.001, | ||
emission_factor_used="Tier 2 - Country-specific emission factor", | ||
# ['Tier 1 - Global emission factor', 'Tier 2 - Country-specific emission factor', | ||
# 'Tier 3 - Project specific emission factor'] | ||
# tier_3_project_specific_emission="AGB and SOC separately", | ||
# ['One emission factor', 'AGB and SOC separately'] | ||
# tier_3_project_specific_emission_one_factor=0.5, | ||
# tier_3_emission_factor_AGB=0.5, | ||
# tier_3_emission_factor_SOC=0.5 | ||
) |