From d0dbb5e69967c8d8305e01b62e4b61aca7b4de30 Mon Sep 17 00:00:00 2001 From: Alicia Date: Mon, 16 Aug 2021 18:32:04 +0200 Subject: [PATCH] added some fixes to job status --- .../job-status/job-status.view.api.entity.ts | 20 +++-- .../modules/projects/job-status/jobs.enum.ts | 1 + data/bots/demo-australia/bot.ts | 75 +++++++++++-------- docker-compose.yml | 1 + 4 files changed, 60 insertions(+), 37 deletions(-) diff --git a/api/apps/api/src/modules/projects/job-status/job-status.view.api.entity.ts b/api/apps/api/src/modules/projects/job-status/job-status.view.api.entity.ts index 8a1ec4c81e..46dbc6cc28 100644 --- a/api/apps/api/src/modules/projects/job-status/job-status.view.api.entity.ts +++ b/api/apps/api/src/modules/projects/job-status/job-status.view.api.entity.ts @@ -76,26 +76,32 @@ export class ScenarioJobStatus { const eventToJobStatusMapping: Record, JobStatus> = { [API_EVENT_KINDS.scenario__costSurface__costUpdateFailed__v1_alpha1]: JobStatus.failure, - [API_EVENT_KINDS.scenario__costSurface__finished__v1_alpha1]: JobStatus.done, + [API_EVENT_KINDS.scenario__costSurface__finished__v1_alpha1]: + JobStatus.done, [API_EVENT_KINDS.scenario__costSurface__shapeConversionFailed__v1_alpha1]: JobStatus.failure, [API_EVENT_KINDS.scenario__costSurface__shapeConverted__v1_alpha1]: JobStatus.running, [API_EVENT_KINDS.scenario__costSurface__submitted__v1_alpha1]: JobStatus.running, - [API_EVENT_KINDS.scenario__run__progress__v1__alpha1]: JobStatus.running, + [API_EVENT_KINDS.scenario__run__progress__v1__alpha1]: + JobStatus.running, [API_EVENT_KINDS.scenario__planningUnitsInclusion__failed__v1__alpha1]: JobStatus.failure, [API_EVENT_KINDS.scenario__planningUnitsInclusion__finished__v1__alpha1]: JobStatus.done, [API_EVENT_KINDS.scenario__planningUnitsInclusion__submitted__v1__alpha1]: JobStatus.running, - [API_EVENT_KINDS.scenario__run__submitted__v1__alpha1]: JobStatus.running, - [API_EVENT_KINDS.scenario__run__finished__v1__alpha1]: JobStatus.running, - [API_EVENT_KINDS.scenario__run__failed__v1__alpha1]: JobStatus.failure, + [API_EVENT_KINDS.scenario__run__submitted__v1__alpha1]: + JobStatus.running, + [API_EVENT_KINDS.scenario__run__finished__v1__alpha1]: + JobStatus.running, + [API_EVENT_KINDS.scenario__run__failed__v1__alpha1]: + JobStatus.failure, [API_EVENT_KINDS.scenario__run__outputSaveFailed__v1__alpha1]: JobStatus.failure, - [API_EVENT_KINDS.scenario__run__outputSaved__v1__alpha1]: JobStatus.done, + [API_EVENT_KINDS.scenario__run__outputSaved__v1__alpha1]: + JobStatus.done, [API_EVENT_KINDS.scenario__geofeatureCopy__submitted__v1__alpha1]: JobStatus.running, [API_EVENT_KINDS.scenario__geofeatureCopy__failed__v1__alpha1]: @@ -114,7 +120,7 @@ const eventToJobStatusMapping: Record, JobStatus> = { JobStatus.failure, [API_EVENT_KINDS.scenario__geofeatureStratification__finished__v1__alpha1]: JobStatus.done, - [API_EVENT_KINDS.scenario__planningAreaProtectedCalculation__failed__v1__alpha1]: + [API_EVENT_KINDS.scenario__planningAreaProtectedCalculation__failed__v1__alpha1]: JobStatus.failure, [API_EVENT_KINDS.scenario__planningAreaProtectedCalculation__finished__v1__alpha1]: JobStatus.done, diff --git a/api/apps/api/src/modules/projects/job-status/jobs.enum.ts b/api/apps/api/src/modules/projects/job-status/jobs.enum.ts index f89fea99a9..43a06fe9bb 100644 --- a/api/apps/api/src/modules/projects/job-status/jobs.enum.ts +++ b/api/apps/api/src/modules/projects/job-status/jobs.enum.ts @@ -7,4 +7,5 @@ export enum JobType { CostSurface = 'scenario.costSurface', Run = 'scenario.run', PlanningUnitInclusion = 'scenario.planningUnitsInclusion', + PlanningUnitPACalculation = 'scenario.planningAreaProtectedCalculation', } diff --git a/data/bots/demo-australia/bot.ts b/data/bots/demo-australia/bot.ts index 1c34709076..511043205b 100644 --- a/data/bots/demo-australia/bot.ts +++ b/data/bots/demo-australia/bot.ts @@ -96,15 +96,13 @@ const scenarioStart = Process.hrtime(); await sleep(5) -// get the list of protected areas in the region and use all of them -const paCategories = await botClient.get(`/protected-areas/iucn-categories?filter%5BcustomAreaId%5D=${planningAreaFile.id}`) - .then((result:{data:Array<{id:string, type:string, attributes:object}>}) => result.data) +const paCategories:{data:Array<{id:string, type:string, attributes:object}>} = await botClient.get(`/protected-areas/iucn-categories?filter%5BcustomAreaId%5D=${planningAreaFile.id}`) + .then((result) => result.data) .catch((e) => { console.log(e); }); console.log(paCategories); -console.log(paCategories.map((i): string => i.id)); const scenario = await botClient @@ -112,22 +110,48 @@ const scenario = await botClient name: `Kimberley ${project.data.attributes.name}`, type: "marxan", projectId: project.data.id, - description: "An Australia scenario", - wdpaIucnCategories: ["Not Applicable"], - wdpaThreshold: 50, + description: "An Australia scenario" }) .then((result) => result.data) .catch((e) => { console.log(e); }); + await sleep(5) +// get the list of protected areas in the region and use all of them + +await botClient + .patch(`/scenarios/${scenario!.data!.id}`, { + wdpaIucnCategories: paCategories!.data.map((i: {id:string, type:string, attributes:object}): string => i.id), + }).catch((e) => { + console.log(e); + }); + +console.log(scenario); + +await sleep(20) + +await botClient + .patch(`/scenarios/${scenario!.data!.id}`, { + wdpaThreshold: 50, + }).catch((e) => { + console.log(e); + }); const scenarioTook = Process.hrtime(scenarioStart); console.log(`Scenario creation done in ${scenarioTook[0]} seconds`); -console.log(scenario); +await botClient.get(`/scenarios/${scenario!.data!.id}`) + .then((result) => console.log(result.data)) + .catch((e) => { + console.log(e); + }); + +await sleep(5) + +// Setup features in the project const features = await botClient - .get(`/projects/${project.data.id}/features?q=demo_`) + .get(`/projects/${project.data.id}/features?q=demo`) .then((result) => result.data) .catch((e) => { console.log(e); @@ -137,28 +161,19 @@ console.log(features); const geoFeatureSpecStart = Process.hrtime(); -// const featureRecipe = features.forEach(element => element.id); { return { -// kind: "plain", -// featureId: x.id, -// marxanSettings: { -// prop: 0.3, -// fpf: 1, -// }, -// }}) -// console.log(featureRecipe); +const featureRecipe = features!.data.map((x: {id:string, type:string, attributes:object}) => { return { + kind: "plain", + featureId: x.id, + marxanSettings: { + prop: 0.3, + fpf: 1, + }, + }}) +console.log(featureRecipe); const geoFeatureSpec = await botClient .post(`/scenarios/${scenario.data.id}/features/specification`, { - status: "draft", - features: [ - { - kind: "plain", - featureId: features.data[0].id, - marxanSettings: { - prop: 0.3, - fpf: 1, - }, - }, - ], + status: "created", + features: featureRecipe }) .then((result) => result.data) .catch((e) => { @@ -171,4 +186,4 @@ console.log( `Processing of features for scenario done in ${geoFeatureSpecTook[0]} seconds` ); -console.log(geoFeatureSpec); +// console.log(geoFeatureSpec); diff --git a/docker-compose.yml b/docker-compose.yml index f480ff4b07..66d38ecb06 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -80,6 +80,7 @@ services: build: context: ./postgresql dockerfile: Dockerfile + shm_size: 1gb container_name: marxan-postgresql-api ports: - "${POSTGRES_API_SERVICE_PORT}:5432"