Skip to content

Commit

Permalink
report min/max amounts in square km for features from shapefile
Browse files Browse the repository at this point in the history
  • Loading branch information
hotzevzl authored and KevSanchez committed Dec 21, 2023
1 parent 26990b9 commit 42e452d
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions api/apps/api/src/modules/projects/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ import {
} from '@marxan-api/modules/projects/protected-area/add-protected-area.service';
import { ensureShapefileHasRequiredFiles } from '@marxan-api/utils/file-uploads.utils';
import { CostSurfaceService } from '@marxan-api/modules/cost-surface/cost-surface.service';
import { GeoFeature } from '../geo-features/geo-feature.api.entity';
export { validationFailed } from '../planning-areas';

export const projectNotFound = Symbol(`project not found`);
Expand Down Expand Up @@ -191,10 +192,7 @@ export class ProjectsService {
data: result.data.map((feature) => {
return {
...feature,
amountRange: {
min: feature?.amountMin ?? null,
max: feature?.amountMax ?? null,
},
amountRange: this.transformMinMaxAmountsFromSquareMetresToSquareKmsForFeaturesFromShapefile(feature),
};
}),
metadata: result.metadata,
Expand All @@ -203,6 +201,23 @@ export class ProjectsService {
return right(resultWithMappedAmountRange);
}

/**
* When reporting feature min/max ranges, amounts set by users for "legacy"
* features (that is, either features from legacy projects or features from
* CSV files with puvspr data - for both we set `isLegacy = true`) should
* be used verbatim; amounts calculated within the platform for features
* uploaded from shapefiles, instead, should be divided by 1M in order to
* report them in square km rather than in square metres (they are stored
* in square metres in the platform's backend).
*/
transformMinMaxAmountsFromSquareMetresToSquareKmsForFeaturesFromShapefile(feature: Partial<GeoFeature> | undefined): { min: number | null, max: number | null } {
const min = feature?.amountMin ? (feature.isLegacy ? feature.amountMin : feature.amountMin / 1_000_000) : null;
const max = feature?.amountMax ? (feature.isLegacy ? feature.amountMax : feature.amountMax / 1_000_000) : null;
return {
min, max
};
}

async findAll(fetchSpec: FetchSpecification, info: ProjectsServiceRequest) {
return this.projectsCrud.findAllPaginated(fetchSpec, info);
}
Expand Down

0 comments on commit 42e452d

Please sign in to comment.