date cacing hack
This commit is contained in:
parent
d4ec4653b8
commit
b4b17c7c48
@ -143,15 +143,15 @@ const LAYER_QUERIES = {
|
|||||||
INNER JOIN buildings ON building_properties.building_id = buildings.building_id`,
|
INNER JOIN buildings ON building_properties.building_id = buildings.building_id`,
|
||||||
planning_applications_status_recent: `SELECT
|
planning_applications_status_recent: `SELECT
|
||||||
buildings.geometry_id, building_properties.uprn, building_properties.building_id, planning_data.status AS status, planning_data.uprn,
|
buildings.geometry_id, building_properties.uprn, building_properties.building_id, planning_data.status AS status, planning_data.uprn,
|
||||||
EXTRACT(epoch FROM age(decision_date))/3600/24 AS days_since_decision_date,
|
1 AS days_since_decision_date,
|
||||||
EXTRACT(epoch FROM age(registered_with_local_authority_date))/3600/24 AS days_since_registered_with_local_authority_date
|
1 AS days_since_registered_with_local_authority_date
|
||||||
FROM building_properties
|
FROM building_properties
|
||||||
INNER JOIN planning_data ON building_properties.uprn = planning_data.uprn
|
INNER JOIN planning_data ON building_properties.uprn = planning_data.uprn
|
||||||
INNER JOIN buildings ON building_properties.building_id = buildings.building_id`,
|
INNER JOIN buildings ON building_properties.building_id = buildings.building_id`,
|
||||||
planning_applications_status_very_recent: `SELECT
|
planning_applications_status_very_recent: `SELECT
|
||||||
buildings.geometry_id, building_properties.uprn, building_properties.building_id, planning_data.status AS status, planning_data.uprn,
|
buildings.geometry_id, building_properties.uprn, building_properties.building_id, planning_data.status AS status, planning_data.uprn,
|
||||||
EXTRACT(epoch FROM age(decision_date))/3600/24 AS days_since_decision_date,
|
planning_data.days_since_decision_date_cached AS days_since_decision_date,
|
||||||
EXTRACT(epoch FROM age(registered_with_local_authority_date))/3600/24 AS days_since_registered_with_local_authority_date
|
planning_data.days_since_registration_cached AS days_since_registered_with_local_authority_date
|
||||||
FROM building_properties
|
FROM building_properties
|
||||||
INNER JOIN planning_data ON building_properties.uprn = planning_data.uprn
|
INNER JOIN planning_data ON building_properties.uprn = planning_data.uprn
|
||||||
INNER JOIN buildings ON building_properties.building_id = buildings.building_id`,
|
INNER JOIN buildings ON building_properties.building_id = buildings.building_id`,
|
||||||
|
@ -136,18 +136,21 @@ def filepath():
|
|||||||
return os.path.dirname(os.path.realpath(__file__)) + os.sep + "data.json"
|
return os.path.dirname(os.path.realpath(__file__)) + os.sep + "data.json"
|
||||||
|
|
||||||
def insert_entry(cursor, e):
|
def insert_entry(cursor, e):
|
||||||
|
now = datetime.datetime.now()
|
||||||
application_url = None
|
application_url = None
|
||||||
if e["application_url"] != None:
|
if e["application_url"] != None:
|
||||||
application_url = e["application_url"]
|
application_url = e["application_url"]
|
||||||
cursor.execute('''INSERT INTO
|
cursor.execute('''INSERT INTO
|
||||||
planning_data (planning_application_id, planning_application_link, description, registered_with_local_authority_date, decision_date, 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, data_source, data_source_link, uprn)
|
||||||
VALUES
|
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)
|
||||||
''', (
|
''', (
|
||||||
e["application_id"],
|
e["application_id"],
|
||||||
application_url, e["description"],
|
application_url, e["description"],
|
||||||
date_object_into_date_string(e["registered_with_local_authority_date"]),
|
date_object_into_date_string(e["registered_with_local_authority_date"]),
|
||||||
|
days_since(e["registered_with_local_authority_date"], now),
|
||||||
date_object_into_date_string(e["decision_date"]),
|
date_object_into_date_string(e["decision_date"]),
|
||||||
|
days_since(e["decision_date"], now),
|
||||||
date_object_into_date_string(e["last_synced_date"]),
|
date_object_into_date_string(e["last_synced_date"]),
|
||||||
e["status"], e["status_before_aliasing"],
|
e["status"], e["status_before_aliasing"],
|
||||||
e["data_source"],
|
e["data_source"],
|
||||||
@ -155,6 +158,11 @@ def insert_entry(cursor, e):
|
|||||||
e["uprn"])
|
e["uprn"])
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def days_since(date, now):
|
||||||
|
if(date == None):
|
||||||
|
return None
|
||||||
|
return (now - date).days
|
||||||
|
|
||||||
def date_object_into_date_string(date):
|
def date_object_into_date_string(date):
|
||||||
if(date == None):
|
if(date == None):
|
||||||
return None
|
return None
|
||||||
|
@ -7,7 +7,9 @@ CREATE TABLE IF NOT EXISTS planning_data (
|
|||||||
planning_application_link VARCHAR(260),
|
planning_application_link VARCHAR(260),
|
||||||
description VARCHAR,
|
description VARCHAR,
|
||||||
registered_with_local_authority_date date,
|
registered_with_local_authority_date date,
|
||||||
|
days_since_registration_cached smallint,
|
||||||
decision_date date,
|
decision_date date,
|
||||||
|
days_since_decision_date_cached smallint,
|
||||||
last_synced_date date,
|
last_synced_date date,
|
||||||
status VARCHAR(50),
|
status VARCHAR(50),
|
||||||
status_before_aliasing VARCHAR(50),
|
status_before_aliasing VARCHAR(50),
|
||||||
|
Loading…
Reference in New Issue
Block a user