Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unifies PUVSPR.dat info source from (geo)FeatureAmounts table [MRXN23-469] #1560

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,22 @@ import { FeatureAmountsPerPlanningUnitRepository } from '@marxan/feature-amounts
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { FeatureAmountPerPlanningUnitId, PuvsprDat } from './puvsrpr.dat';

export type FeatureAmountPerPlanningUnitId = {
featureId: string;
amount: number;
puId: number;
};

@Injectable()
export class PuvsprDatMarxanProject implements PuvsprDat {
export class PuvsprDatFeatureAmountsService {
constructor(
private readonly featureAmountsPerPlanningUnitRepo: FeatureAmountsPerPlanningUnitRepository,
@InjectRepository(ProjectsPuEntity, DbConnections.geoprocessingDB)
private readonly projectsPusRepo: Repository<ProjectsPuEntity>,
) {}
public async getAmountPerPlanningUnitAndFeature(
projectId: string,
scenarioId: string,
featureIds: string[],
): Promise<FeatureAmountPerPlanningUnitId[]> {
const amountPerPlanningUnitOfFeature =
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@ import { TypeOrmModule } from '@nestjs/typeorm';
import { Scenario } from '../../scenario.api.entity';
import { GeoFeatureDtoMapper } from '../../specification/geo-feature-dto.mapper';
import { SplitFeatureConfigMapper } from '../../specification/split-feature-config.mapper';
import { PuvrsprDatFactory } from './puvspr.dat.factory';
import { PuvsprDatLegacyProject } from './puvspr.dat.legacy-project';
import { PuvsprDatMarxanProject } from './puvspr.dat.marxan-project';
import { PuvsprDatProcessor } from './puvspr.dat.processor';
import { FeatureHashModule } from '@marxan-api/modules/features-hash/features-hash.module';
import { ProjectsPuEntity } from '@marxan-jobs/planning-unit-geometry';
import { PuvsprDatFeatureAmountsService } from '@marxan-api/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.feature-amounts.service';

@Module({
imports: [
Expand All @@ -32,9 +30,7 @@ import { ProjectsPuEntity } from '@marxan-jobs/planning-unit-geometry';
providers: [
GeoFeatureDtoMapper,
PuvsprDatProcessor,
PuvrsprDatFactory,
PuvsprDatMarxanProject,
PuvsprDatLegacyProject,
PuvsprDatFeatureAmountsService,
SplitFeatureConfigMapper,
],
exports: [PuvsprDatProcessor],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { isLeft, left, right } from 'fp-ts/lib/Either';
import { EntityManager } from 'typeorm';
import { GeoFeatureDtoMapper } from '../../specification/geo-feature-dto.mapper';
import { SplitFeatureConfigMapper } from '../../specification/split-feature-config.mapper';
import { PuvrsprDatFactory } from './puvspr.dat.factory';
import { PuvsprDatFeatureAmountsService } from '@marxan-api/modules/scenarios/input-files/puvspr.dat.processor/puvspr.dat.feature-amounts.service';

export type PuvrsprDatRow = {
speciesId: number;
Expand All @@ -41,11 +41,10 @@ export class PuvsprDatProcessor {
private readonly featureAmountsPerPlanningUnitService: FeatureAmountsPerPlanningUnitService,
private readonly splitConfigHasher: SingleConfigFeatureValueHasher,
private readonly splitFeatureConfigMapper: SplitFeatureConfigMapper,
private readonly puvsprDatFactory: PuvrsprDatFactory,
private readonly puvsprFeatureAmounts: PuvsprDatFeatureAmountsService,
) {}

async getPuvsprDatRows(
isLegacy: boolean,
scenarioId: string,
projectId: string,
): Promise<PuvrsprDatRow[]> {
Expand All @@ -64,10 +63,8 @@ export class PuvsprDatProcessor {
);

const featuresAmountPerPlanningUnit =
await this.getAmountPerPlanningUnitAndFeature(
isLegacy,
await this.puvsprFeatureAmounts.getAmountPerPlanningUnitAndFeature(
projectId,
scenarioId,
featuresIds,
);

Expand Down Expand Up @@ -133,21 +130,6 @@ export class PuvsprDatProcessor {
return copyFeatureIds.concat(splitFeatureIds);
}

private async getAmountPerPlanningUnitAndFeature(
isLegacy: boolean,
projectId: string,
scenarioId: string,
fetaureIds: string[],
) {
const puvspr = this.puvsprDatFactory.getPuvsrDat(isLegacy);

return puvspr.getAmountPerPlanningUnitAndFeature(
projectId,
scenarioId,
fetaureIds,
);
}

private getCopyFeatureIds(
featureConfigs: (SpecificationFeatureCopy | SpecificationFeatureSplit)[],
) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Project } from '@marxan-api/modules/projects/project.api.entity';
import { ProjectSourcesEnum } from '@marxan/projects';
import { assertDefined } from '@marxan/utils';
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { isRight } from 'fp-ts/lib/Either';
import { Repository } from 'typeorm';
import { Scenario } from '../scenario.api.entity';
import {
Expand All @@ -29,25 +27,14 @@ export class PuvsprDatService {

const projectId = scenario.projectId;

const isLegacyProject = await this.isLegacyProject(projectId);

const puvsprRows = await this.puvsprDatProcessor.getPuvsprDatRows(
isLegacyProject,
scenarioId,
projectId,
);

return this.getFileContent(puvsprRows);
}

private async isLegacyProject(projectId: string) {
const [project] = await this.projectsRepo.find({
where: { id: projectId },
});
assertDefined(project);
return project.sources === ProjectSourcesEnum.legacyImport;
}

private getFileContent(rows: PuvrsprDatRow[]) {
return (
'species\tpu\tamount\n' +
Expand Down
Loading