Skip to content

Commit

Permalink
parse values to num, calculate CapexTotal
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Nov 3, 2024
1 parent 0bfdb9a commit 3ca3a85
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 45 deletions.
132 changes: 109 additions & 23 deletions api/src/modules/calculations/conservation-cost.calculator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class ConservationCostCalculator extends CostCalculator {
this.capexTotalCostPlan = this.initializeCostPlan();
this.opexTotalCostPlan = this.initializeCostPlan();
this.totalCostPlan = this.initializeCostPlan();
this.calculateCapexTotal();
}

private initializeCostPlan(): { [year: number]: number } {
Expand All @@ -43,14 +44,14 @@ export class ConservationCostCalculator extends CostCalculator {

private calculateCapexTotal(): { [year: number]: number } {
const costFunctions = [
// this.calculateFeasibilityAnalysisCost,
// this.calculateConservationPlanningAndAdmin,
// this.calculateDataCollectionAndFieldCost,
// this.calculateCommunityRepresentation,
// this.calculateBlueCarbonProjectPlanning,
// this.calculateEstablishingCarbonRights,
// this.calculateValidation,
// this.calculateImplementationLabor,
this.calculateFeasibilityAnalysisCost,
this.calculateConservationPlanningAndAdmin,
this.calculateDataCollectionAndFieldCost,
this.calculateCommunityRepresentation,
this.calculateBlueCarbonProjectPlanning,
this.calculateEstablishingCarbonRights,
this.calculateValidation,
this.calculateImplementationLabor,
];

for (const costFunc of costFunctions) {
Expand All @@ -61,6 +62,82 @@ export class ConservationCostCalculator extends CostCalculator {
return this.capexTotalCostPlan;
}

private calculateFeasibilityAnalysisCost(): { [year: number]: number } {
const totalBaseCost = this.calculateCostPlan('feasibilityAnalysis');
const feasibilityAnalysisCostPlan = this.createSimplePlan(totalBaseCost, [
-4,
]);
return feasibilityAnalysisCostPlan;
}

private calculateConservationPlanningAndAdmin(): { [year: number]: number } {
const totalBaseCost = this.calculateCostPlan(
'conservationPlanningAndAdmin',
);
const conservationPlanningAndAdminCostPlan = this.createSimplePlan(
totalBaseCost,
[-4, -3, -2, -1],
);
return conservationPlanningAndAdminCostPlan;
}

private calculateDataCollectionAndFieldCost(): { [year: number]: number } {
const totalBaseCost = this.calculateCostPlan('dataCollectionAndFieldCost');
const dataCollectionAndFieldCostPlan = this.createSimplePlan(
totalBaseCost,
[-4, -3, -2],
);
return dataCollectionAndFieldCostPlan;
}

private calculateCommunityRepresentation(): { [year: number]: number } {
const totalBaseCost = this.calculateCostPlan('communityRepresentation');
const projectDevelopmentType =
this.project.costInputs.projectDevelopmentType;
const initialCostPlan =
projectDevelopmentType === 'Development' ? totalBaseCost : 0;
const communityRepresentationCostPlan = this.createSimplePlan(
totalBaseCost,
[-4, -3, -2],
);
communityRepresentationCostPlan[-4] = initialCostPlan;
return communityRepresentationCostPlan;
}

private calculateBlueCarbonProjectPlanning(): { [year: number]: number } {
const totalBaseCost = this.calculateCostPlan('blueCarbonProjectPlanning');
const blueCarbonProjectPlanningCostPlan = this.createSimplePlan(
totalBaseCost,
[-1],
);
return blueCarbonProjectPlanningCostPlan;
}

private calculateEstablishingCarbonRights(): { [year: number]: number } {
const totalBaseCost = this.calculateCostPlan('establishingCarbonRights');
const establishingCarbonRightsCostPlan = this.createSimplePlan(
totalBaseCost,
[-3, -2, -1],
);
return establishingCarbonRightsCostPlan;
}

private calculateValidation(): { [year: number]: number } {
const totalBaseCost = this.calculateCostPlan('validation');
const validationCostPlan = this.createSimplePlan(totalBaseCost, [-1]);
return validationCostPlan;
}

private calculateImplementationLabor(): { [year: number]: number } {
// TODO: This needs SequestrationCreditsCalculator to be implemented
const totalBaseCost = this.project.costInputs.implementationLabor;
return totalBaseCost as any;
// const implementationLaborCostPlan = this.createSimplePlan(totalBaseCost, [
// -1,
// ]);
// return implementationLaborCostPlan;
}

private aggregateCosts(
costPlan: { [year: number]: number },
totalCostPlan: { [year: number]: number },
Expand All @@ -71,19 +148,28 @@ export class ConservationCostCalculator extends CostCalculator {
}
}

// private calculateFeasibilityAnalysisCost(): { [year: number]: number } {
// const totalBaseCost = this.calculateCostPlan(
// this.project.baseSize,
// this.project.baseIncrease,
// this.project.projectSizeHa,
// 'feasibility_analysis',
// this.project.feasibilityAnalysis,
// this.project.activity,
// this.project.ecosystem,
// );
// const feasibilityAnalysisCostPlan = this.createSimplePlan(totalBaseCost, [
// -4,
// ]);
// return feasibilityAnalysisCostPlan;
// }
private calculateCostPlan(baseKey: any): number {
const increasedBy: number = parseFloat(this.baseIncrease[baseKey]);
const baseCostValue: number = parseFloat(this.baseSize[baseKey]);
const sizeDifference =
this.project.projectSizeHa - this.startingPointScaling;
const value = Math.max(Math.round(sizeDifference / baseCostValue), 0);

const totalBaseCost = baseCostValue + increasedBy * value * baseCostValue;
return totalBaseCost;
}

private createSimplePlan(
totalBaseCost: number,
years?: number[],
): { [year: number]: number } {
if (!years) {
years = [-4, -3, -2, -1];
}
const plan: { [year: number]: number } = {};
for (const year of years) {
plan[year] = totalBaseCost;
}
return plan;
}
}
46 changes: 25 additions & 21 deletions api/src/modules/custom-projects/conservation.project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ export class ConservationProject {
this.name = projectConfig.name;
this.ecosystem = projectConfig.ecosystem;
this.countryCode = projectConfig.countryCode;
this.projectSizeHa = projectConfig.projectSizeHa;
this.carbonPrice = projectConfig.carbonPrice || 30;
this.projectSizeHa = Number(projectConfig.projectSizeHa);
this.carbonPrice = Number(projectConfig.carbonPrice) || 30;
this.carbonRevenuesToCover = projectConfig.carbonRevenuesToCover || 'Opex';
this.carbonRevenuesWillNotCover =
this.carbonRevenuesToCover === 'Opex' ? 'Capex' : 'None';
this.lossRate = this.setLossRate(projectConfig.inputData);
this.lossRate = Number(this.setLossRate(projectConfig.inputData));
this.emissionFactorUsed = projectConfig.emissionFactorUsed;
this.tier3ProjectSpecificEmission =
projectConfig.tier3ProjectSpecificEmission;
Expand All @@ -59,25 +59,29 @@ export class ConservationProject {

private initializeCostInputs(baseData: BaseDataView): void {
this.costInputs = {
feasibilityAnalysis: baseData.feasibilityAnalysis,
conservationPlanningAndAdmin: baseData.conservationPlanningAndAdmin,
dataCollectionAndFieldCost: baseData.dataCollectionAndFieldCost,
communityRepresentation: baseData.communityRepresentation,
blueCarbonProjectPlanning: baseData.blueCarbonProjectPlanning,
establishingCarbonRights: baseData.establishingCarbonRights,
validation: baseData.validation,
monitoring: baseData.monitoring,
maintenance: baseData.maintenance,
communityBenefitSharingFund: baseData.communityBenefitSharingFund,
carbonStandardFees: baseData.carbonStandardFees,
baselineReassessment: baseData.baselineReassessment,
mrv: baseData.mrv,
longTermProjectOperating: baseData.longTermProjectOperatingCost,
financingCost: baseData.financingCost,
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),
communityBenefitSharingFund: Number(baseData.communityBenefitSharingFund),
carbonStandardFees: Number(baseData.carbonStandardFees),
baselineReassessment: Number(baseData.baselineReassessment),
mrv: Number(baseData.mrv),
longTermProjectOperating: Number(baseData.longTermProjectOperatingCost),
financingCost: Number(baseData.financingCost),
implementationLabor: 0, // It's set to 0 for Conservation projects
// TODO: Not sure if the below 2 properties are cost inputs
lossRate: this.setLossRate(baseData),
projectSizeHa: baseData.projectSizeHa,
// TODO: Not sure if the below properties are cost inputs
lossRate: Number(this.setLossRate(baseData)),
projectSizeHa: Number(baseData.projectSizeHa),
// Below is not a numeric value: Development, Non-Development
projectDevelopmentType: baseData.otherCommunityCashFlow,
//emissionFactor: this.setEmissionFactor(baseData),
};
}
Expand Down
1 change: 1 addition & 0 deletions api/src/modules/custom-projects/cost-inputs.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export interface CostInputs {
emissionFactor?: number;
// Not sure if projectSizeHa is a cost input
projectSizeHa?: number;
projectDevelopmentType?: string;
}
2 changes: 1 addition & 1 deletion api/src/modules/custom-projects/custom-projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ export class CustomProjectsService extends AppBaseService<
baseIncrease,
baseSize,
);
return calculator;
return calculator.capexTotalCostPlan;
}
}

0 comments on commit 3ca3a85

Please sign in to comment.