Skip to content

Commit

Permalink
Partial save
Browse files Browse the repository at this point in the history
  • Loading branch information
catalin-oancea committed Nov 18, 2024
1 parent a90421a commit ffda985
Show file tree
Hide file tree
Showing 4 changed files with 363 additions and 35 deletions.
5 changes: 5 additions & 0 deletions api/src/modules/custom-projects/custom-projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { DataRepository } from '@api/modules/calculations/data.repository';
import { CostInputs } from '@api/modules/custom-projects/dto/project-cost-inputs.dto';
import { CustomProjectAssumptionsDto } from '@api/modules/custom-projects/dto/project-assumptions.dto';
import { CostCalculator } from '@api/modules/calculations/cost.calculator';
import { CustomProjectSnapshotDto } from './dto/custom-project-snapshot.dto';

@Injectable()
export class CustomProjectsService extends AppBaseService<
Expand Down Expand Up @@ -61,6 +62,10 @@ export class CustomProjectsService extends AppBaseService<
return calculator.costPlans;
}

async saveCustomProject(dto: CustomProjectSnapshotDto): Promise<void> {
await this.repo.save(CustomProject.fromCustomProjectSnapshotDTO(dto));
}

async getDefaultCostInputs(
dto: GetDefaultCostInputsDto,
): Promise<CostInputs> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
IsEnum,
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
Length,
Validate,
Expand Down
215 changes: 215 additions & 0 deletions api/src/modules/custom-projects/dto/custom-project-snapshot.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
import {
IsEnum,
IsNotEmpty,
IsNumber,
IsString,
IsArray,
} from 'class-validator';
import { ACTIVITY } from '@shared/entities/activity.enum';
import { ECOSYSTEM } from '@shared/entities/ecosystem.enum';
import { LOSS_RATE_USED } from '@shared/schemas/custom-projects/create-custom-project.schema';
import { EMISSION_FACTORS_TIER_TYPES } from '@shared/entities/carbon-inputs/emission-factors.entity';

export class CustomProjectSnapshotDto {
@IsNotEmpty()
inputSnapshot: InputSnapshot;

@IsNotEmpty()
outputSnapshot: OutputSnapshot;
}

export class CostInputsDto {
@IsNumber()
feasibilityAnalysis: number;

@IsNumber()
conservationPlanningAndAdmin: number;

@IsNumber()
dataCollectionAndFieldCost: number;

@IsNumber()
communityRepresentation: number;

@IsNumber()
blueCarbonProjectPlanning: number;

@IsNumber()
establishingCarbonRights: number;

@IsNumber()
financingCost: number;

@IsNumber()
validation: number;

@IsNumber()
implementationLaborHybrid: number;

@IsNumber()
monitoring: number;

@IsNumber()
maintenance: number;

@IsNumber()
carbonStandardFees: number;

@IsNumber()
communityBenefitSharingFund: number;

@IsNumber()
baselineReassessment: number;

@IsNumber()
mrv: number;

@IsNumber()
longTermProjectOperatingCost: number;
}

export class AssumptionDto {
@IsNumber()
verificationFrequency: number;

@IsNumber()
baselineReassessmentFrequency: number;

@IsNumber()
discountRate: number;

@IsNumber()
restorationRate: number;

@IsNumber()
carbonPriceIncrease: number;

@IsNumber()
buffer: number;

@IsNumber()
projectLength: number;
}

export class InputSnapshot {
@IsString()
countryCode: string;

@IsString()
projectName: string;

@IsEnum(ACTIVITY)
activity: ACTIVITY;

@IsEnum(ECOSYSTEM)
ecosystem: ECOSYSTEM;

@IsNumber()
projectSizeHa: number;

@IsNumber()
initialCarbonPriceAssumption: number;

@IsString()
carbonRevenuesToCover: string;

@IsEnum(LOSS_RATE_USED)
lossRateUsed: LOSS_RATE_USED;

@IsEnum(EMISSION_FACTORS_TIER_TYPES)
emissionFactorUsed: EMISSION_FACTORS_TIER_TYPES;

@IsNotEmpty()
costInputs: CostInputsDto;

@IsNotEmpty()
assumptions: AssumptionDto;
}

export class OutputSnapshot {
@IsNumber()
projectLength: number;

@IsArray()
feasiabilityAnalysis: number[];

@IsArray()
conservationPlanningAndAdmin: number[];

@IsArray()
dataCollectionAndFieldCost: number[];

@IsArray()
communityRepresentation: number[];

@IsArray()
blueCarbonProjectPlanning: number[];

@IsArray()
establishingCarbonRights: number[];

@IsArray()
validation: number[];

@IsArray()
implementationLabor: number[];

@IsArray()
totalCapex: number[];

// Opex costs
@IsArray()
monitoring: number[];

@IsArray()
maintenance: number[];

@IsArray()
communityBenefitSharingFund: number[];

@IsArray()
carbonStandardFees: number[];

@IsArray()
baselineReassessment: number[];

@IsArray()
mrv: number[];

@IsArray()
longTermProjectOperatingCost: number[];

@IsArray()
totalOpex: number[];

// Total costs
@IsArray()
totalCost: number[];

@IsArray()
estCreditsIssued: number[];

@IsArray()
estRevenue: number[];

@IsArray()
annualNetIncomeRevLessOpex: number[];

@IsArray()
cummulativeNetIncomeRevLessOpex: number[];

@IsArray()
fundingGap: number[];

@IsArray()
irrOpex: number[];

@IsArray()
irrTotalCost: number[];

@IsArray()
irrAnnualNetIncome: number[];

@IsArray()
annualNetCashFlow: number[];
}
Loading

0 comments on commit ffda985

Please sign in to comment.