Skip to content

Commit

Permalink
refactor(Feature Amounts): Further PUVSPR refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
KevSanchez authored and hotzevzl committed Oct 26, 2023
1 parent ba4804a commit 963fd17
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
6 changes: 3 additions & 3 deletions api/apps/api/src/modules/geo-features/geo-features.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand Down

1 comment on commit 963fd17

@vercel
Copy link

@vercel vercel bot commented on 963fd17 Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

marxan – ./

marxan-git-develop-vizzuality1.vercel.app
marxan-vizzuality1.vercel.app
marxan23.vercel.app

Please sign in to comment.