Skip to content

Commit

Permalink
migrate: find+replace article4, listed building grades, and flood zon…
Browse files Browse the repository at this point in the history
…e `fn` (#4151)
  • Loading branch information
jessicamcinchak authored Jan 20, 2025
1 parent 854b698 commit e2f49c1
Show file tree
Hide file tree
Showing 35 changed files with 1,055 additions and 1,013 deletions.
58 changes: 34 additions & 24 deletions api.planx.uk/modules/gis/service/digitalLand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import * as westBerkshire from "./local_authorities/metadata/westBerkshire.js";

export interface LocalAuthorityMetadata {
planningConstraints: {
article4: {
articleFour: {
records: Record<string, string>;
};
};
Expand Down Expand Up @@ -214,30 +214,40 @@ async function go(
}

// --- FLOODING ---
const zoneLookup: Record<string, string> = {
"flood.zone.2": "flood.zoneTwo",
"flood.zone.3": "flood.zoneThree",
};
if (formattedResult["flood"] && formattedResult["flood"].value) {
["flood.zone.2", "flood.zone.3"].forEach(
(zone) =>
(formattedResult[zone] = {
fn: zone,
Object.keys(zoneLookup).forEach(
(oldZone) =>
(formattedResult[zoneLookup[oldZone]] = {
fn: zoneLookup[oldZone],
value: Boolean(
formattedResult["flood"].data?.filter(
(entity) => entity["flood-risk-level"] === zone.split(".").pop(),
(entity) =>
entity["flood-risk-level"] === oldZone.split(".").pop(),
).length,
),
}),
);
}

// --- LISTED BUILDINGS ---
const gradeLookup: Record<string, string> = {
"listed.grade.I": "listed.gradeOne",
"listed.grade.II": "listed.gradeTwo",
"listed.grade.II*": "listed.gradeTwoStar",
};
if (formattedResult["listed"] && formattedResult["listed"].value) {
["listed.grade.I", "listed.grade.II", "listed.grade.II*"].forEach(
(grade) =>
(formattedResult[grade] = {
fn: grade,
Object.keys(gradeLookup).forEach(
(oldGrade) =>
(formattedResult[gradeLookup[oldGrade]] = {
fn: gradeLookup[oldGrade],
value: Boolean(
formattedResult["listed"].data?.filter(
(entity) =>
entity["listed-building-grade"] === grade.split(".").pop(),
entity["listed-building-grade"] === oldGrade.split(".").pop(),
).length,
),
}),
Expand All @@ -249,11 +259,11 @@ async function go(
if (Object.keys(localAuthorityMetadata).includes(localAuthority)) {
// get the article 4 schema map for this local authority
const { planningConstraints } = localAuthorityMetadata[localAuthority];
const a4s = planningConstraints["article4"]["records"] || undefined;
const a4s = planningConstraints["articleFour"]["records"] || undefined;

// loop through any intersecting a4 data entities and set granular planx values based on this local authority's schema
if (a4s && formattedResult["article4"]?.value) {
formattedResult["article4"]?.data?.forEach((entity: any) => {
if (a4s && formattedResult["articleFour"]?.value) {
formattedResult["articleFour"]?.data?.forEach((entity: any) => {
Object.keys(a4s)?.forEach((key) => {
if (
// these are various ways we link source data to granular planx values (see local_authorities/metadata for specifics)
Expand All @@ -272,23 +282,23 @@ async function go(
});
}

// rename `article4.caz` to reflect localAuthority if applicable
const localCaz = `article4.${localAuthority}.caz`;
if (formattedResult["article4.caz"]) {
formattedResult[localCaz] = formattedResult["article4.caz"];
delete formattedResult["article4.caz"];
// rename `articleFour.caz` to reflect localAuthority if applicable
const localCaz = `articleFour.${localAuthority}.caz`;
if (formattedResult["articleFour.caz"]) {
formattedResult[localCaz] = formattedResult["articleFour.caz"];
delete formattedResult["articleFour.caz"];

// if caz is true, but parent a4 is false, sync a4 for accurate granularity
if (
formattedResult[localCaz]?.value &&
!formattedResult["article4"]?.value
!formattedResult["articleFour"]?.value
) {
formattedResult["article4"] = {
fn: "article4",
formattedResult["articleFour"] = {
fn: "articleFour",
value: true,
text: baseSchema["article4"].pos,
text: baseSchema["articleFour"].pos,
data: formattedResult[localCaz].data,
category: baseSchema["article4"].category,
category: baseSchema["articleFour"].category,
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion api.planx.uk/modules/gis/service/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe.skip("fetching GIS data from Digital Land for supported local authoriti
.get(`/gis/${location.council}?geom=${location.geom}`)
.expect(200)
.then((res) => {
expect(res.body["constraints"]["article4"]).toBeDefined();
expect(res.body["constraints"]["articleFour"]).toBeDefined();
expect(res.body["constraints"]["listed"]).toBeDefined();
expect(
res.body["constraints"]["designated.conservationArea"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ https://docs.google.com/spreadsheets/d/1UmxQ95SjU72j0KaVIIkrIfhdE_k_lcFNhUWBc53G
import type { LocalAuthorityMetadata } from "../../digitalLand.js";

const planningConstraints: LocalAuthorityMetadata["planningConstraints"] = {
article4: {
articleFour: {
// Planx granular values link to entity.reference on Planning Data
records: {
"article4.barkingAndDagenham.additionalStoreys.dagenhamVillage": "A4D01",
"article4.barkingAndDagenham.additionalStoreys.lymington": "A4D02",
"article4.barkingAndDagenham.becontree":
"articleFour.barkingAndDagenham.additionalStoreys.dagenhamVillage":
"A4D01",
"articleFour.barkingAndDagenham.additionalStoreys.lymington": "A4D02",
"articleFour.barkingAndDagenham.becontree":
"Proposed Becontree Design Guide Article 4",
// "article4.barkingAndDagenham.becontree.corners": "TBD",
"article4.barkingAndDagenham.hmo": "A4D03",
// "articleFour.barkingAndDagenham.becontree.corners": "TBD",
"articleFour.barkingAndDagenham.hmo": "A4D03",
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ https://docs.google.com/spreadsheets/d/1ZjqYdC7upA8YS9rBoyRIQPT1sqCXJBaxQDrvUh1t
import type { LocalAuthorityMetadata } from "../../digitalLand.js";

const planningConstraints: LocalAuthorityMetadata["planningConstraints"] = {
article4: {
articleFour: {
// Planx granular values link to Digital Land article-4-direction and entity.reference
records: {
"article4.barnet.finchleyChurchEnd": "A4D1",
"article4.barnet.finchleyGardenVillage": "A4D2A1",
"article4.barnet.glenhillClose": "A4D3A1",
"article4.barnet.hendonBurroughs.1": "A4D5A1",
"article4.barnet.hendonBurroughs.2": "A4D5A2",
"article4.barnet.hampsteadGardenSuburb": "A4D4A1",
"article4.barnet.spaniardsEnd": " A4D4A2",
"article4.barnet.millHillA": "A4D6",
"article4.barnet.millHillB": "A4D7",
"article4.barnet.monkenHadleyA": "A4D8",
"article4.barnet.monkenHadleyB": "A4D9",
"article4.barnet.mossHall": "A4D10",
"article4.barnet.totteridgeA": "A4D11",
"article4.barnet.totteridgeB": "A4D12",
"article4.barnet.woodStreet": "A4D13",
"article4.barnet.hmo": "A4D14",
"article4.barnet.agriculturalLand": "A4D15",
"articleFour.barnet.finchleyChurchEnd": "A4D1",
"articleFour.barnet.finchleyGardenVillage": "A4D2A1",
"articleFour.barnet.glenhillClose": "A4D3A1",
"articleFour.barnet.hendonBurroughs.one": "A4D5A1",
"articleFour.barnet.hendonBurroughs.two": "A4D5A2",
"articleFour.barnet.hampsteadGardenSuburb": "A4D4A1",
"articleFour.barnet.spaniardsEnd": " A4D4A2",
"articleFour.barnet.millHillA": "A4D6",
"articleFour.barnet.millHillB": "A4D7",
"articleFour.barnet.monkenHadleyA": "A4D8",
"articleFour.barnet.monkenHadleyB": "A4D9",
"articleFour.barnet.mossHall": "A4D10",
"articleFour.barnet.totteridgeA": "A4D11",
"articleFour.barnet.totteridgeB": "A4D12",
"articleFour.barnet.woodStreet": "A4D13",
"articleFour.barnet.hmo": "A4D14",
"articleFour.barnet.agriculturalLand": "A4D15",
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ type PlanningConstraintsBaseSchema = Record<string, PlanningConstraintConfig>;
// flag as 'active' based on dataset status/availability here https://www.planning.data.gov.uk/dataset/
// planx passport variable names & categories come from https://docs.google.com/spreadsheets/d/1ePihRD37-2071Wq6t2Y7QtBt7juySWuVP6SAF6T-0vo/edit?usp=sharing
const baseSchema: PlanningConstraintsBaseSchema = {
article4: {
articleFour: {
active: true,
neg: "is not in an Article 4 direction area",
pos: "is in an Article 4 direction area",
"digital-land-datasets": ["article-4-direction-area"],
category: "General policy",
},
"article4.caz": {
// will be renamed to `article4.localAuthority.caz` when applicable
"articleFour.caz": {
// will be renamed to `articleFour.localAuthority.caz` when applicable
active: true,
neg: "is not in the Central Activities Zone",
pos: "is in the Central Activities Zone",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ https://docs.google.com/spreadsheets/d/19t4DKDvyWix1Vf5huuQPVf9L8e6jcq1W/edit#gi
import type { LocalAuthorityMetadata } from "../../digitalLand.js";

const planningConstraints: LocalAuthorityMetadata["planningConstraints"] = {
article4: {
articleFour: {
// Planx granular values link to Digital Land entity.reference
records: {
"article4.birmingham.austinVillage": "30",
"article4.birmingham.bournvilleVillage": "8",
"article4.birmingham.cityWideHMO": "36",
"article4.birmingham.edgbaston": "15",
"article4.birmingham.greenfieldRoad": "32",
"article4.birmingham.highStSuttonColdfield": "13",
"article4.birmingham.moorPool": "7",
"article4.birmingham.moseleyVillage": "20",
"article4.birmingham.oldYardley": "5",
"article4.birmingham.sellyOak": "35",
"article4.birmingham.sellyPark": "34",
"article4.birmingham.sellyParkAvenues": "33",
"article4.birmingham.stAgnes": "22",
"articleFour.birmingham.austinVillage": "30",
"articleFour.birmingham.bournvilleVillage": "8",
"articleFour.birmingham.cityWideHMO": "36",
"articleFour.birmingham.edgbaston": "15",
"articleFour.birmingham.greenfieldRoad": "32",
"articleFour.birmingham.highStSuttonColdfield": "13",
"articleFour.birmingham.moorPool": "7",
"articleFour.birmingham.moseleyVillage": "20",
"articleFour.birmingham.oldYardley": "5",
"articleFour.birmingham.sellyOak": "35",
"articleFour.birmingham.sellyPark": "34",
"articleFour.birmingham.sellyParkAvenues": "33",
"articleFour.birmingham.stAgnes": "22",
},
},
};
Expand Down
Loading

0 comments on commit e2f49c1

Please sign in to comment.