add status explanation note
this allow to handle OBS statuses, also done in this commit
This commit is contained in:
parent
dffa4e244b
commit
9512d30c28
@ -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',
|
||||
|
@ -103,6 +103,7 @@ const PlanningDataOfficialDataEntry: React.FC<PlanningDataOfficialDataEntryProps
|
||||
statusBeforeAliasing={item["status_before_aliasing"]}
|
||||
status={item["status"]}
|
||||
/></div>
|
||||
{item["status_explanation_note"] ? <div><b>Explanation</b>: {item["status_explanation_note"]}</div> : <></>}
|
||||
<div><b>Planning application ID:</b> {ShowIfAvailable(item["planning_application_id"])}</div>
|
||||
<div><b>Date registered by the planning authority (validation date)</b>: {ShowIfAvailable(item["registered_with_local_authority_date"])}</div>
|
||||
<div><b>Decision date</b>: {ShowIfAvailable(item["decision_date"])}</div>
|
||||
|
@ -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__':
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user