diff --git a/app/src/api/services/building/planningData.ts b/app/src/api/services/building/planningData.ts
index adc92a6d..9407ab78 100644
--- a/app/src/api/services/building/planningData.ts
+++ b/app/src/api/services/building/planningData.ts
@@ -3,7 +3,7 @@ import db from '../../../db';
export async function getBuildingPlanningDataById(id: number) {
try {
return await db.any(
- 'SELECT building_properties.uprn, building_properties.building_id, planning_data.description, planning_data.status, planning_data.status_before_aliasing, planning_data.uprn, planning_data.planning_application_id, planning_application_link, to_char(planning_data.registered_with_local_authority_date, \'YYYY-MM-DD\') AS registered_with_local_authority_date, to_char(planning_data.decision_date, \'YYYY-MM-DD\') AS decision_date, to_char(planning_data.last_synced_date, \'YYYY-MM-DD\') AS last_synced_date, planning_data.data_source, planning_data.data_source_link \
+ 'SELECT building_properties.uprn, building_properties.building_id, planning_data.description, planning_data.status, planning_data.status_before_aliasing, planning_data.status_explanation_note, planning_data.uprn, planning_data.planning_application_id, planning_application_link, to_char(planning_data.registered_with_local_authority_date, \'YYYY-MM-DD\') AS registered_with_local_authority_date, to_char(planning_data.decision_date, \'YYYY-MM-DD\') AS decision_date, to_char(planning_data.last_synced_date, \'YYYY-MM-DD\') AS last_synced_date, planning_data.data_source, planning_data.data_source_link \
FROM building_properties \
INNER JOIN planning_data ON \
building_properties.uprn = planning_data.uprn WHERE building_id = $1',
diff --git a/app/src/frontend/building/data-components/planning-data-entry.tsx b/app/src/frontend/building/data-components/planning-data-entry.tsx
index 78ed556c..f4c4459b 100644
--- a/app/src/frontend/building/data-components/planning-data-entry.tsx
+++ b/app/src/frontend/building/data-components/planning-data-entry.tsx
@@ -103,6 +103,7 @@ const PlanningDataOfficialDataEntry: React.FC
+ {item["status_explanation_note"] ?
Explanation: {item["status_explanation_note"]}
: <>>}
Planning application ID: {ShowIfAvailable(item["planning_application_id"])}
Date registered by the planning authority (validation date): {ShowIfAvailable(item["registered_with_local_authority_date"])}
Decision date: {ShowIfAvailable(item["decision_date"])}
diff --git a/etl/planning_data/obtain_livestream_data_and_load_into_database.py b/etl/planning_data/obtain_livestream_data_and_load_into_database.py
index 2f1d856e..b123967c 100644
--- a/etl/planning_data/obtain_livestream_data_and_load_into_database.py
+++ b/etl/planning_data/obtain_livestream_data_and_load_into_database.py
@@ -43,7 +43,9 @@ def load_data_into_database(cursor, data):
last_synced_date = parse_date_string_into_date_object(entry['_source']['last_synced'])
uprn = entry['_source']['uprn']
status_before_aliasing = entry['_source']['status']
- status = process_status(status_before_aliasing, decision_date)
+ status_info = process_status(status_before_aliasing, decision_date)
+ status = status_info["status"]
+ status_explanation_note = status_info["status_explanation_note"]
planning_url = obtain_entry_link(entry['_source']['url_planning_app'], application_id)
if uprn == None:
continue
@@ -62,6 +64,7 @@ def load_data_into_database(cursor, data):
"uprn": uprn,
"status": status,
"status_before_aliasing": status_before_aliasing,
+ "status_explanation_note": status_explanation_note,
"data_source": "Greater London Authority's Planning London DataHub",
"data_source_link": None
}
@@ -163,9 +166,9 @@ def insert_entry(cursor, e):
if e["application_url"] != None:
application_url = e["application_url"]
cursor.execute('''INSERT INTO
- planning_data (planning_application_id, planning_application_link, description, registered_with_local_authority_date, days_since_registration_cached, decision_date, days_since_decision_date_cached, last_synced_date, status, status_before_aliasing, data_source, data_source_link, uprn)
+ planning_data (planning_application_id, planning_application_link, description, registered_with_local_authority_date, days_since_registration_cached, decision_date, days_since_decision_date_cached, last_synced_date, status, status_before_aliasing, status_explanation_note, data_source, data_source_link, uprn)
VALUES
- (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
+ (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
''', (
e["application_id"],
application_url, e["description"],
@@ -176,6 +179,7 @@ def insert_entry(cursor, e):
date_object_into_date_string(e["last_synced_date"]),
e["status"],
e["status_before_aliasing"],
+ e["status_explanation_note"],
e["data_source"],
e["data_source_link"],
e["uprn"])
@@ -263,10 +267,6 @@ def obtain_entry_link(provided_link, application_id):
def process_status(status, decision_date):
status_length_limit = 50 # see migrations/034.planning_livestream_data.up.sql
- if len(status) > status_length_limit:
- print("Status was too long and was skipped:", status)
- return None
- """return None if status is invalid"""
if status in ["Application Under Consideration", "Application Received"]:
if decision_date == None:
status = "Submitted"
@@ -280,12 +280,17 @@ def process_status(status, decision_date):
status = "Unknown"
if status in ["Lapsed"]:
status = "Withdrawn"
+ if len(status) > status_length_limit:
+ print("Status was too long and was skipped:", status)
+ return {"status": "Processing failed", "status_explanation_note": "status was unusally long and it was imposible to save it"}
if (status in ["Submitted", "Approved", "Rejected", "Appeal In Progress", "Withdrawn", "Unknown"]):
- return status
+ return {"status": status, "status_explanation_note": None}
+ if status in ["No Objection to Proposal (OBS only)", "Objection Raised to Proposal (OBS only)"]:
+ return {"status": "Approved", "status_explanation_note": "preapproved application, local authority is unable to reject it"}
print("Unexpected status " + status)
- if status not in ["No Objection to Proposal (OBS only)", "Objection Raised to Proposal (OBS only)", "Not Required", "SECS", "Comment Issued", "ALL DECISIONS ISSUED", "Closed", "Declined to Determine"]:
+ if status not in ["Not Required", "SECS", "Comment Issued", "ALL DECISIONS ISSUED", "Closed", "Declined to Determine"]:
print("New unexpected status " + status)
- return status
+ return {"status": status, "status_explanation_note": None}
if __name__ == '__main__':
diff --git a/migrations/034.planning_livestream_data.up.sql b/migrations/034.planning_livestream_data.up.sql
index b51aec5f..c304706b 100644
--- a/migrations/034.planning_livestream_data.up.sql
+++ b/migrations/034.planning_livestream_data.up.sql
@@ -13,6 +13,7 @@ CREATE TABLE IF NOT EXISTS planning_data (
last_synced_date date,
status VARCHAR(50),
status_before_aliasing VARCHAR(50),
+ status_explanation_note VARCHAR(250),
data_source VARCHAR(70),
data_source_link VARCHAR(150),
uprn bigint