Skip to content

Commit

Permalink
feat: Add capex and opex columns to the project entity and truncate d…
Browse files Browse the repository at this point in the history
…ata before importing a new excel file
  • Loading branch information
alepefe committed Dec 17, 2024
1 parent 7b4fd2e commit d1c60c8
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 1 deletion.
4 changes: 4 additions & 0 deletions api/src/modules/import/dtos/excel-projects.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export type ExcelProjects = {
project_size_ha: number;
project_size_filter: string;
abatement_potential: number;
capex_npv: number;
capex: number;
opex_npv: number;
opex: number;
total_cost_npv: number;
total_cost: number;
cost_per_tco2e_npv: number;
Expand Down
38 changes: 37 additions & 1 deletion api/src/modules/import/import.repostiory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,42 @@ export class ImportRepository {
baseIncrease: BaseIncrease[];
modelAssumptions: ModelAssumptions[];
}) {
return this.dataSource.transaction(async (manager) => {
return this.dataSource.transaction('READ COMMITTED', async (manager) => {
// DATA WIPE STARTS
await manager.clear(Project);
await manager.clear(ProjectSize);
await manager.clear(FeasibilityAnalysis);
await manager.clear(ConservationPlanningAndAdmin);
await manager.clear(DataCollectionAndFieldCosts);
await manager.clear(CommunityRepresentation);
await manager.clear(BlueCarbonProjectPlanning);
await manager.clear(CarbonRights);
await manager.clear(FinancingCost);
await manager.clear(ValidationCost);
await manager.clear(MonitoringCost);
await manager.clear(Maintenance);
await manager.clear(CommunityBenefitSharingFund);
await manager.clear(BaselineReassessment);
await manager.clear(MRV);
await manager.clear(LongTermProjectOperating);
await manager.clear(CarbonStandardFees);
await manager.clear(CommunityCashFlow);
await manager.clear(ImplementationLaborCost);

// Carbon inputs ingestion
await manager.clear(EcosystemExtent);
await manager.clear(EcosystemLoss);
await manager.clear(RestorableLand);
await manager.clear(SequestrationRate);
await manager.clear(EmissionFactors);

// Other tables ingestion
await manager.clear(BaseSize);
await manager.clear(BaseIncrease);
await manager.clear(ModelAssumptions);
// DATA WIPE ENDS

// CREATION STARTS
await manager.save(importData.projects);

// Cost inputs ingestion
Expand Down Expand Up @@ -102,6 +137,7 @@ export class ImportRepository {
await manager.save(importData.baseSize);
await manager.save(importData.baseIncrease);
await manager.save(importData.modelAssumptions);
// CREATION ENDS
});
}
}
4 changes: 4 additions & 0 deletions api/src/modules/import/services/entity.preprocessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,10 @@ export class EntityPreprocessor {
project.projectSize = row.project_size_ha;
project.projectSizeFilter = row.project_size_filter;
project.abatementPotential = row.abatement_potential;
project.opexNpv = row.opex_npv;
project.opex = row.opex;
project.capexNpv = row.capex_npv;
project.capex = row.capex;
project.totalCostNPV = row.total_cost_npv;
project.totalCost = row.total_cost;
// TODO: This has dissapeared from the excel file and it is required for filtering, setting a fake value for now
Expand Down
12 changes: 12 additions & 0 deletions shared/entities/projects.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@ export class Project extends BaseEntity {
@Column({ name: "abatement_potential", type: "decimal", nullable: true })
abatementPotential: number;

@Column({ name: "capex_npv", type: "decimal", nullable: true })
capexNpv: number;

@Column({ name: "capex", type: "decimal", nullable: true })
capex: number;

@Column({ name: "opex_npv", type: "decimal", nullable: true })
opexNpv: number;

@Column({ name: "opex", type: "decimal", nullable: true })
opex: number;

@Column({ name: "total_cost_npv", type: "decimal", nullable: true })
totalCostNPV: number;

Expand Down
4 changes: 4 additions & 0 deletions shared/lib/entity-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ export const createProject = async (
totalCost: 100,
costPerTCO2eNPV: 100,
costPerTCO2e: 100,
capexNpv: 100,
capex: 50,
opexNpv: 100,
opex: 50,
initialPriceAssumption: "$100",
priceType: PROJECT_PRICE_TYPE.MARKET_PRICE,
};
Expand Down

0 comments on commit d1c60c8

Please sign in to comment.