From d30303b525eb156f472ee4db4c812a021f37bb43 Mon Sep 17 00:00:00 2001 From: Kevin Date: Mon, 23 Oct 2023 15:14:01 +0200 Subject: [PATCH] refactor(Feature Amounts): Further PUVSPR refactors --- .../api/src/modules/geo-features/geo-features.service.ts | 6 +++--- .../geo-features/import/features-amounts-upload.service.ts | 5 +++-- .../geoprocessing/src/modules/features/features.service.ts | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/api/apps/api/src/modules/geo-features/geo-features.service.ts b/api/apps/api/src/modules/geo-features/geo-features.service.ts index e604fb9558..c80ea2bcde 100644 --- a/api/apps/api/src/modules/geo-features/geo-features.service.ts +++ b/api/apps/api/src/modules/geo-features/geo-features.service.ts @@ -849,9 +849,9 @@ export class GeoFeaturesService extends AppBaseService< .select('feature_id', 'id') .addSelect('MIN(amount)', 'amountMin') .addSelect('MAX(amount)', 'amountMax') - .from('puvspr_calculations', 'puvspr') - .where('puvspr.feature_id IN (:...featureIds)', { featureIds }) - .groupBy('puvspr.feature_id') + .from('feature_amounts_per_planning_unit', 'fappu') + .where('fappu.feature_id IN (:...featureIds)', { featureIds }) + .groupBy('fappu.feature_id') .getRawMany(); const minMaxSqlValueStringForFeatures = minAndMaxAmountsForFeatures diff --git a/api/apps/api/src/modules/geo-features/import/features-amounts-upload.service.ts b/api/apps/api/src/modules/geo-features/import/features-amounts-upload.service.ts index 75f31629c9..83e1e1b3d7 100644 --- a/api/apps/api/src/modules/geo-features/import/features-amounts-upload.service.ts +++ b/api/apps/api/src/modules/geo-features/import/features-amounts-upload.service.ts @@ -26,7 +26,6 @@ import { CHUNK_SIZE_FOR_BATCH_APIDB_OPERATIONS } from '@marxan-api/utils/chunk-s import { UploadedFeatureAmount } from '@marxan-api/modules/geo-features/import/features-amounts-data.api.entity'; import { Project } from '@marxan-api/modules/projects/project.api.entity'; import { ProjectSourcesEnum } from '@marxan/projects'; -import { ScenariosService } from '@marxan-api/modules/scenarios/scenarios.service'; @Injectable() export class FeatureAmountUploadService { @@ -335,7 +334,9 @@ export class FeatureAmountUploadService { parameters, ); await geoQueryRunner.manager.query( - ` INSERT INTO puvspr_calculations (project_id, feature_id, amount, project_pu_id) select $1, $2, amount, project_pu_id from features_data where feature_id = $2`, + ` INSERT INTO feature_amounts_per_planning_unit (project_id, feature_id, amount, project_pu_id) + SELECT $1, $2, amount, project_pu_id + FROM features_data where feature_id = $2`, [projectId, newFeature.id], ); this.logger.log( diff --git a/api/apps/geoprocessing/src/modules/features/features.service.ts b/api/apps/geoprocessing/src/modules/features/features.service.ts index 09bd406235..9c25fe834f 100644 --- a/api/apps/geoprocessing/src/modules/features/features.service.ts +++ b/api/apps/geoprocessing/src/modules/features/features.service.ts @@ -1,4 +1,4 @@ -import { Injectable, Logger, Inject } from '@nestjs/common'; +import { Injectable, Logger } from '@nestjs/common'; import { TileService } from '@marxan-geoprocessing/modules/tile/tile.service'; import { InjectRepository } from '@nestjs/typeorm'; import { Repository } from 'typeorm'; @@ -81,8 +81,8 @@ export class FeatureService { ? `(SELECT ST_RemoveRepeatedPoints((st_dump(the_geom)).geom, ${simplificationLevel}) AS the_geom, amount, feature_id - FROM puvspr_calculations - INNER JOIN projects_pu ppu on ppu.id=puvspr_calculations.project_pu_id + FROM feature_amounts_per_planning_unit + INNER JOIN projects_pu ppu on ppu.id=feature_amounts_per_planning_unit.project_pu_id INNER JOIN planning_units_geom pug on pug.id=ppu.geom_id)` : `(select ST_RemoveRepeatedPoints((st_dump(the_geom)).geom, ${simplificationLevel}) as the_geom, (coalesce(properties,'{}'::jsonb) || jsonb_build_object('amount', amount)) as properties,