Skip to content

Commit 1130fbe

Browse files
Mike's updated SQL with bug fix
1 parent 7ba201b commit 1130fbe

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

scripts/jobs/parking/parking_permit_street_cpz_stress_mc.py

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,23 @@
2121
collects the Motorcycle spaces & permits
2222
2323
22/08/2024 - Create SQL
24+
11/02/2025 - add totals for following permit types
25+
permit_type, All Zone, Doctor, Dispensation, Health and Social Care
26+
Leisure centre permit, Community Support Permit
2427
*********************************************************************************/
2528
With parking_permit_denormalised_data as (
2629
SELECT *
27-
from "dataplatform-stg-liberator-refined-zone".parking_permit_denormalised_data
30+
from "dataplatform-prod-liberator-refined-zone".parking_permit_denormalised_data
2831
where import_date = format_datetime(current_date, 'yyyyMMdd')
2932
),
3033
LLPG as (
3134
SELECT *
32-
FROM "dataplatform-stg-liberator-raw-zone".liberator_permit_llpg
35+
FROM "dataplatform-prod-liberator-raw-zone".liberator_permit_llpg
3336
WHERE import_date = format_datetime(current_date, 'yyyyMMdd')
3437
),
3538
Street_Rec as (
3639
SELECT *
37-
FROM "dataplatform-stg-liberator-raw-zone".liberator_permit_llpg
40+
FROM "dataplatform-prod-liberator-raw-zone".liberator_permit_llpg
3841
WHERE import_date = format_datetime(current_date, 'yyyyMMdd')
3942
AND address1 = 'STREET RECORD'
4043
),
@@ -79,7 +82,7 @@
7982
END As Zone
8083
FROM "parking-raw-zone".geolive_parking_order as A
8184
WHERE import_date = (Select MAX(import_date) from "parking-raw-zone".geolive_parking_order)
82-
AND schedule = 'MC.001'
85+
AND schedule IN ('MC.001', 'MCC - F')
8386
AND street_name is not NULL
8487
),
8588
/** Summerise the Parkmap records **/
@@ -154,7 +157,7 @@
154157
/*** get the VRM details to obtain the m/c flag ***/
155158
MC_Permit_Flag as (
156159
SELECT *
157-
from "dataplatform-stg-liberator-raw-zone".liberator_permit_vrm_480
160+
from "dataplatform-prod-liberator-raw-zone".liberator_permit_vrm_480
158161
WHERE import_date = format_datetime(current_date, 'yyyyMMdd')
159162
),
160163
/** Get the Permits records link in the LLPG data **/
@@ -187,12 +190,7 @@
187190
AND A.VRM = D.vrm
188191
WHERE A.import_date = format_datetime(current_date, 'yyyyMMdd')
189192
AND current_date between start_date and end_date
190-
AND Permit_type IN (
191-
'Business',
192-
'Residents',
193-
'Companion Badge',
194-
'Estate Resident'
195-
)
193+
AND Permit_type not IN ('Suspension')
196194
AND latest_permit_status not IN ('Cancelled', 'Rejected', 'RENEW_REJECTED')
197195
),
198196
Permits_summ as (
@@ -246,6 +244,10 @@
246244
D.currentPermitTotal as Total_Business_Permits,
247245
E.currentPermitTotal as Total_Companion_Badge_Permits,
248246
L.currentPermitTotal as Total_Motorcycle_Permits,
247+
248+
/*** 11/02/2025 - Add other permits ***/
249+
N.currentPermitTotal as Total_Other_Permits,
250+
249251
/****/
250252
F.no_of_spaces as Business_bay_no_of_spaces,
251253
G.no_of_spaces as Shared_Use_no_of_spaces,
@@ -256,10 +258,12 @@
256258
M.no_of_spaces as Motorcycle_bay_no_of_spaces,
257259
/****/
258260
(
259-
coalesce(B.currentPermitTotal, 0) + coalesce(C.currentPermitTotal, 0) + coalesce(D.currentPermitTotal, 0) + coalesce(E.currentPermitTotal, 0) + coalesce(L.currentPermitTotal, 0)
261+
coalesce(B.currentPermitTotal, 0) + coalesce(C.currentPermitTotal, 0) + coalesce(D.currentPermitTotal, 0) +
262+
coalesce(E.currentPermitTotal, 0) + coalesce(L.currentPermitTotal, 0)+ coalesce(N.currentPermitTotal, 0)
260263
) as TotalNoofPermits,
261264
(
262-
coalesce(F.no_of_spaces, 0) + coalesce(G.no_of_spaces, 0) + coalesce(H.no_of_spaces, 0) + coalesce(I.no_of_spaces, 0) + coalesce(J.no_of_spaces, 0) + coalesce(K.no_of_spaces, 0) + coalesce(M.no_of_spaces, 0)
265+
coalesce(F.no_of_spaces, 0) + coalesce(G.no_of_spaces, 0) + coalesce(H.no_of_spaces, 0) +
266+
coalesce(I.no_of_spaces, 0) + coalesce(J.no_of_spaces, 0) + coalesce(K.no_of_spaces, 0) + coalesce(M.no_of_spaces, 0)
263267
) as TotalNoOfSpaces
264268
FROM CPZ_List_DeDupe as A
265269
LEFT JOIN Permits_summ as B ON A.cpz = B.cpz
@@ -274,6 +278,12 @@
274278
LEFT JOIN Permits_summ as E ON A.cpz = E.cpz
275279
AND lower(A.Street) = lower(E.Street)
276280
AND E.permit_type = 'Companion Badge'
281+
282+
/*** 11/02/2025 add the 'other' permits***/
283+
LEFT JOIN Permits_summ as N ON A.cpz = N.cpz
284+
AND lower(A.Street) = lower(N.Street) AND
285+
N.permit_type IN ('All Zone','Dispensation','Health and Social Care',
286+
'Leisure centre permit','Community Support Permit')
277287
/*****/
278288
LEFT JOIN Parkmap_Summary as F ON A.cpz = F.zone
279289
AND lower(A.Street) = lower(F.street_name)
@@ -316,6 +326,7 @@
316326
FROM Output
317327
WHERE length(trim(cpz)) != 0
318328
AND length(trim(Street)) != 0
329+
;
319330
"""
320331

321332
create_update_table_with_partition(

0 commit comments

Comments
 (0)