Skip to content

Commit

Permalink
fix(planning-units): follow marxan real usage instead of documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
kgajowy committed Sep 29, 2021
1 parent 7d2c665 commit e524b7e
Show file tree
Hide file tree
Showing 6 changed files with 1,024 additions and 1,006 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export class CostSurfaceViewService {
const tsvRow = [
data.puid,
data.spucd_cost ?? 0,
data.lockin_status ?? 0,
this.#fixMarxanIssue(data.lockin_status) ?? 0,
].join(this.#separator);
responseStream.write(`\n`);
responseStream.write(tsvRow);
Expand All @@ -56,4 +56,22 @@ export class CostSurfaceViewService {
responseStream.end();
});
}

/**
* alicia.arenzana 27.09.2021 10:24
even though the manual covers a values 0, 1, 2 for maybe, yes and no (inclusion/exclusion)
the software still uses the old version setup 0, 1, 2, 3 for maybe, we don't know, yes and no (exclusion/inclusion) so our 2 should be an exclusion but is intead an inclusion
* @param lockinStatus
*/
#fixMarxanIssue = (lockinStatus: number | null): number | null => {
if (lockinStatus === 1) {
return 2;
}

if (lockinStatus === 2) {
return 3;
}

return lockinStatus;
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ describe(`When scenario has PUs with cost and lock status`, () => {
expect(costAndStatus).toMatchInlineSnapshot(`
Array [
"0 200 0",
"1 400 1",
"2 600 2",
"1 400 2",
"2 600 3",
"3 800 0",
]
`);
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { plainToClass } from 'class-transformer';
import { v4 } from 'uuid';
import { Job } from 'bullmq';
import { Repository } from 'typeorm';
import { booleanEqual } from '@turf/turf';
import { FeatureCollection } from 'geojson';

import { AppConfig } from '@marxan-geoprocessing/utils/config.utils';
import { PlanningUnitsGeom } from '@marxan-jobs/planning-unit-geometry';

import { JobInput, JobOutput } from '@marxan/planning-units-grid';
import { PlanningUnitsGridProcessor } from '@marxan-geoprocessing/modules/planning-units-grid/planning-units-grid.processor';

Expand All @@ -21,6 +22,9 @@ export const getFixtures = async () => {
const projectId = v4();
return {
cleanup: async () => {
await puGeoRepo.delete({
projectId,
});
await app.close();
},
projectId,
Expand Down Expand Up @@ -55,27 +59,32 @@ export const getFixtures = async () => {
}),
);

const geoJsonFromGeometries = (
const geoJsonFromGeometries: FeatureCollection = (
await puGeoRepo.query(
`
select json_build_object(
'type', 'FeatureCollection',
'features', json_agg(ST_AsGeoJSON((t.*)::record, '', 15)::json)
)
from (
select the_geom
from planning_units_geom
where type = 'from_shapefile'
and project_id = $1
) as t(geom)
'features',
json_agg(ST_AsGeoJSON((t.*)::record, '', 15)::json)
)
from (
select the_geom
from planning_units_geom
where type = 'from_shapefile'
and project_id = $1
) as t(geom)
`,
[projectId],
)
)[0].json_build_object;

expect(underlyingGeoJson.features).toEqual(
expect.arrayContaining(geoJsonFromGeometries.features),
);
for (const geo of underlyingGeoJson.features) {
expect(
geoJsonFromGeometries.features.some((geoFromJson) =>
booleanEqual(geoFromJson, geo),
),
).toBeTruthy();
}

expect(output.projectId).toEqual(projectId);
expect(output.geometryIds.length).toEqual(
Expand Down
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"@nestjs/typeorm": "^7.1.5",
"@pgtyped/cli": "0.11.0",
"@pgtyped/query": "0.11.0",
"@turf/turf": "^5.1.6",
"@turf/turf": "6.5.0",
"abort-controller": "3.0.0",
"archiver": "5.3.0",
"axios": "0.21.1",
Expand Down
Loading

0 comments on commit e524b7e

Please sign in to comment.