diff --git a/api/apps/api/src/modules/clone/export/adapters/export-resource-pieces.adapter.spec.ts b/api/apps/api/src/modules/clone/export/adapters/export-resource-pieces.adapter.spec.ts index c40f1f32eb..173b309a78 100644 --- a/api/apps/api/src/modules/clone/export/adapters/export-resource-pieces.adapter.spec.ts +++ b/api/apps/api/src/modules/clone/export/adapters/export-resource-pieces.adapter.spec.ts @@ -99,7 +99,7 @@ const getFixtures = async () => { ClonePiece.ProjectCustomProtectedAreas, ClonePiece.ProjectCostSurfaces, ClonePiece.ProjectCustomFeatures, - ClonePiece.ProjectPuvsprCalculations, + ClonePiece.ProjectFeatureAmountsPerPlanningUnit, ]; }; diff --git a/api/apps/api/src/modules/clone/export/adapters/export-resource-pieces.adapter.ts b/api/apps/api/src/modules/clone/export/adapters/export-resource-pieces.adapter.ts index 271193f6f1..7441d3b07c 100644 --- a/api/apps/api/src/modules/clone/export/adapters/export-resource-pieces.adapter.ts +++ b/api/apps/api/src/modules/clone/export/adapters/export-resource-pieces.adapter.ts @@ -58,7 +58,10 @@ export class ExportResourcePiecesAdapter implements ExportResourcePieces { ExportComponent.newOne(id, ClonePiece.ProjectCustomProtectedAreas), ExportComponent.newOne(id, ClonePiece.ProjectCostSurfaces), ExportComponent.newOne(id, ClonePiece.ProjectCustomFeatures), - ExportComponent.newOne(id, ClonePiece.ProjectPuvsprCalculations), + ExportComponent.newOne( + id, + ClonePiece.ProjectFeatureAmountsPerPlanningUnit, + ), ...scenarioPieces, ]; diff --git a/api/apps/api/src/modules/scenarios-features/compute-area.service.spec.ts b/api/apps/api/src/modules/scenarios-features/compute-area.service.spec.ts index ccb4a30834..f38f0396a2 100644 --- a/api/apps/api/src/modules/scenarios-features/compute-area.service.spec.ts +++ b/api/apps/api/src/modules/scenarios-features/compute-area.service.spec.ts @@ -1,9 +1,9 @@ import { ProjectSourcesEnum } from '@marxan/projects'; import { - MemoryPuvsprCalculationsRepository, - PuvsprCalculationsRepository, - PuvsprCalculationsService, -} from '@marxan/puvspr-calculations'; + MemoryFeatureAmountsPerPlanningUnitRepository, + FeatureAmountsPerPlanningUnitRepository, + FeatureAmountsPerPlanningUnitService, +} from '@marxan/feature-amounts-per-planning-unit'; import { FixtureType } from '@marxan/utils/tests/fixture-type'; import { Test } from '@nestjs/testing'; import { getRepositoryToken } from '@nestjs/typeorm'; @@ -43,11 +43,11 @@ const getFixtures = async () => { useValue: { find: findProjectMock }, }, { - provide: PuvsprCalculationsRepository, - useClass: MemoryPuvsprCalculationsRepository, + provide: FeatureAmountsPerPlanningUnitRepository, + useClass: MemoryFeatureAmountsPerPlanningUnitRepository, }, { - provide: PuvsprCalculationsService, + provide: FeatureAmountsPerPlanningUnitService, useValue: { computeMarxanAmountPerPlanningUnit: computeMarxanAmountPerPlanningUnitMock, @@ -60,8 +60,8 @@ const getFixtures = async () => { await sandbox.init(); const sut = sandbox.get(ComputeArea); - const puvsprCalculationsRepo: MemoryPuvsprCalculationsRepository = - sandbox.get(PuvsprCalculationsRepository); + const featureAmountsPerPlanningUnitRepo: MemoryFeatureAmountsPerPlanningUnitRepository = + sandbox.get(FeatureAmountsPerPlanningUnitRepository); const expectedPuid = v4(); const expectedAmount = 20; @@ -106,7 +106,7 @@ const getFixtures = async () => { featureId: string, ) => { const savedCalculations = - await puvsprCalculationsRepo.getAmountPerPlanningUnitAndFeature( + await featureAmountsPerPlanningUnitRepo.getAmountPerPlanningUnitAndFeature( projectId, [featureId], ); @@ -124,7 +124,7 @@ const getFixtures = async () => { ) => { expect(computeMarxanAmountPerPlanningUnitMock).not.toHaveBeenCalled(); const hasBeenSaved = - await puvsprCalculationsRepo.areAmountPerPlanningUnitAndFeatureSaved( + await featureAmountsPerPlanningUnitRepo.areAmountPerPlanningUnitAndFeatureSaved( projectId, featureId, ); diff --git a/api/apps/api/src/modules/scenarios-features/compute-area.service.ts b/api/apps/api/src/modules/scenarios-features/compute-area.service.ts index 9d3f18a123..d8b8f5f76b 100644 --- a/api/apps/api/src/modules/scenarios-features/compute-area.service.ts +++ b/api/apps/api/src/modules/scenarios-features/compute-area.service.ts @@ -1,8 +1,8 @@ import { ProjectSourcesEnum } from '@marxan/projects'; import { - PuvsprCalculationsRepository, - PuvsprCalculationsService, -} from '@marxan/puvspr-calculations'; + FeatureAmountsPerPlanningUnitRepository, + FeatureAmountsPerPlanningUnitService, +} from '@marxan/feature-amounts-per-planning-unit'; import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; @@ -11,8 +11,8 @@ import { Project } from '../projects/project.api.entity'; @Injectable() export class ComputeArea { constructor( - private readonly puvsprCalculationsRepo: PuvsprCalculationsRepository, - private readonly puvsprCalculations: PuvsprCalculationsService, + private readonly featureAmountsPerPlanningUnitRepo: FeatureAmountsPerPlanningUnitRepository, + private readonly featureAmountsPerPlanningUnit: FeatureAmountsPerPlanningUnitService, @InjectRepository(Project) private readonly projectsRepo: Repository, ) {} @@ -26,7 +26,7 @@ export class ComputeArea { if (isLegacyProject) return; const alreadyComputed = - await this.puvsprCalculationsRepo.areAmountPerPlanningUnitAndFeatureSaved( + await this.featureAmountsPerPlanningUnitRepo.areAmountPerPlanningUnitAndFeatureSaved( projectId, featureId, ); @@ -34,12 +34,12 @@ export class ComputeArea { if (alreadyComputed) return; const amountPerPlanningUnitOfFeature = - await this.puvsprCalculations.computeMarxanAmountPerPlanningUnit( + await this.featureAmountsPerPlanningUnit.computeMarxanAmountPerPlanningUnit( featureId, scenarioId, ); - return this.puvsprCalculationsRepo.saveAmountPerPlanningUnitAndFeature( + return this.featureAmountsPerPlanningUnitRepo.saveAmountPerPlanningUnitAndFeature( projectId, amountPerPlanningUnitOfFeature.map( ({ featureId, projectPuId, amount }) => ({ diff --git a/api/apps/api/src/modules/scenarios-features/scenario-features.module.ts b/api/apps/api/src/modules/scenarios-features/scenario-features.module.ts index 81df2e5852..6009b99d96 100644 --- a/api/apps/api/src/modules/scenarios-features/scenario-features.module.ts +++ b/api/apps/api/src/modules/scenarios-features/scenario-features.module.ts @@ -28,7 +28,7 @@ import { import { AccessControlModule } from '@marxan-api/modules/access-control'; import { ComputeArea } from './compute-area.service'; import { LegacyProjectImportRepositoryModule } from '../legacy-project-import/infra/legacy-project-import.repository.module'; -import { PuvsprCalculationsModule } from '@marxan/puvspr-calculations'; +import { FeatureAmountsPerPlanningUnitModule } from '@marxan/feature-amounts-per-planning-unit'; import { SplitFeatureConfigMapper } from '../scenarios/specification/split-feature-config.mapper'; import { FeatureHashModule } from '../features-hash/features-hash.module'; import { SplitCreateFeatures } from './split/split-create-features.service'; @@ -47,7 +47,7 @@ import { Project } from '../projects/project.api.entity'; DbConnections.geoprocessingDB, ), FeatureHashModule, - PuvsprCalculationsModule.for(DbConnections.geoprocessingDB), + FeatureAmountsPerPlanningUnitModule.for(DbConnections.geoprocessingDB), ProjectsModule, ApiEventsModule, IntersectWithPuModule, diff --git a/api/apps/api/src/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.legacy-project.ts b/api/apps/api/src/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.legacy-project.ts index f001a4c47d..0adb9561d9 100644 --- a/api/apps/api/src/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.legacy-project.ts +++ b/api/apps/api/src/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.legacy-project.ts @@ -1,5 +1,5 @@ import { GeoFeature } from '@marxan-api/modules/geo-features/geo-feature.api.entity'; -import { PuvsprCalculationsService } from '@marxan/puvspr-calculations'; +import { FeatureAmountsPerPlanningUnitService } from '@marxan/feature-amounts-per-planning-unit'; import { Injectable } from '@nestjs/common'; import { FeatureAmountPerPlanningUnitId, PuvsprDat } from './puvsrpr.dat'; import { InjectRepository } from '@nestjs/typeorm'; @@ -8,7 +8,7 @@ import { Repository, In } from 'typeorm'; @Injectable() export class PuvsprDatLegacyProject implements PuvsprDat { constructor( - private readonly puvsprCalculations: PuvsprCalculationsService, + private readonly featureAmountsPerPlanningUnit: FeatureAmountsPerPlanningUnitService, @InjectRepository(GeoFeature) private readonly featuresRepo: Repository, ) {} @@ -57,7 +57,7 @@ export class PuvsprDatLegacyProject implements PuvsprDat { ): Promise { const legacyFeaturesComputations = await Promise.all( featureIds.map((featureId) => - this.puvsprCalculations.computeLegacyAmountPerPlanningUnit( + this.featureAmountsPerPlanningUnit.computeLegacyAmountPerPlanningUnit( featureId, scenarioId, ), @@ -76,7 +76,7 @@ export class PuvsprDatLegacyProject implements PuvsprDat { ): Promise { const marxanFeaturesComputations = await Promise.all( featureIds.map((featureId) => - this.puvsprCalculations.computeMarxanAmountPerPlanningUnit( + this.featureAmountsPerPlanningUnit.computeMarxanAmountPerPlanningUnit( featureId, scenarioId, ), diff --git a/api/apps/api/src/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.marxan-project.ts b/api/apps/api/src/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.marxan-project.ts index c740dadcd0..1d00eb2d82 100644 --- a/api/apps/api/src/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.marxan-project.ts +++ b/api/apps/api/src/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.marxan-project.ts @@ -1,6 +1,6 @@ import { DbConnections } from '@marxan-api/ormconfig.connections'; import { ProjectsPuEntity } from '@marxan-jobs/planning-unit-geometry'; -import { PuvsprCalculationsRepository } from '@marxan/puvspr-calculations'; +import { FeatureAmountsPerPlanningUnitRepository } from '@marxan/feature-amounts-per-planning-unit'; import { Injectable } from '@nestjs/common'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; @@ -9,7 +9,7 @@ import { FeatureAmountPerPlanningUnitId, PuvsprDat } from './puvsrpr.dat'; @Injectable() export class PuvsprDatMarxanProject implements PuvsprDat { constructor( - private readonly puvsprCalculationsRepo: PuvsprCalculationsRepository, + private readonly featureAmountsPerPlanningUnitRepo: FeatureAmountsPerPlanningUnitRepository, @InjectRepository(ProjectsPuEntity, DbConnections.geoprocessingDB) private readonly projectsPusRepo: Repository, ) {} @@ -19,7 +19,7 @@ export class PuvsprDatMarxanProject implements PuvsprDat { featureIds: string[], ): Promise { const amountPerPlanningUnitOfFeature = - await this.puvsprCalculationsRepo.getAmountPerPlanningUnitAndFeature( + await this.featureAmountsPerPlanningUnitRepo.getAmountPerPlanningUnitAndFeature( projectId, featureIds, ); diff --git a/api/apps/api/src/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.processor.module.ts b/api/apps/api/src/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.processor.module.ts index 647b38b674..01dda88b2b 100644 --- a/api/apps/api/src/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.processor.module.ts +++ b/api/apps/api/src/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.processor.module.ts @@ -4,7 +4,7 @@ import { SpecificationAdaptersModule } from '@marxan-api/modules/specification/a import { DbConnections } from '@marxan-api/ormconfig.connections'; import { ScenarioFeaturesData } from '@marxan/features'; import { GeoFeatureGeometry } from '@marxan/geofeatures'; -import { PuvsprCalculationsModule } from '@marxan/puvspr-calculations'; +import { FeatureAmountsPerPlanningUnitModule } from '@marxan/feature-amounts-per-planning-unit'; import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { Scenario } from '../../scenario.api.entity'; @@ -19,7 +19,7 @@ import { ProjectsPuEntity } from '@marxan-jobs/planning-unit-geometry'; @Module({ imports: [ - PuvsprCalculationsModule.for(DbConnections.geoprocessingDB), + FeatureAmountsPerPlanningUnitModule.for(DbConnections.geoprocessingDB), FeatureHashModule, TypeOrmModule.forFeature([Scenario, GeoFeature]), TypeOrmModule.forFeature( diff --git a/api/apps/api/src/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.processor.ts b/api/apps/api/src/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.processor.ts index ddcdae9bf0..f1fb18ed1e 100644 --- a/api/apps/api/src/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.processor.ts +++ b/api/apps/api/src/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.processor.ts @@ -13,7 +13,7 @@ import { import { SpecificationRepository } from '@marxan-api/modules/specification/application/specification.repository'; import { Specification } from '@marxan-api/modules/specification/domain'; import { SingleSplitConfigFeatureValue } from '@marxan/features-hash'; -import { PuvsprCalculationsService } from '@marxan/puvspr-calculations'; +import { FeatureAmountsPerPlanningUnitService } from '@marxan/feature-amounts-per-planning-unit'; import { SpecificationOperation } from '@marxan/specification'; import { Injectable } from '@nestjs/common'; import { InjectEntityManager } from '@nestjs/typeorm'; @@ -38,7 +38,7 @@ export class PuvsprDatProcessor { private readonly scenarioSpecificationsRepo: ScenarioSpecificationRepo, private readonly specificationsRepo: SpecificationRepository, private readonly geoFeatureMapper: GeoFeatureDtoMapper, - private readonly puvsprCalculationsService: PuvsprCalculationsService, + private readonly featureAmountsPerPlanningUnitService: FeatureAmountsPerPlanningUnitService, private readonly splitConfigHasher: SingleConfigFeatureValueHasher, private readonly splitFeatureConfigMapper: SplitFeatureConfigMapper, private readonly puvsprDatFactory: PuvrsprDatFactory, @@ -58,7 +58,7 @@ export class PuvsprDatProcessor { const featuresIds = await this.getFeaturesIds(specification); const featuresIdsWithSpeciesId = - await this.puvsprCalculationsService.computeSpeciesId( + await this.featureAmountsPerPlanningUnitService.computeSpeciesId( featuresIds, scenarioId, ); diff --git a/api/apps/api/test/jest-e2e.json b/api/apps/api/test/jest-e2e.json index 452299a072..5e8805b4ae 100644 --- a/api/apps/api/test/jest-e2e.json +++ b/api/apps/api/test/jest-e2e.json @@ -88,8 +88,8 @@ "@marxan/planning-units-grid": "/../../../libs/planning-units-grid/src", "@marxan/protected-areas/(.*)": "/../../../libs/protected-areas/src/$1", "@marxan/protected-areas": "/../../../libs/protected-areas/src", - "@marxan/puvspr-calculations/(.*)": "/../../../libs/puvspr-calculations/src/$1", - "@marxan/puvspr-calculations": "/../../../libs/puvspr-calculations/src", + "@marxan/feature-amounts-per-planning-unit/(.*)": "/../../../libs/feature-amounts-per-planning-unit/src/$1", + "@marxan/feature-amounts-per-planning-unit": "/../../../libs/feature-amounts-per-planning-unit/src", "@marxan/specification/(.*)": "/../../../libs/specification/src/$1", "@marxan/specification": "/../../../libs/specification/src", "@marxan/tiles/(.*)": "/../../../libs/tiles/src/$1", diff --git a/api/apps/geoprocessing/src/export/pieces-exporters/pieces-exporters.module.ts b/api/apps/geoprocessing/src/export/pieces-exporters/pieces-exporters.module.ts index 0f0e3cfb8e..a48e62e899 100644 --- a/api/apps/geoprocessing/src/export/pieces-exporters/pieces-exporters.module.ts +++ b/api/apps/geoprocessing/src/export/pieces-exporters/pieces-exporters.module.ts @@ -6,7 +6,7 @@ import { MarxanExecutionMetadataGeoEntity, OutputScenariosFeaturesDataGeoEntity, } from '@marxan/marxan-output'; -import { PuvsprCalculationsModule } from '@marxan/puvspr-calculations'; +import { FeatureAmountsPerPlanningUnitModule } from '@marxan/feature-amounts-per-planning-unit'; import { Logger, Module } from '@nestjs/common'; import { HttpModule } from '@nestjs/axios'; import { TypeOrmModule } from '@nestjs/typeorm'; @@ -21,7 +21,7 @@ import { PlanningUnitsGridPieceExporter } from './planning-units-grid.piece-expo import { ProjectCustomFeaturesPieceExporter } from './project-custom-features.piece-exporter'; import { ProjectCustomProtectedAreasPieceExporter } from './project-custom-protected-areas.piece-exporter'; import { ProjectMetadataPieceExporter } from './project-metadata.piece-exporter'; -import { ProjectPuvsprCalculationsPieceExporter } from './project-puvspr-calculations.piece-exporter'; +import { ProjectFeatureAmountsPerPlanningUnitPieceExporter } from './project-feature-amounts-per-planning-unit.piece-exporter'; import { ScenarioFeaturesDataPieceExporter } from './scenario-features-data.piece-exporter'; import { ScenarioFeaturesSpecificationPieceExporter } from './scenario-features-specification.piece-exporter'; import { ScenarioInputFolderPieceExporter } from './scenario-input-folder.piece-exporter'; @@ -45,7 +45,9 @@ import { ProjectCostSurfacesPieceExporter } from '@marxan-geoprocessing/export/p ], geoprocessingConnections.default, ), - PuvsprCalculationsModule.for(geoprocessingConnections.default.name!), + FeatureAmountsPerPlanningUnitModule.for( + geoprocessingConnections.default.name!, + ), HttpModule, ], providers: [ @@ -69,7 +71,7 @@ import { ProjectCostSurfacesPieceExporter } from '@marxan-geoprocessing/export/p ScenarioOutputFolderPieceExporter, ScenarioFeaturesSpecificationPieceExporter, MarxanExecutionMetadataPieceExporter, - ProjectPuvsprCalculationsPieceExporter, + ProjectFeatureAmountsPerPlanningUnitPieceExporter, Logger, ], }) diff --git a/api/apps/geoprocessing/src/export/pieces-exporters/project-puvspr-calculations.piece-exporter.ts b/api/apps/geoprocessing/src/export/pieces-exporters/project-feature-amounts-per-planning-unit.piece-exporter.ts similarity index 85% rename from api/apps/geoprocessing/src/export/pieces-exporters/project-puvspr-calculations.piece-exporter.ts rename to api/apps/geoprocessing/src/export/pieces-exporters/project-feature-amounts-per-planning-unit.piece-exporter.ts index 1c096cce76..114044fd5c 100644 --- a/api/apps/geoprocessing/src/export/pieces-exporters/project-puvspr-calculations.piece-exporter.ts +++ b/api/apps/geoprocessing/src/export/pieces-exporters/project-feature-amounts-per-planning-unit.piece-exporter.ts @@ -4,12 +4,12 @@ import { ClonePiece, ExportJobInput, ExportJobOutput } from '@marxan/cloning'; import { CloningFilesRepository } from '@marxan/cloning-files-repository'; import { ComponentLocation, ResourceKind } from '@marxan/cloning/domain'; import { ClonePieceRelativePathResolver } from '@marxan/cloning/infrastructure/clone-piece-data'; -import { ProjectPuvsprCalculationsContent } from '@marxan/cloning/infrastructure/clone-piece-data/project-puvspr-calculations'; +import { ProjectFeatureAmountsPerPlanningUnitContent } from '@marxan/cloning/infrastructure/clone-piece-data/project-feature-amounts-per-planning-unit'; import { SingleConfigFeatureValueStripped } from '@marxan/features-hash'; import { FeatureAmountPerProjectPlanningUnit, - PuvsprCalculationsRepository, -} from '@marxan/puvspr-calculations'; + FeatureAmountsPerPlanningUnitRepository, +} from '@marxan/feature-amounts-per-planning-unit'; import { SpecificationOperation } from '@marxan/specification'; import { Injectable, Logger } from '@nestjs/common'; import { InjectEntityManager, InjectRepository } from '@nestjs/typeorm'; @@ -36,16 +36,16 @@ type FeatureByIdMap = Record>; @Injectable() @PieceExportProvider() -export class ProjectPuvsprCalculationsPieceExporter +export class ProjectFeatureAmountsPerPlanningUnitPieceExporter implements ExportPieceProcessor { private readonly logger: Logger = new Logger( - ProjectPuvsprCalculationsPieceExporter.name, + ProjectFeatureAmountsPerPlanningUnitPieceExporter.name, ); constructor( private readonly fileRepository: CloningFilesRepository, - private readonly puvsprCalculationsRepo: PuvsprCalculationsRepository, + private readonly featureAmountsPerPlanningUnitRepo: FeatureAmountsPerPlanningUnitRepository, @InjectRepository(ProjectsPuEntity) private readonly projectPusRepo: Repository, @InjectEntityManager(geoprocessingConnections.apiDB) @@ -54,7 +54,7 @@ export class ProjectPuvsprCalculationsPieceExporter isSupported(piece: ClonePiece, kind: ResourceKind): boolean { return ( - piece === ClonePiece.ProjectPuvsprCalculations && + piece === ClonePiece.ProjectFeatureAmountsPerPlanningUnit && kind === ResourceKind.Project ); } @@ -63,7 +63,7 @@ export class ProjectPuvsprCalculationsPieceExporter const projectId = input.resourceId; const featureAmountPerPlanningUnit = - await this.puvsprCalculationsRepo.getAmountPerPlanningUnitAndFeatureInProject( + await this.featureAmountsPerPlanningUnitRepo.getAmountPerPlanningUnitAndFeatureInProject( projectId, ); @@ -76,13 +76,13 @@ export class ProjectPuvsprCalculationsPieceExporter const projectFeaturesGeoOperations = await this.getProjectFeaturesGeoOperations(projectId); - const fileContent: ProjectPuvsprCalculationsContent = { - puvsprCalculations: featuresAmountPerPlanningUnitParsed, + const fileContent: ProjectFeatureAmountsPerPlanningUnitContent = { + featureAmountsPerPlanningUnit: featuresAmountPerPlanningUnitParsed, projectFeaturesGeoOperations, }; const relativePath = ClonePieceRelativePathResolver.resolveFor( - ClonePiece.ProjectPuvsprCalculations, + ClonePiece.ProjectFeatureAmountsPerPlanningUnit, ); const outputFile = await this.fileRepository.saveCloningFile( @@ -92,7 +92,7 @@ export class ProjectPuvsprCalculationsPieceExporter ); if (isLeft(outputFile)) { - const errorMessage = `${ProjectPuvsprCalculationsPieceExporter.name} - Project - couldn't save file - ${outputFile.left.description}`; + const errorMessage = `${ProjectFeatureAmountsPerPlanningUnitPieceExporter.name} - Project - couldn't save file - ${outputFile.left.description}`; this.logger.error(errorMessage); throw new Error(errorMessage); } diff --git a/api/apps/geoprocessing/src/import/pieces-importers/pieces-importers.module.ts b/api/apps/geoprocessing/src/import/pieces-importers/pieces-importers.module.ts index 6d797e537e..f10abccab5 100644 --- a/api/apps/geoprocessing/src/import/pieces-importers/pieces-importers.module.ts +++ b/api/apps/geoprocessing/src/import/pieces-importers/pieces-importers.module.ts @@ -1,7 +1,7 @@ import { GeoCloningFilesRepositoryModule } from '@marxan-geoprocessing/modules/cloning-files-repository'; import { geoprocessingConnections } from '@marxan-geoprocessing/ormconfig'; import { ProjectsPuEntity } from '@marxan-jobs/planning-unit-geometry'; -import { PuvsprCalculationsEntity } from '@marxan/puvspr-calculations'; +import { FeatureAmountsPerPlanningUnitEntity } from '@marxan/feature-amounts-per-planning-unit'; import { Module } from '@nestjs/common'; import { TypeOrmModule } from '@nestjs/typeorm'; import { ScenariosOutputResultsApiEntity } from '../../../../../libs/marxan-output/src'; @@ -12,7 +12,7 @@ import { PlanningUnitsGridPieceImporter } from './planning-units-grid.piece-impo import { ProjectCustomFeaturesPieceImporter } from './project-custom-features.piece-importer'; import { ProjectCustomProtectedAreasPieceImporter } from './project-custom-protected-areas.piece-importer'; import { ProjectMetadataPieceImporter } from './project-metadata.piece-importer'; -import { ProjectPuvsprCalculationsPieceImporter } from './project-puvspr-calculations.piece-importer'; +import { ProjectFeatureAmountsPerPlanningUnitPieceImporter } from './project-feature-amounts-per-planning-unit.piece-importer'; import { ScenarioFeaturesDataPieceImporter } from './scenario-features-data.piece-importer'; import { ScenarioFeaturesSpecificationPieceImporter } from './scenario-features-specification.piece-importer'; import { ScenarioMetadataPieceImporter } from './scenario-metadata.piece-importer'; @@ -28,7 +28,10 @@ import { ProjectCostSurfacesPieceImporter } from '@marxan-geoprocessing/import/p [ScenariosOutputResultsApiEntity], geoprocessingConnections.apiDB, ), - TypeOrmModule.forFeature([PuvsprCalculationsEntity, ProjectsPuEntity]), + TypeOrmModule.forFeature([ + FeatureAmountsPerPlanningUnitEntity, + ProjectsPuEntity, + ]), ], providers: [ ProjectMetadataPieceImporter, @@ -45,7 +48,7 @@ import { ProjectCostSurfacesPieceImporter } from '@marxan-geoprocessing/import/p ScenarioFeaturesDataPieceImporter, ScenarioFeaturesSpecificationPieceImporter, MarxanExecutionMetadataPieceImporter, - ProjectPuvsprCalculationsPieceImporter, + ProjectFeatureAmountsPerPlanningUnitPieceImporter, ], }) export class PiecesImportersModule {} diff --git a/api/apps/geoprocessing/src/import/pieces-importers/project-puvspr-calculations.piece-importer.ts b/api/apps/geoprocessing/src/import/pieces-importers/project-feature-amounts-per-planning-unit.piece-importer.ts similarity index 79% rename from api/apps/geoprocessing/src/import/pieces-importers/project-puvspr-calculations.piece-importer.ts rename to api/apps/geoprocessing/src/import/pieces-importers/project-feature-amounts-per-planning-unit.piece-importer.ts index 42f8fa3ab6..36909d5be7 100644 --- a/api/apps/geoprocessing/src/import/pieces-importers/project-puvspr-calculations.piece-importer.ts +++ b/api/apps/geoprocessing/src/import/pieces-importers/project-feature-amounts-per-planning-unit.piece-importer.ts @@ -7,9 +7,9 @@ import { ResourceKind } from '@marxan/cloning/domain'; import { FeatureAmountPerPlanningUnit, ProjectFeatureGeoOperation, - ProjectPuvsprCalculationsContent, -} from '@marxan/cloning/infrastructure/clone-piece-data/project-puvspr-calculations'; -import { PuvsprCalculationsEntity } from '@marxan/puvspr-calculations'; + ProjectFeatureAmountsPerPlanningUnitContent, +} from '@marxan/cloning/infrastructure/clone-piece-data/project-feature-amounts-per-planning-unit'; +import { FeatureAmountsPerPlanningUnitEntity } from '@marxan/feature-amounts-per-planning-unit'; import { SpecificationOperation } from '@marxan/specification'; import { readableToBuffer } from '@marxan/utils'; import { Injectable, Logger } from '@nestjs/common'; @@ -28,11 +28,11 @@ type FeatureSelectResult = { @Injectable() @PieceImportProvider() -export class ProjectPuvsprCalculationsPieceImporter +export class ProjectFeatureAmountsPerPlanningUnitPieceImporter implements ImportPieceProcessor { private readonly logger: Logger = new Logger( - ProjectPuvsprCalculationsPieceImporter.name, + ProjectFeatureAmountsPerPlanningUnitPieceImporter.name, ); constructor( @@ -47,7 +47,7 @@ export class ProjectPuvsprCalculationsPieceImporter isSupported(piece: ClonePiece, kind: ResourceKind): boolean { return ( - piece === ClonePiece.ProjectPuvsprCalculations && + piece === ClonePiece.ProjectFeatureAmountsPerPlanningUnit && kind === ResourceKind.Project ); } @@ -61,31 +61,32 @@ export class ProjectPuvsprCalculationsPieceImporter this.logger.error(errorMessage); throw new Error(errorMessage); } - const [puvsprCalculationsLocation] = uris; + const [featureAmountsPerPlanningUnitLocation] = uris; const readableOrError = await this.fileRepository.get( - puvsprCalculationsLocation.uri, + featureAmountsPerPlanningUnitLocation.uri, ); if (isLeft(readableOrError)) { - const errorMessage = `File with piece data for ${piece}/${pieceResourceId} is not available at ${puvsprCalculationsLocation.uri}`; + const errorMessage = `File with piece data for ${piece}/${pieceResourceId} is not available at ${featureAmountsPerPlanningUnitLocation.uri}`; this.logger.error(errorMessage); throw new Error(errorMessage); } const buffer = await readableToBuffer(readableOrError.right); - const stringPuvsprCalculationsOrError = buffer.toString(); + const stringFeatureAmountsPerPlanningUnitOrError = buffer.toString(); const { - puvsprCalculations, + featureAmountsPerPlanningUnit, projectFeaturesGeoOperations, - }: ProjectPuvsprCalculationsContent = JSON.parse( - stringPuvsprCalculationsOrError, + }: ProjectFeatureAmountsPerPlanningUnitContent = JSON.parse( + stringFeatureAmountsPerPlanningUnitOrError, ); - const parsedPuvsprCalculations = await this.parsePuvsprCalculations( - puvsprCalculations, - projectId, - ); + const parsedFeatureAmountsPerPlanningUnit = + await this.parseFeatureAmountsPerPlanningUnit( + featureAmountsPerPlanningUnit, + projectId, + ); const parsedProjectFeaturesGeoOperations = await this.parseProjectFeaturesGeoOperations( @@ -94,14 +95,21 @@ export class ProjectPuvsprCalculationsPieceImporter ); await this.geoEntityManager.transaction(async (em) => { - const puvsprRepo = em.getRepository(PuvsprCalculationsEntity); + const featureAmountsPerPlanningUnitRepo = em.getRepository( + FeatureAmountsPerPlanningUnitEntity, + ); try { - await puvsprRepo.save(parsedPuvsprCalculations, { - chunk: CHUNK_SIZE_FOR_BATCH_GEODB_OPERATIONS, - }); + await featureAmountsPerPlanningUnitRepo.save( + parsedFeatureAmountsPerPlanningUnit, + { + chunk: CHUNK_SIZE_FOR_BATCH_GEODB_OPERATIONS, + }, + ); } catch (e) { this.logger.error(e); - throw new Error('error while saving parsed puvspr calculations'); + throw new Error( + 'error while saving parsed feature amounts per planning units', + ); } await this.apiEntityManager.transaction(async (em) => { @@ -132,11 +140,11 @@ export class ProjectPuvsprCalculationsPieceImporter }; } - private async parsePuvsprCalculations( - puvsprCalculations: FeatureAmountPerPlanningUnit[], + private async parseFeatureAmountsPerPlanningUnit( + featureAmountsPerPlanningUnit: FeatureAmountPerPlanningUnit[], projectId: string, ) { - const customFeaturesNames = puvsprCalculations + const customFeaturesNames = featureAmountsPerPlanningUnit .filter(({ isCustom }) => isCustom) .map(({ featureName }) => featureName); @@ -145,7 +153,7 @@ export class ProjectPuvsprCalculationsPieceImporter projectId, ); - const platformFeaturesNames = puvsprCalculations + const platformFeaturesNames = featureAmountsPerPlanningUnit .filter(({ isCustom }) => !isCustom) .map(({ featureName }) => featureName); @@ -155,18 +163,20 @@ export class ProjectPuvsprCalculationsPieceImporter const projectPusByPuid = await this.getProjectPusByPuid(projectId); - return puvsprCalculations.map(({ isCustom, featureName, amount, puid }) => { - const featureId = isCustom - ? customFeaturesMap[featureName] - : platformFeaturesMap[featureName]; - - return { - amount, - projectPuId: projectPusByPuid[puid], - featureId, - projectId: projectId, - }; - }); + return featureAmountsPerPlanningUnit.map( + ({ isCustom, featureName, amount, puid }) => { + const featureId = isCustom + ? customFeaturesMap[featureName] + : platformFeaturesMap[featureName]; + + return { + amount, + projectPuId: projectPusByPuid[puid], + featureId, + projectId: projectId, + }; + }, + ); } private async getCustomFeaturesByFeatureName( diff --git a/api/apps/geoprocessing/test/integration/cloning/piece-exporters/project-puvspr-calculations.piece-exporter.e2e-spec.ts b/api/apps/geoprocessing/test/integration/cloning/piece-exporters/project-feature-amounts-per-planning-unit.piece-exporter.e2e-spec.ts similarity index 64% rename from api/apps/geoprocessing/test/integration/cloning/piece-exporters/project-puvspr-calculations.piece-exporter.e2e-spec.ts rename to api/apps/geoprocessing/test/integration/cloning/piece-exporters/project-feature-amounts-per-planning-unit.piece-exporter.e2e-spec.ts index 12e969a7b5..6307b0f21f 100644 --- a/api/apps/geoprocessing/test/integration/cloning/piece-exporters/project-puvspr-calculations.piece-exporter.e2e-spec.ts +++ b/api/apps/geoprocessing/test/integration/cloning/piece-exporters/project-feature-amounts-per-planning-unit.piece-exporter.e2e-spec.ts @@ -16,12 +16,12 @@ import { readSavedFile, } from '../fixtures'; import { GeoCloningFilesRepositoryModule } from '@marxan-geoprocessing/modules/cloning-files-repository'; -import { ProjectPuvsprCalculationsPieceExporter } from '@marxan-geoprocessing/export/pieces-exporters/project-puvspr-calculations.piece-exporter'; -import { ProjectPuvsprCalculationsContent } from '@marxan/cloning/infrastructure/clone-piece-data/project-puvspr-calculations'; +import { ProjectFeatureAmountsPerPlanningUnitPieceExporter } from '@marxan-geoprocessing/export/pieces-exporters/project-feature-amounts-per-planning-unit.piece-exporter'; +import { ProjectFeatureAmountsPerPlanningUnitContent } from '@marxan/cloning/infrastructure/clone-piece-data/project-feature-amounts-per-planning-unit'; import { - PuvsprCalculationsModule, - PuvsprCalculationsRepository, -} from '@marxan/puvspr-calculations'; + FeatureAmountsPerPlanningUnitModule, + FeatureAmountsPerPlanningUnitRepository, +} from '@marxan/feature-amounts-per-planning-unit'; import { isDefined } from '@marxan/utils'; import { SingleConfigFeatureValueStripped, @@ -42,7 +42,7 @@ type FeatureData = { let fixtures: FixtureType; -describe(ProjectPuvsprCalculationsPieceExporter, () => { +describe(ProjectFeatureAmountsPerPlanningUnitPieceExporter, () => { beforeEach(async () => { fixtures = await getFixtures(); }, 10_000); @@ -52,42 +52,52 @@ describe(ProjectPuvsprCalculationsPieceExporter, () => { }); it("saves an empty file when project doesn't have neither derived features and puvspr calculations", async () => { - const input = fixtures.GivenAProjectPuvsprCalculationsExportJob(); + const input = + fixtures.GivenAProjectFeatureAmountsPerPlanningUnitExportJob(); await fixtures.GivenProjectExist(); await fixtures.GivenACustomAndAPlatformFeatureForProject(); fixtures.GivenNoDerivedFeaturesForProject(); - fixtures.GivenProjectDoesNotHavePuvsprCalculations(); + fixtures.GivenProjectDoesNotHaveFeatureAmountsPerPlanningUnit(); await fixtures .WhenPieceExporterIsInvoked(input) - .ThenAnEmptyProjectPuvsprCalculationsFileIsSaved(); + .ThenAnEmptyProjectFeatureAmountsPerPlanningUnitFileIsSaved(); }); it('saves succesfully puvspr calculations for a custom feature ', async () => { - const input = fixtures.GivenAProjectPuvsprCalculationsExportJob(); + const input = + fixtures.GivenAProjectFeatureAmountsPerPlanningUnitExportJob(); await fixtures.GivenProjectExist(); const { customFeature } = await fixtures.GivenACustomAndAPlatformFeatureForProject(); - await fixtures.GivenProjectHasPuvsprCalculations(customFeature.id); + await fixtures.GivenProjectHasFeatureAmountsPerPlanningUnit( + customFeature.id, + ); await fixtures .WhenPieceExporterIsInvoked(input) - .ThenPuvsprCalculationsFileHasPuvsprCalculationsForFeature(customFeature); + .ThenFeatureAmountsPerPlanningUnitFileHasFeatureAmountsPerPlanningUnitForFeature( + customFeature, + ); }); it('saves succesfully puvspr calculations for a platform feature ', async () => { - const input = fixtures.GivenAProjectPuvsprCalculationsExportJob(); + const input = + fixtures.GivenAProjectFeatureAmountsPerPlanningUnitExportJob(); await fixtures.GivenProjectExist(); const { platformFeature } = await fixtures.GivenACustomAndAPlatformFeatureForProject(); - await fixtures.GivenProjectHasPuvsprCalculations(platformFeature.id); + await fixtures.GivenProjectHasFeatureAmountsPerPlanningUnit( + platformFeature.id, + ); await fixtures .WhenPieceExporterIsInvoked(input) - .ThenPuvsprCalculationsFileHasPuvsprCalculationsForFeature( + .ThenFeatureAmountsPerPlanningUnitFileHasFeatureAmountsPerPlanningUnitForFeature( platformFeature, ); }); it('saves succesfully a split derived feature from a platform feature', async () => { - const input = fixtures.GivenAProjectPuvsprCalculationsExportJob(); + const input = + fixtures.GivenAProjectFeatureAmountsPerPlanningUnitExportJob(); await fixtures.GivenProjectExist(); const { platformFeature } = await fixtures.GivenACustomAndAPlatformFeatureForProject(); @@ -96,14 +106,15 @@ describe(ProjectPuvsprCalculationsPieceExporter, () => { ); await fixtures .WhenPieceExporterIsInvoked(input) - .ThenPuvsprCalculationsFileHasASplitDerivedFeature( + .ThenFeatureAmountsPerPlanningUnitFileHasASplitDerivedFeature( derivedFeature, platformFeature, ); }); it('saves succesfully a split derived features from a custom feature', async () => { - const input = fixtures.GivenAProjectPuvsprCalculationsExportJob(); + const input = + fixtures.GivenAProjectFeatureAmountsPerPlanningUnitExportJob(); await fixtures.GivenProjectExist(); const { customFeature } = await fixtures.GivenACustomAndAPlatformFeatureForProject(); @@ -112,7 +123,7 @@ describe(ProjectPuvsprCalculationsPieceExporter, () => { ); await fixtures .WhenPieceExporterIsInvoked(input) - .ThenPuvsprCalculationsFileHasASplitDerivedFeature( + .ThenFeatureAmountsPerPlanningUnitFileHasASplitDerivedFeature( derivedFeature, customFeature, ); @@ -134,9 +145,11 @@ const getFixtures = async () => { }), TypeOrmModule.forFeature([ProjectsPuEntity]), GeoCloningFilesRepositoryModule, - PuvsprCalculationsModule.for(geoprocessingConnections.default.name!), + FeatureAmountsPerPlanningUnitModule.for( + geoprocessingConnections.default.name!, + ), ], - providers: [ProjectPuvsprCalculationsPieceExporter], + providers: [ProjectFeatureAmountsPerPlanningUnitPieceExporter], }).compile(); await sandbox.init(); @@ -144,7 +157,7 @@ const getFixtures = async () => { const projectId = v4(); const organizationId = v4(); - const sut = sandbox.get(ProjectPuvsprCalculationsPieceExporter); + const sut = sandbox.get(ProjectFeatureAmountsPerPlanningUnitPieceExporter); const apiEntityManager: EntityManager = sandbox.get( getEntityManagerToken(geoprocessingConnections.apiDB), ); @@ -152,7 +165,9 @@ const getFixtures = async () => { getEntityManagerToken(geoprocessingConnections.default), ); const fileRepository = sandbox.get(CloningFilesRepository); - const puvsprCalculationsRepo = sandbox.get(PuvsprCalculationsRepository); + const featureAmountsPerPlanningUnitRepo = sandbox.get( + FeatureAmountsPerPlanningUnitRepository, + ); const amountOfCustomFeatures = 1; const amountOfPlatformFeatures = 1; @@ -179,18 +194,18 @@ const getFixtures = async () => { await DeleteProjectPus(geoEntityManager, projectId); }, - GivenAProjectPuvsprCalculationsExportJob: (): ExportJobInput => { + GivenAProjectFeatureAmountsPerPlanningUnitExportJob: (): ExportJobInput => { return { allPieces: [ { resourceId: projectId, piece: ClonePiece.ProjectMetadata }, { resourceId: projectId, - piece: ClonePiece.ProjectPuvsprCalculations, + piece: ClonePiece.ProjectFeatureAmountsPerPlanningUnit, }, ], componentId: v4(), exportId: v4(), - piece: ClonePiece.ProjectPuvsprCalculations, + piece: ClonePiece.ProjectFeatureAmountsPerPlanningUnit, resourceId: projectId, resourceKind: ResourceKind.Project, }; @@ -236,62 +251,68 @@ const getFixtures = async () => { return derivedFeature; }, GivenNoDerivedFeaturesForProject: () => {}, - GivenProjectHasPuvsprCalculations: async (featureId: string) => { + GivenProjectHasFeatureAmountsPerPlanningUnit: async (featureId: string) => { projectPus = await GivenProjectPus( geoEntityManager, projectId, amountOfPuvsrCalculationsPerFeature, ); - const puvsprCalculations = Array(amountOfPuvsrCalculationsPerFeature) + const featureAmountsPerPlanningUnit = Array( + amountOfPuvsrCalculationsPerFeature, + ) .fill(0) .map((_, index) => ({ amount: expectedAmountPerPu, featureId, projectPuId: projectPus[index].id, })); - return puvsprCalculationsRepo.saveAmountPerPlanningUnitAndFeature( + return featureAmountsPerPlanningUnitRepo.saveAmountPerPlanningUnitAndFeature( projectId, - puvsprCalculations, + featureAmountsPerPlanningUnit, ); }, - GivenProjectDoesNotHavePuvsprCalculations: () => {}, + GivenProjectDoesNotHaveFeatureAmountsPerPlanningUnit: () => {}, WhenPieceExporterIsInvoked: (input: ExportJobInput) => { return { - ThenAnEmptyProjectPuvsprCalculationsFileIsSaved: async () => { - const result = await sut.run(input); - const file = await fileRepository.get(result.uris[0].uri); - expect((file as Right).right).toBeDefined(); - if (isLeft(file)) throw new Error(); - const savedStrem = file.right; - const content = - await readSavedFile(savedStrem); - expect(content.projectFeaturesGeoOperations).toEqual([]); - expect(content.puvsprCalculations).toEqual([]); - }, - ThenPuvsprCalculationsFileHasPuvsprCalculationsForFeature: async ( - feature: FeatureData, - ) => { - const result = await sut.run(input); - const file = await fileRepository.get(result.uris[0].uri); - expect((file as Right).right).toBeDefined(); - if (isLeft(file)) throw new Error(); - const savedStrem = file.right; - const content = - await readSavedFile(savedStrem); - expect( - content.puvsprCalculations.every( - ({ amount, featureName, isCustom, puid }) => - amount === expectedAmountPerPu && - featureName === feature.feature_class_name && - isCustom === isDefined(feature.project_id) && - puid <= amountOfPuvsrCalculationsPerFeature, - ), - ).toEqual(true); - expect(content.puvsprCalculations).toHaveLength( - amountOfPuvsrCalculationsPerFeature, - ); - }, - ThenPuvsprCalculationsFileHasASplitDerivedFeature: async ( + ThenAnEmptyProjectFeatureAmountsPerPlanningUnitFileIsSaved: + async () => { + const result = await sut.run(input); + const file = await fileRepository.get(result.uris[0].uri); + expect((file as Right).right).toBeDefined(); + if (isLeft(file)) throw new Error(); + const savedStrem = file.right; + const content = + await readSavedFile( + savedStrem, + ); + expect(content.projectFeaturesGeoOperations).toEqual([]); + expect(content.featureAmountsPerPlanningUnit).toEqual([]); + }, + ThenFeatureAmountsPerPlanningUnitFileHasFeatureAmountsPerPlanningUnitForFeature: + async (feature: FeatureData) => { + const result = await sut.run(input); + const file = await fileRepository.get(result.uris[0].uri); + expect((file as Right).right).toBeDefined(); + if (isLeft(file)) throw new Error(); + const savedStrem = file.right; + const content = + await readSavedFile( + savedStrem, + ); + expect( + content.featureAmountsPerPlanningUnit.every( + ({ amount, featureName, isCustom, puid }) => + amount === expectedAmountPerPu && + featureName === feature.feature_class_name && + isCustom === isDefined(feature.project_id) && + puid <= amountOfPuvsrCalculationsPerFeature, + ), + ).toEqual(true); + expect(content.featureAmountsPerPlanningUnit).toHaveLength( + amountOfPuvsrCalculationsPerFeature, + ); + }, + ThenFeatureAmountsPerPlanningUnitFileHasASplitDerivedFeature: async ( derivedFeature: FeatureData, baseFeature: FeatureData, ) => { @@ -301,7 +322,9 @@ const getFixtures = async () => { if (isLeft(file)) throw new Error(); const savedStrem = file.right; const content = - await readSavedFile(savedStrem); + await readSavedFile( + savedStrem, + ); expect(content.projectFeaturesGeoOperations).toHaveLength(1); const derivedFeatureContent = content.projectFeaturesGeoOperations[0]; const derivedFeatureOperation = diff --git a/api/apps/geoprocessing/test/integration/cloning/piece-importers/project-puvspr-calculations.piece-importer.e2e-spec.ts b/api/apps/geoprocessing/test/integration/cloning/piece-importers/project-feature-amounts-per-planning-unit.piece-importer.e2e-spec.ts similarity index 78% rename from api/apps/geoprocessing/test/integration/cloning/piece-importers/project-puvspr-calculations.piece-importer.e2e-spec.ts rename to api/apps/geoprocessing/test/integration/cloning/piece-importers/project-feature-amounts-per-planning-unit.piece-importer.e2e-spec.ts index 56e4a638bb..6518ae8b43 100644 --- a/api/apps/geoprocessing/test/integration/cloning/piece-importers/project-puvspr-calculations.piece-importer.e2e-spec.ts +++ b/api/apps/geoprocessing/test/integration/cloning/piece-importers/project-feature-amounts-per-planning-unit.piece-importer.e2e-spec.ts @@ -27,15 +27,15 @@ import { GivenProjectPus, } from '../fixtures'; import { GeoCloningFilesRepositoryModule } from '@marxan-geoprocessing/modules/cloning-files-repository'; -import { ProjectPuvsprCalculationsPieceImporter } from '@marxan-geoprocessing/import/pieces-importers/project-puvspr-calculations.piece-importer'; -import { ProjectPuvsprCalculationsContent } from '@marxan/cloning/infrastructure/clone-piece-data/project-puvspr-calculations'; +import { ProjectFeatureAmountsPerPlanningUnitPieceImporter } from '@marxan-geoprocessing/import/pieces-importers/project-feature-amounts-per-planning-unit.piece-importer'; +import { ProjectFeatureAmountsPerPlanningUnitContent } from '@marxan/cloning/infrastructure/clone-piece-data/project-feature-amounts-per-planning-unit'; import { SpecificationOperation } from '@marxan/specification'; import { SingleConfigFeatureValueStripped } from '@marxan/features-hash'; import { - PuvsprCalculationsEntity, - PuvsprCalculationsModule, - PuvsprCalculationsRepository, -} from '@marxan/puvspr-calculations'; + FeatureAmountsPerPlanningUnitEntity, + FeatureAmountsPerPlanningUnitModule, + FeatureAmountsPerPlanningUnitRepository, +} from '@marxan/feature-amounts-per-planning-unit'; import { ProjectsPuEntity } from '@marxan-jobs/planning-unit-geometry'; import { FakeLogger } from '@marxan-geoprocessing/utils/__mocks__/fake-logger'; @@ -59,7 +59,7 @@ describe(ProjectCustomFeaturesPieceImporter, () => { it('fails when the file cannot be retrieved from file repo', async () => { const archiveLocation = - fixtures.GivenNoProjectPuvsprCalculationsFileIsAvailable(); + fixtures.GivenNoProjectFeatureAmountsPerPlanningUnitFileIsAvailable(); const input = fixtures.GivenJobInput(archiveLocation); await fixtures .WhenPieceImporterIsInvoked(input) @@ -69,11 +69,11 @@ describe(ProjectCustomFeaturesPieceImporter, () => { it('imports project puvspr calculations', async () => { await fixtures.GivenProject(); const archiveLocation = - await fixtures.GivenValidProjectPuvsprCalculationsFile(); + await fixtures.GivenValidProjectFeatureAmountsPerPlanningUnitFile(); const input = fixtures.GivenJobInput(archiveLocation); await fixtures .WhenPieceImporterIsInvoked(input) - .ThenPuvsprCalculationsAreImportedAndDerivedFeaturesAreUpdated(); + .ThenFeatureAmountsPerPlanningUnitAreImportedAndDerivedFeaturesAreUpdated(); }); }); @@ -91,13 +91,15 @@ const getFixtures = async () => { logging: false, }), TypeOrmModule.forFeature( - [PuvsprCalculationsEntity, ProjectsPuEntity], + [FeatureAmountsPerPlanningUnitEntity, ProjectsPuEntity], geoprocessingConnections.default, ), GeoCloningFilesRepositoryModule, - PuvsprCalculationsModule.for(geoprocessingConnections.default.name!), + FeatureAmountsPerPlanningUnitModule.for( + geoprocessingConnections.default.name!, + ), ], - providers: [ProjectPuvsprCalculationsPieceImporter], + providers: [ProjectFeatureAmountsPerPlanningUnitPieceImporter], }).compile(); await sandbox.init(); @@ -112,14 +114,16 @@ const getFixtures = async () => { getEntityManagerToken(geoprocessingConnections.apiDB.name), ); - const sut = sandbox.get(ProjectPuvsprCalculationsPieceImporter); + const sut = sandbox.get(ProjectFeatureAmountsPerPlanningUnitPieceImporter); const fileRepository = sandbox.get(CloningFilesRepository); - const puvsprCalculationsRepo = sandbox.get(PuvsprCalculationsRepository); + const featureAmountsPerPlanningUnitRepo = sandbox.get( + FeatureAmountsPerPlanningUnitRepository, + ); const projectPusRepo: Repository = sandbox.get( getRepositoryToken(ProjectsPuEntity), ); - const amountOfPuvsprCalculations = 5; + const amountOfFeatureAmountsPerPlanningUnit = 5; let featureIds: string[] = []; const getFeaturesImported = async () => { const projectFeatures: { @@ -198,10 +202,10 @@ const getFixtures = async () => { ownerId: userId, }; }, - GivenNoProjectPuvsprCalculationsFileIsAvailable: () => { + GivenNoProjectFeatureAmountsPerPlanningUnitFileIsAvailable: () => { return new ArchiveLocation('not found'); }, - GivenValidProjectPuvsprCalculationsFile: async () => { + GivenValidProjectFeatureAmountsPerPlanningUnitFile: async () => { const { platformFeatures, customFeatures } = await GivenFeatures( apiEntityManager, 1, @@ -211,12 +215,12 @@ const getFixtures = async () => { const projectPus = await GivenProjectPus( geoEntityManager, projectId, - amountOfPuvsprCalculations, + amountOfFeatureAmountsPerPlanningUnit, ); const basePlatformFeature = platformFeatures[0]; featureIds = [basePlatformFeature.id]; const importedSplitDerivedFeature = customFeatures[0]; - const validProjectPuvsprCalculationsFile: ProjectPuvsprCalculationsContent = + const validProjectFeatureAmountsPerPlanningUnitFile: ProjectFeatureAmountsPerPlanningUnitContent = { projectFeaturesGeoOperations: [ { @@ -229,7 +233,9 @@ const getFixtures = async () => { }, }, ], - puvsprCalculations: Array(amountOfPuvsprCalculations) + featureAmountsPerPlanningUnit: Array( + amountOfFeatureAmountsPerPlanningUnit, + ) .fill(0) .map((_, index) => ({ amount: 200, @@ -241,12 +247,14 @@ const getFixtures = async () => { const exportId = v4(); const relativePath = ClonePieceRelativePathResolver.resolveFor( - ClonePiece.ProjectPuvsprCalculations, + ClonePiece.ProjectFeatureAmountsPerPlanningUnit, ); const uriOrError = await fileRepository.saveCloningFile( exportId, - Readable.from(JSON.stringify(validProjectPuvsprCalculationsFile)), + Readable.from( + JSON.stringify(validProjectFeatureAmountsPerPlanningUnitFile), + ), relativePath, ); @@ -263,7 +271,7 @@ const getFixtures = async () => { /File with piece data for/gi, ); }, - ThenPuvsprCalculationsAreImportedAndDerivedFeaturesAreUpdated: + ThenFeatureAmountsPerPlanningUnitAreImportedAndDerivedFeaturesAreUpdated: async () => { const projectFeaturesImported = 1; const featuresAlreadyImported = await getFeaturesImported(); @@ -275,15 +283,17 @@ const getFixtures = async () => { expect(featuresAlreadyImported).toHaveLength( projectFeaturesImported, ); - const projectPuvsprCalculations = - await puvsprCalculationsRepo.getAmountPerPlanningUnitAndFeatureInProject( + const projectFeatureAmountsPerPlanningUnit = + await featureAmountsPerPlanningUnitRepo.getAmountPerPlanningUnitAndFeatureInProject( projectId, ); - expect(projectPuvsprCalculations).toEqual([]); + expect(projectFeatureAmountsPerPlanningUnit).toEqual([]); const projectPus = await projectPusRepo.find({ where: { projectId }, }); - expect(projectPus).toHaveLength(amountOfPuvsprCalculations); + expect(projectPus).toHaveLength( + amountOfFeatureAmountsPerPlanningUnit, + ); await sut.run(input); @@ -297,15 +307,15 @@ const getFixtures = async () => { expect(baseFeature).toBeDefined(); expect(baseFeature!.geoOperation).toEqual(null); - const puvsprCalculationsAfterImport = - await puvsprCalculationsRepo.getAmountPerPlanningUnitAndFeatureInProject( + const featureAmountsPerPlanningUnitAfterImport = + await featureAmountsPerPlanningUnitRepo.getAmountPerPlanningUnitAndFeatureInProject( projectId, ); - expect(puvsprCalculationsAfterImport).toHaveLength( - amountOfPuvsprCalculations, + expect(featureAmountsPerPlanningUnitAfterImport).toHaveLength( + amountOfFeatureAmountsPerPlanningUnit, ); expect( - puvsprCalculationsAfterImport.every( + featureAmountsPerPlanningUnitAfterImport.every( ({ featureId }) => baseFeatureId === featureId, ), ); diff --git a/api/apps/geoprocessing/test/jest-e2e.json b/api/apps/geoprocessing/test/jest-e2e.json index 674e9522df..177e54adcb 100644 --- a/api/apps/geoprocessing/test/jest-e2e.json +++ b/api/apps/geoprocessing/test/jest-e2e.json @@ -93,8 +93,8 @@ "@marxan/planning-units-grid": "/../../libs/planning-units-grid/src", "@marxan/protected-areas/(.*)": "/../../libs/protected-areas/src/$1", "@marxan/protected-areas": "/../../libs/protected-areas/src", - "@marxan/puvspr-calculations/(.*)": "/../../libs/puvspr-calculations/src/$1", - "@marxan/puvspr-calculations": "/../../libs/puvspr-calculations/src", + "@marxan/feature-amounts-per-planning-unit/(.*)": "/../../libs/feature-amounts-per-planning-unit/src/$1", + "@marxan/feature-amounts-per-planning-unit": "/../../libs/feature-amounts-per-planning-unit/src", "@marxan/specification/(.*)": "/../../libs/specification/src/$1", "@marxan/specification": "/../../libs/specification/src", "@marxan/tiles/(.*)": "/../../libs/tiles/src/$1", diff --git a/api/libs/cloning/src/domain/clone-piece.ts b/api/libs/cloning/src/domain/clone-piece.ts index 422282eed2..e9fc27a78a 100644 --- a/api/libs/cloning/src/domain/clone-piece.ts +++ b/api/libs/cloning/src/domain/clone-piece.ts @@ -4,7 +4,7 @@ export enum ClonePiece { ProjectCostSurfaces = 'project-cost-surfaces', ProjectCustomProtectedAreas = 'project-custom-protected-areas', ProjectCustomFeatures = 'project-custom-features', - ProjectPuvsprCalculations = 'project-puvspr-calculations', + ProjectFeatureAmountsPerPlanningUnit = 'project-feature-amounts-per-planning-unit', PlanningAreaGAdm = 'planning-area-gadm', PlanningAreaCustom = 'planning-area-custom', PlanningUnitsGrid = 'planning-units-grid', diff --git a/api/libs/cloning/src/infrastructure/clone-piece-data/index.ts b/api/libs/cloning/src/infrastructure/clone-piece-data/index.ts index f7092e65b2..7c79ab05b2 100644 --- a/api/libs/cloning/src/infrastructure/clone-piece-data/index.ts +++ b/api/libs/cloning/src/infrastructure/clone-piece-data/index.ts @@ -12,7 +12,7 @@ import { planningUnitsGridGeoJSONRelativePath } from './planning-units-grid-geoj import { projectCustomFeaturesRelativePath } from './project-custom-features'; import { projectCustomProtectedAreasRelativePath } from './project-custom-protected-areas'; import { projectMetadataRelativePath } from './project-metadata'; -import { projectPuvsprCalculationsRelativePath } from './project-puvspr-calculations'; +import { projectFeatureAmountsPerPlanningUnitRelativePath } from './project-feature-amounts-per-planning-unit'; import { scenarioFeaturesDataRelativePath } from './scenario-features-data'; import { featuresSpecificationRelativePath } from './scenario-features-specification'; import { scenarioInputFolderRelativePath } from './scenario-input-folder'; @@ -69,7 +69,7 @@ export const clonePieceImportOrder: Record = { [ClonePiece.ScenarioProtectedAreas]: 4, [ClonePiece.ScenarioPlanningUnitsData]: 4, // - [ClonePiece.ProjectPuvsprCalculations]: 5, + [ClonePiece.ProjectFeatureAmountsPerPlanningUnit]: 5, [ClonePiece.ScenarioFeaturesData]: 5, // [ClonePiece.ScenarioRunResults]: 6, @@ -99,8 +99,8 @@ export class ClonePieceRelativePathResolver { projectCustomProtectedAreasRelativePath, [ClonePiece.ProjectCostSurfaces]: () => projectCostSurfacesRelativePath, [ClonePiece.ProjectCustomFeatures]: () => projectCustomFeaturesRelativePath, - [ClonePiece.ProjectPuvsprCalculations]: () => - projectPuvsprCalculationsRelativePath, + [ClonePiece.ProjectFeatureAmountsPerPlanningUnit]: () => + projectFeatureAmountsPerPlanningUnitRelativePath, [ClonePiece.FeaturesSpecification]: ClonePieceRelativePathResolver.scenarioPieceRelativePathResolver( featuresSpecificationRelativePath, diff --git a/api/libs/cloning/src/infrastructure/clone-piece-data/project-puvspr-calculations.ts b/api/libs/cloning/src/infrastructure/clone-piece-data/project-feature-amounts-per-planning-unit.ts similarity index 68% rename from api/libs/cloning/src/infrastructure/clone-piece-data/project-puvspr-calculations.ts rename to api/libs/cloning/src/infrastructure/clone-piece-data/project-feature-amounts-per-planning-unit.ts index 0cc8b021a4..c917dff4e9 100644 --- a/api/libs/cloning/src/infrastructure/clone-piece-data/project-puvspr-calculations.ts +++ b/api/libs/cloning/src/infrastructure/clone-piece-data/project-feature-amounts-per-planning-unit.ts @@ -17,10 +17,10 @@ export type ProjectFeatureGeoOperation = { geoOperation: GeoOperation; }; -export type ProjectPuvsprCalculationsContent = { - puvsprCalculations: FeatureAmountPerPlanningUnit[]; +export type ProjectFeatureAmountsPerPlanningUnitContent = { + featureAmountsPerPlanningUnit: FeatureAmountPerPlanningUnit[]; projectFeaturesGeoOperations: ProjectFeatureGeoOperation[]; }; -export const projectPuvsprCalculationsRelativePath = - 'project-puvspr-calculations.json'; +export const projectFeatureAmountsPerPlanningUnitRelativePath = + 'project-feature-amounts-per-planning-unit.json'; diff --git a/api/libs/puvspr-calculations/src/puvspr-calculations.geo.entity.ts b/api/libs/feature-amounts-per-planning-unit/src/feature-amounts-per-planning-unit.geo.entity.ts similarity index 93% rename from api/libs/puvspr-calculations/src/puvspr-calculations.geo.entity.ts rename to api/libs/feature-amounts-per-planning-unit/src/feature-amounts-per-planning-unit.geo.entity.ts index 3e2419c740..a329481d8c 100644 --- a/api/libs/puvspr-calculations/src/puvspr-calculations.geo.entity.ts +++ b/api/libs/feature-amounts-per-planning-unit/src/feature-amounts-per-planning-unit.geo.entity.ts @@ -8,7 +8,7 @@ import { } from 'typeorm'; @Entity('feature_amounts_per_planning_unit') -export class PuvsprCalculationsEntity { +export class FeatureAmountsPerPlanningUnitEntity { @PrimaryGeneratedColumn('uuid') id!: string; diff --git a/api/libs/feature-amounts-per-planning-unit/src/feature-amounts-per-planning-unit.module.ts b/api/libs/feature-amounts-per-planning-unit/src/feature-amounts-per-planning-unit.module.ts new file mode 100644 index 0000000000..2ba5eef40e --- /dev/null +++ b/api/libs/feature-amounts-per-planning-unit/src/feature-amounts-per-planning-unit.module.ts @@ -0,0 +1,39 @@ +import { DynamicModule, Module } from '@nestjs/common'; +import { getEntityManagerToken, TypeOrmModule } from '@nestjs/typeorm'; +import { TypeormFeatureAmountsPerPlanningUnitRepository } from './repository/typeorm-feature-amounts-per-planning-unit.repository'; +import { FeatureAmountsPerPlanningUnitEntity } from './feature-amounts-per-planning-unit.geo.entity'; +import { + geoEntityManagerToken, + FeatureAmountsPerPlanningUnitsService, +} from './feature-amounts-per-planning-units.service'; +import { FeatureAmountsPerPlanningUnitRepository } from './repository/feature-amounts-per-planning-unit.repository'; + +@Module({}) +export class FeatureAmountsPerPlanningUnitModule { + static for(geoConnectionName: string): DynamicModule { + return { + module: FeatureAmountsPerPlanningUnitModule, + imports: [ + TypeOrmModule.forFeature( + [FeatureAmountsPerPlanningUnitEntity], + geoConnectionName, + ), + ], + providers: [ + { + provide: geoEntityManagerToken, + useExisting: getEntityManagerToken(geoConnectionName), + }, + FeatureAmountsPerPlanningUnitsService, + { + provide: FeatureAmountsPerPlanningUnitRepository, + useClass: TypeormFeatureAmountsPerPlanningUnitRepository, + }, + ], + exports: [ + FeatureAmountsPerPlanningUnitsService, + FeatureAmountsPerPlanningUnitRepository, + ], + }; + } +} diff --git a/api/libs/puvspr-calculations/src/puvspr-calculations.service.ts b/api/libs/feature-amounts-per-planning-unit/src/feature-amounts-per-planning-units.service.ts similarity index 97% rename from api/libs/puvspr-calculations/src/puvspr-calculations.service.ts rename to api/libs/feature-amounts-per-planning-unit/src/feature-amounts-per-planning-units.service.ts index f8ce643033..1d6c436828 100644 --- a/api/libs/puvspr-calculations/src/puvspr-calculations.service.ts +++ b/api/libs/feature-amounts-per-planning-unit/src/feature-amounts-per-planning-units.service.ts @@ -1,7 +1,7 @@ import { ScenarioFeaturesData } from '@marxan/features'; import { Inject, Injectable } from '@nestjs/common'; import { EntityManager } from 'typeorm'; -import { FeatureAmountPerProjectPlanningUnit } from './repository/puvspr-calculations.repository'; +import { FeatureAmountPerProjectPlanningUnit } from './repository/feature-amounts-per-planning-unit.repository'; export const geoEntityManagerToken = Symbol('geo entity manager token'); @@ -11,7 +11,7 @@ export type ComputeFeatureAmountPerPlanningUnit = }; @Injectable() -export class PuvsprCalculationsService { +export class FeatureAmountsPerPlanningUnitService { constructor( @Inject(geoEntityManagerToken) private readonly geoEntityManager: EntityManager, diff --git a/api/libs/feature-amounts-per-planning-unit/src/index.ts b/api/libs/feature-amounts-per-planning-unit/src/index.ts new file mode 100644 index 0000000000..531924748d --- /dev/null +++ b/api/libs/feature-amounts-per-planning-unit/src/index.ts @@ -0,0 +1,9 @@ +export { TypeormFeatureAmountsPerPlanningUnitRepository } from './repository/typeorm-feature-amounts-per-planning-unit.repository'; +export { MemoryFeatureAmountsPerPlanningUnitRepository } from './repository/memory-feature-amounts-per-planning-unit.repository'; +export { + FeatureAmountsPerPlanningUnitRepository, + FeatureAmountPerProjectPlanningUnit, +} from './repository/feature-amounts-per-planning-unit.repository'; +export { FeatureAmountsPerPlanningUnitEntity } from './feature-amounts-per-planning-unit.geo.entity'; +export { FeatureAmountsPerPlanningUnitService } from './feature-amounts-per-planning-units.service'; +export { FeatureAmountsPerPlanningUnitModule } from './feature-amounts-per-planning-unit.module'; diff --git a/api/libs/puvspr-calculations/src/repository/puvspr-calculations.repository.ts b/api/libs/feature-amounts-per-planning-unit/src/repository/feature-amounts-per-planning-unit.repository.ts similarity index 91% rename from api/libs/puvspr-calculations/src/repository/puvspr-calculations.repository.ts rename to api/libs/feature-amounts-per-planning-unit/src/repository/feature-amounts-per-planning-unit.repository.ts index 860748e9e9..239e3ca9a3 100644 --- a/api/libs/puvspr-calculations/src/repository/puvspr-calculations.repository.ts +++ b/api/libs/feature-amounts-per-planning-unit/src/repository/feature-amounts-per-planning-unit.repository.ts @@ -4,7 +4,7 @@ export type FeatureAmountPerProjectPlanningUnit = { projectPuId: string; }; -export abstract class PuvsprCalculationsRepository { +export abstract class FeatureAmountsPerPlanningUnitRepository { abstract areAmountPerPlanningUnitAndFeatureSaved( projectId: string, featureId: string, diff --git a/api/libs/puvspr-calculations/src/repository/memory-puvspr-calculations.repository.ts b/api/libs/feature-amounts-per-planning-unit/src/repository/memory-feature-amounts-per-planning-unit.repository.ts similarity index 85% rename from api/libs/puvspr-calculations/src/repository/memory-puvspr-calculations.repository.ts rename to api/libs/feature-amounts-per-planning-unit/src/repository/memory-feature-amounts-per-planning-unit.repository.ts index 817e366549..a5a30f6faa 100644 --- a/api/libs/puvspr-calculations/src/repository/memory-puvspr-calculations.repository.ts +++ b/api/libs/feature-amounts-per-planning-unit/src/repository/memory-feature-amounts-per-planning-unit.repository.ts @@ -1,12 +1,12 @@ import { Injectable } from '@nestjs/common'; import { FeatureAmountPerProjectPlanningUnit, - PuvsprCalculationsRepository, -} from './puvspr-calculations.repository'; + FeatureAmountsPerPlanningUnitRepository, +} from './feature-amounts-per-planning-unit.repository'; @Injectable() -export class MemoryPuvsprCalculationsRepository - implements PuvsprCalculationsRepository +export class MemoryFeatureAmountsPerPlanningUnitRepository + implements FeatureAmountsPerPlanningUnitRepository { public memory: Record = {}; async areAmountPerPlanningUnitAndFeatureSaved( diff --git a/api/libs/puvspr-calculations/src/repository/typeorm-puvspr-calculations.repository.ts b/api/libs/feature-amounts-per-planning-unit/src/repository/typeorm-feature-amounts-per-planning-unit.repository.ts similarity index 73% rename from api/libs/puvspr-calculations/src/repository/typeorm-puvspr-calculations.repository.ts rename to api/libs/feature-amounts-per-planning-unit/src/repository/typeorm-feature-amounts-per-planning-unit.repository.ts index 283133163d..5fe71e9284 100644 --- a/api/libs/puvspr-calculations/src/repository/typeorm-puvspr-calculations.repository.ts +++ b/api/libs/feature-amounts-per-planning-unit/src/repository/typeorm-feature-amounts-per-planning-unit.repository.ts @@ -1,15 +1,15 @@ import { Inject, Injectable } from '@nestjs/common'; import { EntityManager } from 'typeorm'; -import { PuvsprCalculationsEntity } from '../puvspr-calculations.geo.entity'; -import { geoEntityManagerToken } from '../puvspr-calculations.service'; +import { FeatureAmountsPerPlanningUnitEntity } from '../feature-amounts-per-planning-unit.geo.entity'; +import { geoEntityManagerToken } from '../feature-amounts-per-planning-units.service'; import { FeatureAmountPerProjectPlanningUnit, - PuvsprCalculationsRepository, -} from './puvspr-calculations.repository'; + FeatureAmountsPerPlanningUnitRepository, +} from './feature-amounts-per-planning-unit.repository'; @Injectable() -export class TypeOrmPuvsprCalculationsRepository - implements PuvsprCalculationsRepository +export class TypeormFeatureAmountsPerPlanningUnitRepository + implements FeatureAmountsPerPlanningUnitRepository { constructor( @Inject(geoEntityManagerToken) @@ -23,7 +23,7 @@ export class TypeOrmPuvsprCalculationsRepository .select('amount') .addSelect('project_pu_id', 'projectPuId') .addSelect('feature_id', 'featureId') - .from(PuvsprCalculationsEntity, 'puvspr') + .from(FeatureAmountsPerPlanningUnitEntity, 'fappu') .where('project_id = :projectId', { projectId }) .execute(); } @@ -37,7 +37,7 @@ export class TypeOrmPuvsprCalculationsRepository .select('amount') .addSelect('project_pu_id', 'projectPuId') .addSelect('feature_id', 'featureId') - .from(PuvsprCalculationsEntity, 'puvspr') + .from(FeatureAmountsPerPlanningUnitEntity, 'fappu') .where('project_id = :projectId', { projectId }) .andWhere('feature_id IN (:...featureIds)', { featureIds }) .execute(); @@ -47,7 +47,9 @@ export class TypeOrmPuvsprCalculationsRepository projectId: string, results: FeatureAmountPerProjectPlanningUnit[], ) { - const repo = this.geoEntityManager.getRepository(PuvsprCalculationsEntity); + const repo = this.geoEntityManager.getRepository( + FeatureAmountsPerPlanningUnitEntity, + ); await repo.save( results.map(({ amount, projectPuId, featureId }) => ({ projectId, diff --git a/api/libs/puvspr-calculations/tsconfig.lib.json b/api/libs/feature-amounts-per-planning-unit/tsconfig.lib.json similarity index 73% rename from api/libs/puvspr-calculations/tsconfig.lib.json rename to api/libs/feature-amounts-per-planning-unit/tsconfig.lib.json index e55ed1384a..73e9cc160d 100644 --- a/api/libs/puvspr-calculations/tsconfig.lib.json +++ b/api/libs/feature-amounts-per-planning-unit/tsconfig.lib.json @@ -2,7 +2,7 @@ "extends": "../../tsconfig.json", "compilerOptions": { "declaration": true, - "outDir": "../../dist/libs/puvspr-calculations" + "outDir": "../../dist/libs/feature-amounts-per-planning-unit" }, "include": ["src/**/*"], "exclude": ["node_modules", "dist", "test", "**/*spec.ts"] diff --git a/api/libs/puvspr-calculations/src/index.ts b/api/libs/puvspr-calculations/src/index.ts deleted file mode 100644 index 02dddac2b8..0000000000 --- a/api/libs/puvspr-calculations/src/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -export { TypeOrmPuvsprCalculationsRepository } from './repository/typeorm-puvspr-calculations.repository'; -export { MemoryPuvsprCalculationsRepository } from './repository/memory-puvspr-calculations.repository'; -export { - PuvsprCalculationsRepository, - FeatureAmountPerProjectPlanningUnit, -} from './repository/puvspr-calculations.repository'; -export { PuvsprCalculationsEntity } from './puvspr-calculations.geo.entity'; -export { PuvsprCalculationsService } from './puvspr-calculations.service'; -export { PuvsprCalculationsModule } from './puvspr-calculations.module'; diff --git a/api/libs/puvspr-calculations/src/puvspr-calculations.module.ts b/api/libs/puvspr-calculations/src/puvspr-calculations.module.ts deleted file mode 100644 index 2a0fec7be8..0000000000 --- a/api/libs/puvspr-calculations/src/puvspr-calculations.module.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { DynamicModule, Module } from '@nestjs/common'; -import { getEntityManagerToken, TypeOrmModule } from '@nestjs/typeorm'; -import { TypeOrmPuvsprCalculationsRepository } from './repository/typeorm-puvspr-calculations.repository'; -import { PuvsprCalculationsEntity } from './puvspr-calculations.geo.entity'; -import { - geoEntityManagerToken, - PuvsprCalculationsService, -} from './puvspr-calculations.service'; -import { PuvsprCalculationsRepository } from './repository/puvspr-calculations.repository'; - -@Module({}) -export class PuvsprCalculationsModule { - static for(geoConnectionName: string): DynamicModule { - return { - module: PuvsprCalculationsModule, - imports: [ - TypeOrmModule.forFeature([PuvsprCalculationsEntity], geoConnectionName), - ], - providers: [ - { - provide: geoEntityManagerToken, - useExisting: getEntityManagerToken(geoConnectionName), - }, - PuvsprCalculationsService, - { - provide: PuvsprCalculationsRepository, - useClass: TypeOrmPuvsprCalculationsRepository, - }, - ], - exports: [PuvsprCalculationsService, PuvsprCalculationsRepository], - }; - } -} diff --git a/api/package.json b/api/package.json index 69637df048..b987faf363 100644 --- a/api/package.json +++ b/api/package.json @@ -244,8 +244,8 @@ "@marxan/planning-units-grid": "/libs/planning-units-grid/src", "@marxan/protected-areas/(.*)": "/libs/protected-areas/src/$1", "@marxan/protected-areas": "/libs/protected-areas/src", - "@marxan/puvspr-calculations/(.*)": "/libs/puvspr-calculations/src/$1", - "@marxan/puvspr-calculations": "/libs/puvspr-calculations/src", + "@marxan/feature-amounts-per-planning-unit/(.*)": "/libs/feature-amounts-per-planning-unit/src/$1", + "@marxan/feature-amounts-per-planning-unit": "/libs/feature-amounts-per-planning-unitF/src", "@marxan/specification/(.*)": "/libs/specification/src/$1", "@marxan/specification": "/libs/specification/src", "@marxan/tiles/(.*)": "/libs/tiles/src/$1", diff --git a/api/tsconfig.json b/api/tsconfig.json index 599eb81496..45f62db3b1 100644 --- a/api/tsconfig.json +++ b/api/tsconfig.json @@ -140,11 +140,11 @@ "@marxan/protected-areas/*": [ "libs/protected-areas/src/*" ], - "@marxan/puvspr-calculations": [ - "libs/puvspr-calculations/src" + "@marxan/feature-amounts-per-planning-unit": [ + "libs/feature-amounts-per-planning-unit/src" ], - "@marxan/puvspr-calculations/*": [ - "libs/puvspr-calculations/src/*" + "@marxan/feature-amounts-per-planning-unit/*": [ + "libs/feature-amounts-per-planning-unit/src/*" ], "@marxan/specification": [ "libs/specification/src" diff --git a/docs/features/db-storage/README_db-storage-of-marxan-features.md b/docs/features/db-storage/README_db-storage-of-marxan-features.md index 3a4a6222c3..cc1bea273f 100644 --- a/docs/features/db-storage/README_db-storage-of-marxan-features.md +++ b/docs/features/db-storage/README_db-storage-of-marxan-features.md @@ -39,7 +39,7 @@ When we process/calculate features that were created from shapefiles (that is, to calculate the area of the intersection between a feature and each planning unit in a project), we do generate a union of all of a feature's geometries "on the fly" via `st_union()` (see -`PuvsprCalculationsService.computeMarxanAmountPerPlanningUnit()`), and then +`FeatureAmountsPerPlanningUnitService.computeMarxanAmountPerPlanningUnit()`), and then intersect this "whole feature" with each planning unit, and calculate the intersection area as "amount" of the feature).