From 56dba3ed8e4253be146b825563778a3b1454c1eb Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Fri, 2 Feb 2024 16:05:26 +0100 Subject: [PATCH 1/3] add listed building grade --- .../modules/gis/service/digitalLand.ts | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/api.planx.uk/modules/gis/service/digitalLand.ts b/api.planx.uk/modules/gis/service/digitalLand.ts index f115761ccc..fe5ba5eca2 100644 --- a/api.planx.uk/modules/gis/service/digitalLand.ts +++ b/api.planx.uk/modules/gis/service/digitalLand.ts @@ -107,8 +107,9 @@ async function go( if (res && res.count > 0 && res.entities) { res.entities.forEach((entity: { dataset: any }) => { // get the planx variable that corresponds to this entity's 'dataset', should never be null because our initial request is filtered on 'dataset' - const key = Object.keys(baseSchema).find((key) => - baseSchema[key]["digital-land-datasets"]?.includes(entity.dataset), + const key = Object.keys(baseSchema).find( + (key) => + baseSchema[key]["digital-land-datasets"]?.includes(entity.dataset), ); // because there can be many digital land datasets per planx variable, check if this key is already in our result if (key && Object.keys(formattedResult).includes(key)) { @@ -170,7 +171,7 @@ async function go( formattedResult[broads] = { fn: broads, value: false }; } - // FLOODING + // --- FLOODING --- if (formattedResult["flood"] && formattedResult["flood"].value) { ["flood.zone.1", "flood.zone.2", "flood.zone.3"].forEach( (zone) => @@ -186,7 +187,20 @@ async function go( } // --- LISTED BUILDINGS --- - // TODO add granular variables to reflect grade (eg `listed.grade1`), not reflected in content yet though + if (formattedResult["listed"] && formattedResult["listed"].value) { + ["listd.grade.I", "listed.grade.II", "listed.grade.II*"].forEach( + (grade) => + (formattedResult[grade] = { + fn: grade, + value: Boolean( + formattedResult["listed"].data?.filter( + (entity) => + entity["listed-building-grade"] === grade.split(".").pop(), + ).length, + ), + }), + ); + } // --- ARTICLE 4S --- // only attempt to set granular a4s if we have metadata for this local authority; proceed with non-granular a4 queries under "opensystemslab" team etc @@ -254,8 +268,11 @@ async function go( .then((responses) => { responses.forEach((response: any) => { // get the planx variable that corresponds to this 'dataset', should never be null because we only requested known datasets - const key = Object.keys(baseSchema).find((key) => - baseSchema[key]["digital-land-datasets"]?.includes(response.dataset), + const key = Object.keys(baseSchema).find( + (key) => + baseSchema[key]["digital-land-datasets"]?.includes( + response.dataset, + ), ); if (key) metadata[key] = response; }); From e172b952f0fd68ff64890011739237be72a40991 Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Fri, 2 Feb 2024 16:42:59 +0100 Subject: [PATCH 2/3] run prettier with latest version --- api.planx.uk/modules/gis/service/digitalLand.ts | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/api.planx.uk/modules/gis/service/digitalLand.ts b/api.planx.uk/modules/gis/service/digitalLand.ts index fe5ba5eca2..7c604dda1b 100644 --- a/api.planx.uk/modules/gis/service/digitalLand.ts +++ b/api.planx.uk/modules/gis/service/digitalLand.ts @@ -107,9 +107,8 @@ async function go( if (res && res.count > 0 && res.entities) { res.entities.forEach((entity: { dataset: any }) => { // get the planx variable that corresponds to this entity's 'dataset', should never be null because our initial request is filtered on 'dataset' - const key = Object.keys(baseSchema).find( - (key) => - baseSchema[key]["digital-land-datasets"]?.includes(entity.dataset), + const key = Object.keys(baseSchema).find((key) => + baseSchema[key]["digital-land-datasets"]?.includes(entity.dataset), ); // because there can be many digital land datasets per planx variable, check if this key is already in our result if (key && Object.keys(formattedResult).includes(key)) { @@ -268,11 +267,8 @@ async function go( .then((responses) => { responses.forEach((response: any) => { // get the planx variable that corresponds to this 'dataset', should never be null because we only requested known datasets - const key = Object.keys(baseSchema).find( - (key) => - baseSchema[key]["digital-land-datasets"]?.includes( - response.dataset, - ), + const key = Object.keys(baseSchema).find((key) => + baseSchema[key]["digital-land-datasets"]?.includes(response.dataset), ); if (key) metadata[key] = response; }); From 322747d073ec4f854055cefe1077b6273c6d064e Mon Sep 17 00:00:00 2001 From: Jessica McInchak Date: Fri, 2 Feb 2024 17:12:22 +0100 Subject: [PATCH 3/3] fix typo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dafydd Llŷr Pearson --- api.planx.uk/modules/gis/service/digitalLand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api.planx.uk/modules/gis/service/digitalLand.ts b/api.planx.uk/modules/gis/service/digitalLand.ts index 7c604dda1b..9b228441f9 100644 --- a/api.planx.uk/modules/gis/service/digitalLand.ts +++ b/api.planx.uk/modules/gis/service/digitalLand.ts @@ -187,7 +187,7 @@ async function go( // --- LISTED BUILDINGS --- if (formattedResult["listed"] && formattedResult["listed"].value) { - ["listd.grade.I", "listed.grade.II", "listed.grade.II*"].forEach( + ["listed.grade.I", "listed.grade.II", "listed.grade.II*"].forEach( (grade) => (formattedResult[grade] = { fn: grade,