diff --git a/scripts/jobs/parking/parking_disputes_kpi_gds_summary.py b/scripts/jobs/parking/parking_disputes_kpi_gds_summary.py deleted file mode 100644 index dab348a1a..000000000 --- a/scripts/jobs/parking/parking_disputes_kpi_gds_summary.py +++ /dev/null @@ -1,146 +0,0 @@ -import sys -from awsglue.transforms import * -from awsglue.utils import getResolvedOptions -from pyspark.context import SparkContext -from awsglue.context import GlueContext -from awsglue.job import Job -from awsglue import DynamicFrame -from scripts.helpers.helpers import get_glue_env_var, get_latest_partitions, PARTITION_KEYS - -def sparkSqlQuery(glueContext, query, mapping, transformation_ctx) -> DynamicFrame: - for alias, frame in mapping.items(): - frame.toDF().createOrReplaceTempView(alias) - result = spark.sql(query) - return DynamicFrame.fromDF(result, glueContext, transformation_ctx) - - -args = getResolvedOptions(sys.argv, ["JOB_NAME"]) -sc = SparkContext() -glueContext = GlueContext(sc) -spark = glueContext.spark_session -job = Job(glueContext) -job.init(args["JOB_NAME"], args) -environment = get_glue_env_var("environment") - - -# Script generated for node Amazon S3 - pcnfoidetails_pcn_foi_full -AmazonS3pcnfoidetails_pcn_foi_full_node1630000386155 = ( - glueContext.create_dynamic_frame.from_catalog( - database="dataplatform-"+environment+"-liberator-refined-zone", - table_name="pcnfoidetails_pcn_foi_full", - transformation_ctx="AmazonS3pcnfoidetails_pcn_foi_full_node1630000386155", - ) -) - -# Script generated for node Amazon S3 - Liberator_pcn_ic -AmazonS3Liberator_pcn_ic_node1628839657576 = ( - glueContext.create_dynamic_frame.from_catalog( - database="dataplatform-"+environment+"-liberator-raw-zone", - table_name="liberator_pcn_ic", - transformation_ctx="AmazonS3Liberator_pcn_ic_node1628839657576", - ) -) - -# Script generated for node ApplyMapping -SqlQuery0 = """ - - - -/************************************************************************************************************** -PCNs FOI with Disputes - -Number Summary Disputes to parking PCNs for GDS - -12/08/2021 - create the query for correspondence reps and appeals -26/08/2021 - updated for disputes -15/09/2021 - created updated version - -****************************************************************************************************************/ -WITH pcnfoi as ( -select -cast(concat(substr(Cast(pcnissuedate as varchar(10)),1, 7), '-01')as date) AS IssueMonthYear - ,pcn -,pcnissuedate -,pcnissuedate + interval '3' month as kpi_reporting_date -,cast(concat(Cast(extract(year from pcnfoidetails_pcn_foi_full.pcnissuedate + interval '3' month) as varchar(4)),'-',cast(extract(month from pcnfoidetails_pcn_foi_full.pcnissuedate + interval '3' month)as varchar(2)), '-01') as Date) AS kpi_MonthYear - -,(Case - When (zone like 'Estates' or street_location like '%Estate%' OR usrn like 'Z%') and (isvda = 0) and (isvoid = 0) and (warningflag = 0) Then 'Flag_kpi_Estates' - When (debttype like 'CCTV%') and (isvda = 0) and (isvoid = 0) and (warningflag = 0) Then 'Flag_kpi_CCTV' - When (zone like 'Car Parks') and (isvda = 0) and (isvoid = 0) and (warningflag = 0) Then 'Flag_kpi_Car_Parks' - When (debttype not like 'CCTV%' or (zone not like 'Estates' or street_location not like '%Estate%' OR usrn not like 'Z%') or zone not like 'Car Parks') and (isvda = 0) and (isvoid = 0) and (warningflag = 0) Then 'Flag_kpi_onstreet' - Else '0' End) as pcn_type -,(Case - When (zone like 'Estates' or street_location like '%Estate%' OR usrn like 'Z%') and (isvda = 0) and (isvoid = 0) and (warningflag = 0) Then 'Estates' - When (debttype like 'CCTV%') and (isvda = 0) and (isvoid = 0) and (warningflag = 0) Then 'CCTV' - When (zone like 'Car Parks') and (isvda = 0) and (isvoid = 0) and (warningflag = 0) Then 'Car_Parks' - When (debttype not like 'CCTV%' or (zone not like 'Estates' or street_location not like '%Estate%' OR usrn not like 'Z%') or zone not like 'Car Parks') and (isvda = 0) and (isvoid = 0) and (warningflag = 0) Then 'OnStreet' - Else '0' End) as pcn_type_name - - -FROM pcnfoidetails_pcn_foi_full -WHERE import_date = (SELECT max(import_date) from pcnfoidetails_pcn_foi_full) -and pcnissuedate > current_date - interval '36' month --CAST(EVENT_TRIGGERED_DATE AS DATE) -and warningflag = 0 and isvda = 0 and isvoid = 0 - -order by concat(substr(Cast(pcnissuedate as varchar(10)),1, 7), '-01') desc -), -Disputes as ( -SELECT distinct - liberator_pcn_ic.ticketserialnumber, - -- liberator_pcn_ic.Serviceable, - cast(substr(liberator_pcn_ic.date_received, 1, 10) as date) as date_received, - cast(substr(liberator_pcn_ic.response_generated_at, 1, 10) as date) as response_generated_at, - cast(concat(substr(Cast(liberator_pcn_ic.date_received as varchar(10)),1, 7), '-01') as date) as MonthYear, - datediff( cast(substr(liberator_pcn_ic.response_generated_at, 1, 10) as date), cast(substr(liberator_pcn_ic.date_received, 1, 10) as date) ) as ResponseDays, - import_date - -from liberator_pcn_ic - -where liberator_pcn_ic.import_date = (Select MAX(liberator_pcn_ic.import_date) from liberator_pcn_ic) -AND liberator_pcn_ic.date_received != '' AND liberator_pcn_ic.response_generated_at != '' -AND length(liberator_pcn_ic.ticketserialnumber) = 10 -AND liberator_pcn_ic.Serviceable IN ('Challenges','Key worker','Removals','TOL','Charge certificate','Representations') - ) - -select issuemonthyear,kpi_MonthYear, pcn_type, pcn_type_name -, count (*) as TotalPCN_records, count(distinct pcn) as TotalPCNs, count(distinct ticketserialnumber) as TotalpcnDisputed, count(ticketserialnumber) as TotalDisputed -/*** Control Dates ***/ - ,substr(Cast(current_date as varchar(10)),1, 4) as import_year, - substr(Cast(current_date as varchar(10)),6, 2) as import_month, - substr(Cast(current_date as varchar(10)),9, 4) as import_day, - Cast(current_date as varchar(10)) as import_date - -from pcnfoi -left join disputes on disputes.ticketserialnumber = pcnfoi.pcn - -group by issuemonthyear, kpi_MonthYear, pcn_type, pcn_type_name -order by issuemonthyear desc - -""" -ApplyMapping_node2 = sparkSqlQuery( - glueContext, - query=SqlQuery0, - mapping={ - "liberator_pcn_ic": AmazonS3Liberator_pcn_ic_node1628839657576, - "pcnfoidetails_pcn_foi_full": AmazonS3pcnfoidetails_pcn_foi_full_node1630000386155, - }, - transformation_ctx="ApplyMapping_node2", -) - -# Script generated for node S3 bucket -S3bucket_node3 = glueContext.getSink( - path="s3://dataplatform-"+environment+"-refined-zone/parking/liberator/parking_Disputes_KPI_GDS_Summary/", - connection_type="s3", - updateBehavior="UPDATE_IN_DATABASE", - partitionKeys=["import_year", "import_month", "import_day", "import_date"], - enableUpdateCatalog=True, - transformation_ctx="S3bucket_node3", -) -S3bucket_node3.setCatalogInfo( - catalogDatabase="dataplatform-"+environment+"-liberator-refined-zone", - catalogTableName="parking_Disputes_kpi_gds_summary", -) -S3bucket_node3.setFormat("glueparquet") -S3bucket_node3.writeFrame(ApplyMapping_node2) -job.commit() diff --git a/scripts/jobs/parking/parking_eta_decision_records_pcn_dispute_gds.py b/scripts/jobs/parking/parking_eta_decision_records_pcn_dispute_gds.py index 17e468174..2d3a6a7fd 100644 --- a/scripts/jobs/parking/parking_eta_decision_records_pcn_dispute_gds.py +++ b/scripts/jobs/parking/parking_eta_decision_records_pcn_dispute_gds.py @@ -1,538 +1,1859 @@ -import sys -from awsglue.transforms import * -from awsglue.utils import getResolvedOptions -from pyspark.context import SparkContext -from awsglue.context import GlueContext -from awsglue.job import Job -from awsglue import DynamicFrame -from scripts.helpers.helpers import ( - get_glue_env_var, - get_latest_partitions, - create_pushdown_predicate, - PARTITION_KEYS, -) - -def sparkSqlQuery(glueContext, query, mapping, transformation_ctx) -> DynamicFrame: - for alias, frame in mapping.items(): - frame.toDF().createOrReplaceTempView(alias) - result = spark.sql(query) - return DynamicFrame.fromDF(result, glueContext, transformation_ctx) +""" +Only need to change the table name and the query prototyped on the Athena UI +by replacing table_name and query_on_athena +Note: python file name should be the same as the table name +""" +from scripts.helpers.athena_helpers import create_update_table_with_partition +from scripts.helpers.helpers import get_glue_env_var -args = getResolvedOptions(sys.argv, ["JOB_NAME"]) -sc = SparkContext() -glueContext = GlueContext(sc) -spark = glueContext.spark_session -job = Job(glueContext) -job.init(args["JOB_NAME"], args) environment = get_glue_env_var("environment") -# Script generated for node Amazon S3 - Liberator_pcn_ic -AmazonS3Liberator_pcn_ic_node1631812698045 = ( - glueContext.create_dynamic_frame.from_catalog( - database="dataplatform-"+environment+"-liberator-raw-zone", - table_name="liberator_pcn_ic", - transformation_ctx="AmazonS3Liberator_pcn_ic_node1631812698045", - push_down_predicate=create_pushdown_predicate("import_date", 7), - ) -) - -# Script generated for node S3 bucket - pcnfoidetails_pcn_foi_full -S3bucketpcnfoidetails_pcn_foi_full_node1 = ( - glueContext.create_dynamic_frame.from_catalog( - database="dataplatform-"+environment+"-liberator-refined-zone", - table_name="pcnfoidetails_pcn_foi_full", - transformation_ctx="S3bucketpcnfoidetails_pcn_foi_full_node1", - push_down_predicate=create_pushdown_predicate("import_date", 7), - ) -) - -# Script generated for node Amazon S3 - liberator_pcn_tickets -AmazonS3liberator_pcn_tickets_node1637153316033 = ( - glueContext.create_dynamic_frame.from_catalog( - database="dataplatform-"+environment+"-liberator-raw-zone", - table_name="liberator_pcn_tickets", - transformation_ctx="AmazonS3liberator_pcn_tickets_node1637153316033", - push_down_predicate=create_pushdown_predicate("import_date", 7), - ) -) - -# Script generated for node Amazon S3 - parking-raw-zone - parking_eta_decision_records -AmazonS3parkingrawzoneparking_eta_decision_records_node1645806323578 = glueContext.create_dynamic_frame.from_catalog( - database="parking-raw-zone", - table_name="parking_eta_decision_records", - transformation_ctx="AmazonS3parkingrawzoneparking_eta_decision_records_node1645806323578", - push_down_predicate=create_pushdown_predicate("import_date", 7), -) +# The target table in liberator refined zone +table_name = "parking_eta_decision_records_pcn_dispute_gds" -# Script generated for node ApplyMapping -SqlQuery0 = """ +# The exact same query prototyped in pre-prod(stg) or prod Athena +query_on_athena = """ +--> "dataplatform-prod-liberator-refined-zone"."parking_eta_decision_records_pcn_dispute_gds" +--< Orchestration depends upon "dataplatform-prod-liberator-refined-zone"."pcnfoidetails_pcn_foi_full" +--< Note "import_date" is unsynchronized across all source tables so may be misaligned if unchecked by orchestration. /*23/03/2022 - created feed -07/04/2022 - added field for pcn stacking/grouping if pcn disputed/eta or not - added flage for HQ records as 'HQ_SiDEM_PCN' - updated join to match pcns with end special chars -*/ - -With er as ( -SELECT case_reference, name ,pcn as er_pcn ,hearing_type ,case_status ,decision_i_e_dnc_appeal_allowed_appeal_rejected ,review_flag ,reporting_period ,month_year ,import_datetime as er_import_datetime ,import_timestamp as er_import_timestamp ,import_year as er_import_year ,import_month as er_import_month ,import_day as er_import_day ,import_date as er_import_date FROM eta_decision_records -where import_date = (SELECT max(import_date) FROM eta_decision_records ) -) -,eta_recs as ( -select pcn as etar_pcn--, Case when decision_i_e_dnc_appeal_allowed_appeal_rejected in ('Appeal Rejected','Appeal Refused') then 'REJECTED' when decision_i_e_dnc_appeal_allowed_appeal_rejected in ('Appeal Allowed','appeal Allowed') then 'ALLOWED' when decision_i_e_dnc_appeal_allowed_appeal_rejected in ('DNC','dnc') then 'DNC' when decision_i_e_dnc_appeal_allowed_appeal_rejected in ('Appeal with Direction','Direction') then 'DIRECTION' else upper(decision_i_e_dnc_appeal_allowed_appeal_rejected) end as etar_decision - -,sum(Case when decision_i_e_dnc_appeal_allowed_appeal_rejected in ('Appeal Rejected','Appeal Refused') then 1 else 0 end) as appeal_rejected -,sum(Case when decision_i_e_dnc_appeal_allowed_appeal_rejected in ('Appeal Allowed','appeal Allowed') then 1 else 0 end) as appeal_allowed -,sum(Case when decision_i_e_dnc_appeal_allowed_appeal_rejected in ('DNC','dnc') then 1 else 0 end) as appeal_dnc -,sum(Case when decision_i_e_dnc_appeal_allowed_appeal_rejected in ('Appeal with Direction','Direction') then 1 else 0 end) as appeal_with_direction - -FROM eta_decision_records where eta_decision_records.import_date =(select max(eta_decision_records.import_date) FROM eta_decision_records) -group by pcn , Case when decision_i_e_dnc_appeal_allowed_appeal_rejected in ('Appeal Rejected','Appeal Refused') then 'REJECTED' when decision_i_e_dnc_appeal_allowed_appeal_rejected in ('Appeal Allowed','appeal Allowed') then 'ALLOWED' when decision_i_e_dnc_appeal_allowed_appeal_rejected in ('DNC','dnc') then 'DNC' when decision_i_e_dnc_appeal_allowed_appeal_rejected in ('Appeal with Direction','Direction') then 'DIRECTION' else upper(decision_i_e_dnc_appeal_allowed_appeal_rejected) end order by pcn -) -,Disputes as ( -SELECT distinct - liberator_pcn_ic.ticketserialnumber - ,count(distinct ticketserialnumber) as TotalpcnDisputed -,count(ticketserialnumber) as TotalDisputed -/*-- liberator_pcn_ic.Serviceable, - cast(substr(liberator_pcn_ic.date_received, 1, 10) as date) as date_received, - cast(substr(liberator_pcn_ic.response_generated_at, 1, 10) as date) as response_generated_at, - concat(substr(Cast(liberator_pcn_ic.date_received as varchar(10)),1, 7), '-01') as MonthYear, - concat(substr(Cast(liberator_pcn_ic.response_generated_at as varchar(10)),1, 7), '-01') as response_MonthYear, - date_diff('day', cast(substr(liberator_pcn_ic.date_received, 1, 10) as date), cast(substr(liberator_pcn_ic.response_generated_at, 1, 10) as date)) as ResponseDays*/ - , import_date as dispute_import_date - -from liberator_pcn_ic - -where liberator_pcn_ic.import_Date = (Select MAX(liberator_pcn_ic.import_date) from liberator_pcn_ic) -AND liberator_pcn_ic.date_received != '' AND liberator_pcn_ic.response_generated_at != '' -AND length(liberator_pcn_ic.ticketserialnumber) = 10 -AND liberator_pcn_ic.Serviceable IN ('Challenges','Key worker','Removals','TOL','Charge certificate','Representations') -group by liberator_pcn_ic.ticketserialnumber, import_date - + 07/04/2022 - added field for pcn stacking/grouping if pcn disputed/eta or not - added flags for HQ records as 'HQ_SiDEM_PCN' - updated join to match pcns with end special chars + */ +WITH er AS ( + SELECT case_reference, + name, + pcn AS er_pcn, + hearing_type, + case_status, + decision_i_e_dnc_appeal_allowed_appeal_rejected, + review_flag, + reporting_period, + month_year, + import_datetime AS er_import_datetime, + import_timestamp AS er_import_timestamp, + import_year AS er_import_year, + import_month AS er_import_month, + import_day AS er_import_day, + import_date AS er_import_date + FROM "parking-raw-zone"."parking_eta_decision_records" -- in place of "eta_decision_records" + WHERE import_date = ( + SELECT MAX(import_date) + FROM "parking-raw-zone"."parking_eta_decision_records" -- in place of "eta_decision_records" + ) +), +eta_recs AS ( + SELECT pcn AS etar_pcn, + SUM( + CASE + WHEN decision_i_e_dnc_appeal_allowed_appeal_rejected IN ('Appeal Rejected', 'Appeal Refused') THEN 1 + ELSE 0 + END + ) AS appeal_rejected, + SUM( + CASE + WHEN decision_i_e_dnc_appeal_allowed_appeal_rejected IN ('Appeal Allowed', 'appeal Allowed') THEN 1 + ELSE 0 + END + ) AS appeal_allowed, + SUM( + CASE + WHEN decision_i_e_dnc_appeal_allowed_appeal_rejected IN ('DNC', 'dnc') THEN 1 + ELSE 0 + END + ) AS appeal_dnc, + SUM( + CASE + WHEN decision_i_e_dnc_appeal_allowed_appeal_rejected IN ('Appeal with Direction', 'Direction') THEN 1 + ELSE 0 + END + ) AS appeal_with_direction + FROM "parking-raw-zone"."parking_eta_decision_records" -- in place of "eta_decision_records" + WHERE import_date = ( + SELECT MAX(import_date) + FROM "parking-raw-zone"."parking_eta_decision_records" -- in place of "eta_decision_records" + ) + GROUP BY pcn +), +Disputes AS ( + SELECT ticketserialnumber, + COUNT(DISTINCT ticketserialnumber) AS TotalpcnDisputed, + COUNT(ticketserialnumber) AS TotalDisputed, + /*-- liberator_pcn_ic.Serviceable, + cast(substr(liberator_pcn_ic.date_received, 1, 10) as date) as date_received, + cast(substr(liberator_pcn_ic.response_generated_at, 1, 10) as date) as response_generated_at, + concat(substr(Cast(liberator_pcn_ic.date_received as varchar(10)),1, 7), '-01') as MonthYear, + concat(substr(Cast(liberator_pcn_ic.response_generated_at as varchar(10)),1, 7), '-01') as response_MonthYear, + date_diff('day', cast(substr(liberator_pcn_ic.date_received, 1, 10) as date), cast(substr(liberator_pcn_ic.response_generated_at, 1, 10) as date)) as ResponseDays + */ + import_date AS dispute_import_date + FROM "dataplatform-prod-liberator-raw-zone"."liberator_pcn_ic" + WHERE import_date = ( + SELECT MAX(import_date) + FROM "dataplatform-prod-liberator-raw-zone"."liberator_pcn_ic" + ) + AND date_received != '' + AND response_generated_at != '' + AND LENGTH(ticketserialnumber) = 10 + AND Serviceable IN ( + 'Challenges', + 'Key worker', + 'Removals', + 'TOL', + 'Charge certificate', + 'Representations' + ) + GROUP BY ticketserialnumber, + import_date +), +pcn AS ( + SELECT * + FROM "dataplatform-prod-liberator-refined-zone"."pcnfoidetails_pcn_foi_full" + WHERE import_date = ( + SELECT MAX(import_date) + FROM "dataplatform-prod-liberator-refined-zone"."pcnfoidetails_pcn_foi_full" + ) +), +transform AS ( + SELECT DISTINCT CASE + WHEN ZONE LIKE 'Estates' THEN usrn + WHEN UPPER(SUBSTR(er.er_pcn, 1, 2)) = 'HQ' THEN 'HQ_SiDEM_PCN' + ELSE ZONE + END AS r_zone, + CASE + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND ZONE NOT LIKE 'Car Parks' THEN 'onstreet' + WHEN ( + (ZONE LIKE 'Estates') + OR (street_location LIKE '%Estate%') + OR (usrn LIKE 'Z%') + ) THEN 'Estates' + WHEN debttype LIKE 'CCTV%' THEN 'CCTV' + WHEN ZONE LIKE 'Car Parks' THEN 'Car Parks' + WHEN UPPER(SUBSTR(er.er_pcn, 1, 2)) = 'HQ' THEN 'HQ_SiDEM_PCN' + ELSE debttype + END AS pcn_type, + /* LTN Camera/location list as of 15/03/2022 - https://docs.google.com/spreadsheets/d/12_QqvToXPAMMLRMUQpQtwJg9gRZR0vMs_LQghhdwiYw*/ + CASE + WHEN street_location = 'Allen Road' THEN 'YB1052 - Allen Road' + WHEN street_location = 'Ashenden Road junction of Glyn Road' THEN 'LW2205 - Ashenden Road' + WHEN street_location = 'Barnabas Road JCT Berger Road' THEN 'LW2204 - Barnabas Road' + WHEN street_location = 'Barnabas Road JCT Oriel Road' THEN 'LW2204 - Barnabas Road' + WHEN street_location = 'Benthal Road' THEN 'LW2206 - Benthal Road' + WHEN street_location = 'Bouverie Road junction of Stoke Newington Church Street' THEN 'LW2593 - Bouverie Road' + WHEN street_location = 'Clissold Crescent' THEN 'LW2397 - Clissold Crescent' + WHEN street_location = 'Cremer Street' THEN 'LW2041 - Cremer Street' + WHEN street_location = 'Downs Road' THEN 'LW2389 - Downs Road' + WHEN street_location = 'Elsdale Street' THEN 'LW2393 - Elsdale Street' + WHEN street_location = 'Gore Road junction of Lauriston Road.' THEN 'LW2078 - Gore Road' + WHEN street_location = 'Hyde Road' THEN 'LW2208 - Hyde Road' + WHEN street_location = 'Hyde Road JCT Northport Street' THEN 'LW2208 - Hyde Road' + WHEN street_location = 'Lee Street junction of Stean Street' THEN 'LW1535 - Lee Street' + WHEN street_location = 'Loddiges Road jct Frampton Park Road' THEN 'LW1051 - Loddiges Road' + WHEN street_location = 'Lordship Road junction of Lordship Terrace' THEN 'LW2590 - Lordship Road' + WHEN street_location = 'Maury Road junction of Evering Road' THEN 'LW2390 - Maury Road' + WHEN street_location = 'Mead Place' THEN 'LW2395 - Mead Place' + WHEN street_location = 'Meeson Street junction of Kingsmead Way' THEN 'LW2079 - Meeson Street' + WHEN street_location = 'Mount Pleasant Lane' THEN 'LW2391 - Mount Pleasant Lane' + WHEN street_location = 'Nevill Road junction of Barbauld Road' THEN 'LW2595 - Nevill Road/ Barbauld Road' + WHEN street_location = 'Nevill Road junction of Osterley Road' THEN 'LW0633 - Nevill Road (Osterley Road)' + WHEN street_location = 'Neville Road junction of Osterley Road' THEN 'LW0633 - Nevill Road (Osterley Road)' + WHEN street_location = 'Oldfield Road (E)' THEN 'LW2596 - Oldfield Road' + WHEN street_location = 'Oldfield Road junction of Kynaston Road' THEN 'LW2596 - Oldfield Road' + WHEN street_location = 'Pitfield Street (F)' THEN 'LW2207 - Pitfield Street' + WHEN street_location = 'Pitfield Street JCT Hemsworth Street' THEN 'LW2207 - Pitfield Street' + WHEN street_location = 'Powell Road junction of Kenninghall Road' THEN 'LW1691 - Powell Road (Kenninghall Road)' + WHEN street_location = 'Shepherdess Walk' THEN 'LW2076 - Shepherdess Walk' + WHEN street_location = 'Shore Place' THEN 'Mobile camera car - Shore Place' + WHEN street_location = 'Stoke Newington Church Street junction of Lordship Road - Eastbound' THEN 'LW2591 - Stoke Newington Church Street eastbound' + WHEN street_location = 'Stoke Newington Church Street junction of Marton Road - Westbound' THEN 'LW2592 - Stoke Newington Church Street westbound' + WHEN street_location = 'Ufton Road junction of Downham Road' THEN 'LW2077 - Ufton Road' + WHEN street_location = 'Wayland Avenue' THEN 'LW2392 - Wayland Avenue' + WHEN street_location = 'Weymouth Terrace junction of Dunloe Street' THEN 'Mobile camera car - Weymouth Terrace' + WHEN street_location = 'Wilton Way junction of Greenwood Road' THEN 'LW1457 - Wilton Way' + WHEN street_location = 'Woodberry Grove junction of Rowley Gardens' THEN 'LW1457 - Woodberry Grove' + WHEN street_location = 'Woodberry Grove junction of Seven Sisters Road' THEN 'LW1457 - Woodberry Grove' + WHEN street_location = 'Yoakley Road junction of Stoke Newington Church Street' THEN 'LW2594 - Yoakley Road' + ELSE 'NOT current LTN Camera Location' + END AS ltn_camera_location, + CASE + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 THEN 1 + ELSE 0 + END AS kpi_pcns, + /*PCNs by Type with VDA's excluded before and included after 1st June 2021*/ + CASE + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 THEN 1 + ELSE 0 + END AS Flg_kpi_onstreet_carparks, + CASE + WHEN ( + (ZONE LIKE 'Estates') + OR (street_location LIKE '%Estate%') + OR (usrn LIKE 'Z%') + ) + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 THEN 1 + ELSE 0 + END AS Flg_kpi_Estates, + CASE + WHEN debttype LIKE 'CCTV%' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 THEN 1 + ELSE 0 + END AS Flg_kpi_CCTV, + CASE + WHEN ZONE LIKE 'Car Parks' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 THEN 1 + ELSE 0 + END AS Flg_kpi_Car_Parks, + CASE + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND ZONE NOT LIKE 'Car Parks' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 THEN 1 + ELSE 0 + END AS Flg_kpi_onstreet, + -- Disputed pcns and by pcn type + CASE + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND (isvda = 0) + AND (isvoid = 0) + AND (warningflag = 0) + AND Disputes.ticketserialnumber IS NOT NULL THEN 1 + ELSE 0 + END Flg_kpi_onstreet_carparks_disputes, + CASE + WHEN ( + (ZONE LIKE 'Estates') + OR (street_location LIKE '%Estate%') + OR (usrn LIKE 'Z%') + ) + AND (isvda = 0) + AND (isvoid = 0) + AND (warningflag = 0) + AND Disputes.ticketserialnumber IS NOT NULL THEN 1 + ELSE 0 + END Flag_kpi_Estates_disputes, + CASE + WHEN (debttype LIKE 'CCTV%') + AND (isvda = 0) + AND (isvoid = 0) + AND (warningflag = 0) + AND Disputes.ticketserialnumber IS NOT NULL THEN 1 + ELSE 0 + END AS Flag_kpi_CCTV_disputes, + CASE + WHEN (ZONE LIKE 'Car Parks') + AND (isvda = 0) + AND (isvoid = 0) + AND (warningflag = 0) + AND Disputes.ticketserialnumber IS NOT NULL THEN 1 + ELSE 0 + END AS Flag_kpi_Car_Parks_disputes, + CASE + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND ZONE NOT LIKE 'Car Parks' + AND (isvda = 0) + AND (isvoid = 0) + AND (warningflag = 0) + AND Disputes.ticketserialnumber IS NOT NULL THEN 1 + ELSE 0 + END AS Flg_kpi_onstreet_disputes, + /*onstreet_carparks ETA Decisions*/ + CASE + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_rejected > 0 THEN eta_recs.appeal_rejected + ELSE 0 + END AS Flg_decision_appeal_rejected_onstreet_carparks, + CASE + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_allowed > 0 THEN eta_recs.appeal_allowed + ELSE 0 + END AS Flg_decision_appeal_allowed_onstreet_carparks, + CASE + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_dnc > 0 THEN eta_recs.appeal_dnc + ELSE 0 + END AS Flg_decision_appeal_dnc_onstreet_carparks, + CASE + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_with_direction > 0 THEN eta_recs.appeal_with_direction + ELSE 0 + END AS Flg_decision_appeal_with_direction_onstreet_carparks, + CASE + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + eta_recs.appeal_rejected > 0 + OR eta_recs.appeal_allowed > 0 + OR eta_recs.appeal_dnc > 0 + OR eta_recs.appeal_with_direction > 0 + ) THEN ( + eta_recs.appeal_rejected + eta_recs.appeal_allowed + eta_recs.appeal_dnc + eta_recs.appeal_with_direction + ) + ELSE 0 + END AS Flg_eta_decision_onstreet_carparks, + /*Estates ETA Decisions*/ + CASE + WHEN ( + (ZONE LIKE 'Estates') + OR (street_location LIKE '%Estate%') + OR (usrn LIKE 'Z%') + ) + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_rejected > 0 THEN eta_recs.appeal_rejected + ELSE 0 + END AS Flg_decision_appeal_rejected_Estates, + CASE + WHEN ( + (ZONE LIKE 'Estates') + OR (street_location LIKE '%Estate%') + OR (usrn LIKE 'Z%') + ) + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_allowed > 0 THEN eta_recs.appeal_allowed + ELSE 0 + END AS Flg_decision_appeal_allowed_Estates, + CASE + WHEN ( + (ZONE LIKE 'Estates') + OR (street_location LIKE '%Estate%') + OR (usrn LIKE 'Z%') + ) + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_dnc > 0 THEN eta_recs.appeal_dnc + ELSE 0 + END AS Flg_decision_appeal_dnc_Estates, + CASE + WHEN ( + (ZONE LIKE 'Estates') + OR (street_location LIKE '%Estate%') + OR (usrn LIKE 'Z%') + ) + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_with_direction > 0 THEN eta_recs.appeal_with_direction + ELSE 0 + END AS Flg_decision_appeal_with_direction_Estates, + CASE + WHEN ( + (ZONE LIKE 'Estates') + OR (street_location LIKE '%Estate%') + OR (usrn LIKE 'Z%') + ) + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + eta_recs.appeal_rejected > 0 + OR eta_recs.appeal_allowed > 0 + OR eta_recs.appeal_dnc > 0 + OR eta_recs.appeal_with_direction > 0 + ) THEN ( + eta_recs.appeal_rejected + eta_recs.appeal_allowed + eta_recs.appeal_dnc + eta_recs.appeal_with_direction + ) + ELSE 0 + END AS Flg_eta_decision_Estates, + /*CCTV ETA Decisions*/ + CASE + WHEN debttype LIKE 'CCTV%' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_rejected > 0 THEN eta_recs.appeal_rejected + ELSE 0 + END AS Flg_decision_appeal_rejected_CCTV, + CASE + WHEN debttype LIKE 'CCTV%' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_allowed > 0 THEN eta_recs.appeal_allowed + ELSE 0 + END AS Flg_decision_appeal_allowed_CCTV, + CASE + WHEN debttype LIKE 'CCTV%' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_dnc > 0 THEN eta_recs.appeal_dnc + ELSE 0 + END AS Flg_decision_appeal_dnc_CCTV, + CASE + WHEN debttype LIKE 'CCTV%' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_with_direction > 0 THEN eta_recs.appeal_with_direction + ELSE 0 + END AS Flg_decision_appeal_with_direction_CCTV, + CASE + WHEN debttype LIKE 'CCTV%' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + eta_recs.appeal_rejected > 0 + OR eta_recs.appeal_allowed > 0 + OR eta_recs.appeal_dnc > 0 + OR eta_recs.appeal_with_direction > 0 + ) THEN ( + eta_recs.appeal_rejected + eta_recs.appeal_allowed + eta_recs.appeal_dnc + eta_recs.appeal_with_direction + ) + ELSE 0 + END AS Flg_eta_decision_CCTV, + /*Car_Parks ETA Decisions*/ + CASE + WHEN ZONE LIKE 'Car Parks' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_rejected > 0 THEN eta_recs.appeal_rejected + ELSE 0 + END AS Flg_decision_appeal_rejected_Car_Parks, + CASE + WHEN ZONE LIKE 'Car Parks' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_allowed > 0 THEN eta_recs.appeal_allowed + ELSE 0 + END AS Flg_decision_appeal_allowed_Car_Parks, + CASE + WHEN ZONE LIKE 'Car Parks' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_dnc > 0 THEN eta_recs.appeal_dnc + ELSE 0 + END AS Flg_decision_appeal_dnc_Car_Parks, + CASE + WHEN ZONE LIKE 'Car Parks' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_with_direction > 0 THEN eta_recs.appeal_with_direction + ELSE 0 + END AS Flg_decision_appeal_with_direction_Car_Parks, + CASE + WHEN ZONE LIKE 'Car Parks' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + eta_recs.appeal_rejected > 0 + OR eta_recs.appeal_allowed > 0 + OR eta_recs.appeal_dnc > 0 + OR eta_recs.appeal_with_direction > 0 + ) THEN ( + eta_recs.appeal_rejected + eta_recs.appeal_allowed + eta_recs.appeal_dnc + eta_recs.appeal_with_direction + ) + ELSE 0 + END AS Flg_eta_decision_Car_Parks, + /*onstreet ETA Decisions*/ + CASE + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND ZONE NOT LIKE 'Car Parks' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_rejected > 0 THEN eta_recs.appeal_rejected + ELSE 0 + END AS Flg_decision_appeal_rejected_onstreet, + CASE + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND ZONE NOT LIKE 'Car Parks' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_allowed > 0 THEN eta_recs.appeal_allowed + ELSE 0 + END AS Flg_decision_appeal_allowed_onstreet, + CASE + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND ZONE NOT LIKE 'Car Parks' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_dnc > 0 THEN eta_recs.appeal_dnc + ELSE 0 + END AS Flg_decision_appeal_dnc_onstreet, + CASE + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND ZONE NOT LIKE 'Car Parks' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_with_direction > 0 THEN eta_recs.appeal_with_direction + ELSE 0 + END AS Flg_decision_appeal_with_direction_onstreet, + CASE + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND ZONE NOT LIKE 'Car Parks' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + eta_recs.appeal_rejected > 0 + OR eta_recs.appeal_allowed > 0 + OR eta_recs.appeal_dnc > 0 + OR eta_recs.appeal_with_direction > 0 + ) THEN ( + eta_recs.appeal_rejected + eta_recs.appeal_allowed + eta_recs.appeal_dnc + eta_recs.appeal_with_direction + ) + ELSE 0 + END AS Flg_eta_decision_onstreet, + /* All kpi ETA Decisions*/ + CASE + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_rejected > 0 THEN eta_recs.appeal_rejected + ELSE 0 + END AS Flg_decision_appeal_rejected_all_kpi, + CASE + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_allowed > 0 THEN eta_recs.appeal_allowed + ELSE 0 + END AS Flg_decision_appeal_allowed_all_kpi, + CASE + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_dnc > 0 THEN eta_recs.appeal_dnc + ELSE 0 + END AS Flg_decision_appeal_dnc_all_kpi, + CASE + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_with_direction > 0 THEN eta_recs.appeal_with_direction + ELSE 0 + END AS Flg_decision_appeal_with_direction_all_kpi, + CASE + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + eta_recs.appeal_rejected > 0 + OR eta_recs.appeal_allowed > 0 + OR eta_recs.appeal_dnc > 0 + OR eta_recs.appeal_with_direction > 0 + ) THEN ( + eta_recs.appeal_rejected + eta_recs.appeal_allowed + eta_recs.appeal_dnc + eta_recs.appeal_with_direction + ) + ELSE 0 + END AS Flg_eta_decision_all_kpi, + /*PCNs catergorised not eta or disputed for stacking*/ + CASE + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + ( + eta_recs.appeal_rejected = 0 + AND eta_recs.appeal_allowed = 0 + AND eta_recs.appeal_dnc = 0 + AND eta_recs.appeal_with_direction = 0 + ) + OR ( + eta_recs.appeal_rejected IS NULL + AND eta_recs.appeal_allowed IS NULL + AND eta_recs.appeal_dnc IS NULL + AND eta_recs.appeal_with_direction IS NULL + ) + ) + AND Disputes.ticketserialnumber IS NULL THEN 'Not dispute or eta' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + ( + eta_recs.appeal_rejected = 0 + AND eta_recs.appeal_allowed = 0 + AND eta_recs.appeal_dnc = 0 + AND eta_recs.appeal_with_direction = 0 + ) + OR ( + eta_recs.appeal_rejected IS NULL + AND eta_recs.appeal_allowed IS NULL + AND eta_recs.appeal_dnc IS NULL + AND eta_recs.appeal_with_direction IS NULL + ) + ) + AND Disputes.ticketserialnumber IS NOT NULL THEN 'disputed' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_rejected = 0 + AND eta_recs.appeal_allowed = 0 + AND eta_recs.appeal_dnc = 0 + AND eta_recs.appeal_with_direction > 0 + AND Disputes.ticketserialnumber IS NULL THEN 'eta with direction' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_rejected = 0 + AND eta_recs.appeal_allowed = 0 + AND eta_recs.appeal_with_direction = 0 + AND eta_recs.appeal_dnc > 0 + AND Disputes.ticketserialnumber IS NULL THEN 'eta dnc' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_rejected = 0 + AND eta_recs.appeal_dnc = 0 + AND eta_recs.appeal_with_direction = 0 + AND eta_recs.appeal_allowed > 0 + AND Disputes.ticketserialnumber IS NULL THEN 'eta allowed' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_allowed = 0 + AND eta_recs.appeal_dnc = 0 + AND eta_recs.appeal_with_direction = 0 + AND eta_recs.appeal_rejected > 0 + AND Disputes.ticketserialnumber IS NULL THEN 'eta rejected' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_with_direction > 0 + AND Disputes.ticketserialnumber IS NOT NULL THEN 'disputed and eta with direction' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_dnc > 0 + AND Disputes.ticketserialnumber IS NOT NULL THEN 'disputed and eta dnc' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_allowed > 0 + AND Disputes.ticketserialnumber IS NOT NULL THEN 'disputed and eta allowed' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_rejected > 0 + AND Disputes.ticketserialnumber IS NOT NULL THEN 'disputed and eta rejected' + ELSE 'NOT KPI' + END AS kpi_pcn_dispute_eta_group, + CASE + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + ( + eta_recs.appeal_rejected = 0 + AND eta_recs.appeal_allowed = 0 + AND eta_recs.appeal_dnc = 0 + AND eta_recs.appeal_with_direction = 0 + ) + OR ( + eta_recs.appeal_rejected IS NULL + AND eta_recs.appeal_allowed IS NULL + AND eta_recs.appeal_dnc IS NULL + AND eta_recs.appeal_with_direction IS NULL + ) + ) + AND Disputes.ticketserialnumber IS NULL THEN 'Y' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + ( + eta_recs.appeal_rejected = 0 + AND eta_recs.appeal_allowed = 0 + AND eta_recs.appeal_dnc = 0 + AND eta_recs.appeal_with_direction = 0 + ) + OR ( + eta_recs.appeal_rejected IS NULL + AND eta_recs.appeal_allowed IS NULL + AND eta_recs.appeal_dnc IS NULL + AND eta_recs.appeal_with_direction IS NULL + ) + ) + AND Disputes.ticketserialnumber IS NOT NULL THEN 'Y' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_rejected = 0 + AND eta_recs.appeal_allowed = 0 + AND eta_recs.appeal_dnc = 0 + AND eta_recs.appeal_with_direction > 0 + AND Disputes.ticketserialnumber IS NULL THEN 'Y' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_rejected = 0 + AND eta_recs.appeal_allowed = 0 + AND eta_recs.appeal_with_direction = 0 + AND eta_recs.appeal_dnc > 0 + AND Disputes.ticketserialnumber IS NULL THEN 'Y' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_rejected = 0 + AND eta_recs.appeal_dnc = 0 + AND eta_recs.appeal_with_direction = 0 + AND eta_recs.appeal_allowed > 0 + AND Disputes.ticketserialnumber IS NULL THEN 'Y' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_allowed = 0 + AND eta_recs.appeal_dnc = 0 + AND eta_recs.appeal_with_direction = 0 + AND eta_recs.appeal_rejected > 0 + AND Disputes.ticketserialnumber IS NULL THEN 'Y' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_with_direction > 0 + AND Disputes.ticketserialnumber IS NOT NULL THEN 'Y' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_dnc > 0 + AND Disputes.ticketserialnumber IS NOT NULL THEN 'Y' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_allowed > 0 + AND Disputes.ticketserialnumber IS NOT NULL THEN 'Y' + WHEN ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND eta_recs.appeal_rejected > 0 + AND Disputes.ticketserialnumber IS NOT NULL THEN 'Y' + ELSE 'N' + END AS kpi_pcn_dispute_eta_flag, + /*PCNs not eta or disputed*/ + CASE + WHEN ( + (ZONE LIKE 'Estates') + OR (street_location LIKE '%Estate%') + OR (usrn LIKE 'Z%') + ) + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + ( + eta_recs.appeal_rejected = 0 + AND eta_recs.appeal_allowed = 0 + AND eta_recs.appeal_dnc = 0 + AND eta_recs.appeal_with_direction = 0 + ) + OR ( + eta_recs.appeal_rejected IS NULL + AND eta_recs.appeal_allowed IS NULL + AND eta_recs.appeal_dnc IS NULL + AND eta_recs.appeal_with_direction IS NULL + ) + ) + AND Disputes.ticketserialnumber IS NULL THEN 'Estates' + WHEN debttype LIKE 'CCTV%' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + ( + eta_recs.appeal_rejected = 0 + AND eta_recs.appeal_allowed = 0 + AND eta_recs.appeal_dnc = 0 + AND eta_recs.appeal_with_direction = 0 + ) + OR ( + eta_recs.appeal_rejected IS NULL + AND eta_recs.appeal_allowed IS NULL + AND eta_recs.appeal_dnc IS NULL + AND eta_recs.appeal_with_direction IS NULL + ) + ) + AND Disputes.ticketserialnumber IS NULL THEN 'CCTV' + WHEN ZONE LIKE 'Car Parks' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + ( + eta_recs.appeal_rejected = 0 + AND eta_recs.appeal_allowed = 0 + AND eta_recs.appeal_dnc = 0 + AND eta_recs.appeal_with_direction = 0 + ) + OR ( + eta_recs.appeal_rejected IS NULL + AND eta_recs.appeal_allowed IS NULL + AND eta_recs.appeal_dnc IS NULL + AND eta_recs.appeal_with_direction IS NULL + ) + ) + AND Disputes.ticketserialnumber IS NULL THEN 'Car_Parks' + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND ZONE NOT LIKE 'Car Parks' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + ( + eta_recs.appeal_rejected = 0 + AND eta_recs.appeal_allowed = 0 + AND eta_recs.appeal_dnc = 0 + AND eta_recs.appeal_with_direction = 0 + ) + OR ( + eta_recs.appeal_rejected IS NULL + AND eta_recs.appeal_allowed IS NULL + AND eta_recs.appeal_dnc IS NULL + AND eta_recs.appeal_with_direction IS NULL + ) + ) + AND Disputes.ticketserialnumber IS NULL THEN 'onstreet' + /*disputed by kpi pcn type*/ + WHEN ( + (ZONE LIKE 'Estates') + OR (street_location LIKE '%Estate%') + OR (usrn LIKE 'Z%') + ) + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + ( + eta_recs.appeal_rejected > 0 + OR eta_recs.appeal_allowed > 0 + OR eta_recs.appeal_dnc > 0 + OR eta_recs.appeal_with_direction > 0 + ) + OR (Disputes.ticketserialnumber IS NOT NULL) + ) THEN 'Estates - disputed_eta' + WHEN debttype LIKE 'CCTV%' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + ( + eta_recs.appeal_rejected > 0 + OR eta_recs.appeal_allowed > 0 + OR eta_recs.appeal_dnc > 0 + OR eta_recs.appeal_with_direction > 0 + ) + OR (Disputes.ticketserialnumber IS NOT NULL) + ) THEN 'CCTV - disputed_eta' + WHEN ZONE LIKE 'Car Parks' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + ( + eta_recs.appeal_rejected > 0 + OR eta_recs.appeal_allowed > 0 + OR eta_recs.appeal_dnc > 0 + OR eta_recs.appeal_with_direction > 0 + ) + OR (Disputes.ticketserialnumber IS NOT NULL) + ) THEN 'Car_Parks - disputed_eta' + WHEN debttype NOT LIKE 'CCTV%' + AND ZONE NOT LIKE 'Estates' + AND street_location NOT LIKE '%Estate%' + AND usrn NOT LIKE 'Z%' + AND ZONE NOT LIKE 'Car Parks' + AND ( + ( + isvda = 0 + AND CAST(pcnissuedate AS DATE) < CAST('2021-06-01' AS DATE) + ) + OR ( + CAST(pcnissuedate AS DATE) > CAST('2021-05-31' AS DATE) + ) + ) + AND isvoid = 0 + AND warningflag = 0 + AND ( + ( + eta_recs.appeal_rejected > 0 + OR eta_recs.appeal_allowed > 0 + OR eta_recs.appeal_dnc > 0 + OR eta_recs.appeal_with_direction > 0 + ) + OR (Disputes.ticketserialnumber IS NOT NULL) + ) THEN 'onstreet - disputed_eta' + ELSE 'NOT KPI' + END AS kpi_pcn_not_dispute_eta_name, + * + /*** Collect all columns from the source tables including columns we don't yet know about. ***/ + FROM er + LEFT JOIN eta_recs ON SUBSTR(eta_recs.etar_pcn, 1, 10) = SUBSTR(er.er_pcn, 1, 10) + LEFT JOIN Disputes ON Disputes.ticketserialnumber = SUBSTR(er.er_pcn, 1, 10) + LEFT JOIN pcn ON SUBSTR(er.er_pcn, 1, 10) = pcn.pcn ) -,pcn as ( -SELECT * FROM pcnfoidetails_pcn_foi_full where import_date = (SELECT max(import_date) FROM pcnfoidetails_pcn_foi_full) -) -Select distinct -(Case When zone like 'Estates' Then usrn when upper(substr(er.er_pcn, 1, 2)) ='HQ'then 'HQ_SiDEM_PCN' Else zone End) as r_zone -,Case - When debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' and zone not like 'Car Parks' then 'onstreet' - When ((zone like 'Estates') or (street_location like '%Estate%') OR (usrn like 'Z%')) then 'Estates' - When debttype like 'CCTV%' then 'CCTV' - When zone like 'Car Parks' then 'Car Parks' - when upper(substr(er.er_pcn, 1, 2)) ='HQ'then 'HQ_SiDEM_PCN' - else debttype End as pcn_type -/* LTN Camera/location list as of 15/03/2022 - https://docs.google.com/spreadsheets/d/12_QqvToXPAMMLRMUQpQtwJg9gRZR0vMs_LQghhdwiYw*/ -, (case When street_location = 'Allen Road' then 'YB1052 - Allen Road' -When street_location = 'Ashenden Road junction of Glyn Road' then 'LW2205 - Ashenden Road' -When street_location = 'Barnabas Road JCT Berger Road' then 'LW2204 - Barnabas Road' -When street_location = 'Barnabas Road JCT Oriel Road' then 'LW2204 - Barnabas Road' -When street_location = 'Benthal Road' then 'LW2206 - Benthal Road' -When street_location = 'Bouverie Road junction of Stoke Newington Church Street' then 'LW2593 - Bouverie Road' -When street_location = 'Clissold Crescent' then 'LW2397 - Clissold Crescent' -When street_location = 'Cremer Street' then 'LW2041 - Cremer Street' -When street_location = 'Downs Road' then 'LW2389 - Downs Road' -When street_location = 'Elsdale Street' then 'LW2393 - Elsdale Street' -When street_location = 'Gore Road junction of Lauriston Road.' then 'LW2078 - Gore Road' -When street_location = 'Hyde Road' then 'LW2208 - Hyde Road' -When street_location = 'Hyde Road JCT Northport Street' then 'LW2208 - Hyde Road' -When street_location = 'Lee Street junction of Stean Street' then 'LW1535 - Lee Street' -When street_location = 'Loddiges Road jct Frampton Park Road' then 'LW1051 - Loddiges Road' -When street_location = 'Lordship Road junction of Lordship Terrace' then 'LW2590 - Lordship Road' -When street_location = 'Maury Road junction of Evering Road' then 'LW2390 - Maury Road' -When street_location = 'Mead Place' then 'LW2395 - Mead Place' -When street_location = 'Meeson Street junction of Kingsmead Way' then 'LW2079 - Meeson Street' -When street_location = 'Mount Pleasant Lane' then 'LW2391 - Mount Pleasant Lane' -When street_location = 'Nevill Road junction of Barbauld Road' then 'LW2595 - Nevill Road/ Barbauld Road' -When street_location = 'Nevill Road junction of Osterley Road' then 'LW0633 - Nevill Road (Osterley Road)' -When street_location = 'Neville Road junction of Osterley Road' then 'LW0633 - Nevill Road (Osterley Road)' -When street_location = 'Oldfield Road (E)' then 'LW2596 - Oldfield Road' -When street_location = 'Oldfield Road junction of Kynaston Road' then 'LW2596 - Oldfield Road' -When street_location = 'Pitfield Street (F)' then 'LW2207 - Pitfield Street' -When street_location = 'Pitfield Street JCT Hemsworth Street' then 'LW2207 - Pitfield Street' -When street_location = 'Powell Road junction of Kenninghall Road' then 'LW1691 - Powell Road (Kenninghall Road)' -When street_location = 'Shepherdess Walk' then 'LW2076 - Shepherdess Walk' -When street_location = 'Shore Place' then 'Mobile camera car - Shore Place' -When street_location = 'Stoke Newington Church Street junction of Lordship Road - Eastbound' then 'LW2591 - Stoke Newington Church Street eastbound' -When street_location = 'Stoke Newington Church Street junction of Marton Road - Westbound' then 'LW2592 - Stoke Newington Church Street westbound' -When street_location = 'Ufton Road junction of Downham Road' then 'LW2077 - Ufton Road' -When street_location = 'Wayland Avenue' then 'LW2392 - Wayland Avenue' -When street_location = 'Weymouth Terrace junction of Dunloe Street' then 'Mobile camera car - Weymouth Terrace' -When street_location = 'Wilton Way junction of Greenwood Road' then 'LW1457 - Wilton Way' -When street_location = 'Woodberry Grove junction of Rowley Gardens' then 'LW1457 - Woodberry Grove' -When street_location = 'Woodberry Grove junction of Seven Sisters Road' then 'LW1457 - Woodberry Grove' -When street_location = 'Yoakley Road junction of Stoke Newington Church Street' then 'LW2594 - Yoakley Road' else 'NOT current LTN Camera Location' end) as ltn_camera_location - -,case when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 then 1 else 0 end as kpi_pcns - -/*PCNs by Type with VDA's excluded before and included after 1st June 2021*/ - -,Case - When - debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - Then 1 Else 0 End as Flg_kpi_onstreet_carparks - -,Case - When - ((zone like 'Estates') or (street_location like '%Estate%') OR (usrn like 'Z%')) - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - Then 1 Else 0 End as Flg_kpi_Estates - -,Case - When - debttype like 'CCTV%' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - Then 1 Else 0 End as Flg_kpi_CCTV - -,Case - When - zone like 'Car Parks' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - Then 1 Else 0 End as Flg_kpi_Car_Parks - -,Case - When - debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' and zone not like 'Car Parks' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - Then 1 Else 0 End as Flg_kpi_onstreet - --- Disputed pcns and by pcn type -,Case When debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' and (isvda = 0) and (isvoid = 0) and (warningflag = 0) and Disputes.ticketserialnumber is not null Then 1 else 0 End Flg_kpi_onstreet_carparks_disputes -,Case When ((zone like 'Estates') or (street_location like '%Estate%') OR (usrn like 'Z%')) and (isvda = 0) and (isvoid = 0) and (warningflag = 0) and Disputes.ticketserialnumber is not null Then 1 else 0 End Flag_kpi_Estates_disputes -,Case When (debttype like 'CCTV%') and (isvda = 0) and (isvoid = 0) and (warningflag = 0) and Disputes.ticketserialnumber is not null Then 1 else 0 End as Flag_kpi_CCTV_disputes -,Case When (zone like 'Car Parks') and (isvda = 0) and (isvoid = 0) and (warningflag = 0) and Disputes.ticketserialnumber is not null Then 1 else 0 End as Flag_kpi_Car_Parks_disputes -,Case When debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' and zone not like 'Car Parks' and (isvda = 0) and (isvoid = 0) and (warningflag = 0) and Disputes.ticketserialnumber is not null Then 1 else 0 End as Flg_kpi_onstreet_disputes - -/*onstreet_carparks ETA Decisions*/ -,Case - When - debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_rejected > 0 - Then eta_recs.appeal_rejected Else 0 End as Flg_decision_appeal_rejected_onstreet_carparks -,Case - When - debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_allowed > 0 - Then eta_recs.appeal_allowed Else 0 End as Flg_decision_appeal_allowed_onstreet_carparks -,Case - When - debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_dnc > 0 - Then eta_recs.appeal_dnc Else 0 End as Flg_decision_appeal_dnc_onstreet_carparks -,Case - When - debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_with_direction > 0 - Then eta_recs.appeal_with_direction Else 0 End as Flg_decision_appeal_with_direction_onstreet_carparks -,Case - When - debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and (eta_recs.appeal_rejected > 0 or eta_recs.appeal_allowed > 0 or eta_recs.appeal_dnc > 0 or eta_recs.appeal_with_direction > 0) - Then (eta_recs.appeal_rejected + eta_recs.appeal_allowed + eta_recs.appeal_dnc + eta_recs.appeal_with_direction ) Else 0 End as Flg_eta_decision_onstreet_carparks - -/*Estates ETA Decisions*/ -,Case - When - ((zone like 'Estates') or (street_location like '%Estate%') OR (usrn like 'Z%')) - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_rejected > 0 - Then eta_recs.appeal_rejected Else 0 End as Flg_decision_appeal_rejected_Estates -,Case - When - ((zone like 'Estates') or (street_location like '%Estate%') OR (usrn like 'Z%')) - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_allowed > 0 - Then eta_recs.appeal_allowed Else 0 End as Flg_decision_appeal_allowed_Estates -,Case - When - ((zone like 'Estates') or (street_location like '%Estate%') OR (usrn like 'Z%')) - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_dnc > 0 - Then eta_recs.appeal_dnc Else 0 End as Flg_decision_appeal_dnc_Estates -,Case - When - ((zone like 'Estates') or (street_location like '%Estate%') OR (usrn like 'Z%')) - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_with_direction > 0 - Then eta_recs.appeal_with_direction Else 0 End as Flg_decision_appeal_with_direction_Estates -,Case - When - ((zone like 'Estates') or (street_location like '%Estate%') OR (usrn like 'Z%')) - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and (eta_recs.appeal_rejected > 0 or eta_recs.appeal_allowed > 0 or eta_recs.appeal_dnc > 0 or eta_recs.appeal_with_direction > 0) - Then (eta_recs.appeal_rejected + eta_recs.appeal_allowed + eta_recs.appeal_dnc + eta_recs.appeal_with_direction ) Else 0 End as Flg_eta_decision_Estates - - -/*CCTV ETA Decisions*/ -,Case - When - debttype like 'CCTV%' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_rejected > 0 - Then eta_recs.appeal_rejected Else 0 End as Flg_decision_appeal_rejected_CCTV -,Case - When - debttype like 'CCTV%' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_allowed > 0 - Then eta_recs.appeal_allowed Else 0 End as Flg_decision_appeal_allowed_CCTV -,Case - When - debttype like 'CCTV%' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_dnc > 0 - Then eta_recs.appeal_dnc Else 0 End as Flg_decision_appeal_dnc_CCTV -,Case - When - debttype like 'CCTV%' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_with_direction > 0 - Then eta_recs.appeal_with_direction Else 0 End as Flg_decision_appeal_with_direction_CCTV -,Case - When - debttype like 'CCTV%' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and (eta_recs.appeal_rejected > 0 or eta_recs.appeal_allowed > 0 or eta_recs.appeal_dnc > 0 or eta_recs.appeal_with_direction > 0) - Then (eta_recs.appeal_rejected + eta_recs.appeal_allowed + eta_recs.appeal_dnc + eta_recs.appeal_with_direction ) Else 0 End as Flg_eta_decision_CCTV - -/*Car_Parks ETA Decisions*/ -,Case - When - zone like 'Car Parks' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_rejected > 0 - Then eta_recs.appeal_rejected Else 0 End as Flg_decision_appeal_rejected_Car_Parks -,Case - When - zone like 'Car Parks' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_allowed > 0 - Then eta_recs.appeal_allowed Else 0 End as Flg_decision_appeal_allowed_Car_Parks -,Case - When - zone like 'Car Parks' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_dnc > 0 - Then eta_recs.appeal_dnc Else 0 End as Flg_decision_appeal_dnc_Car_Parks -,Case - When - zone like 'Car Parks' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_with_direction > 0 - Then eta_recs.appeal_with_direction Else 0 End as Flg_decision_appeal_with_direction_Car_Parks -,Case - When - zone like 'Car Parks' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and (eta_recs.appeal_rejected > 0 or eta_recs.appeal_allowed > 0 or eta_recs.appeal_dnc > 0 or eta_recs.appeal_with_direction > 0) - Then (eta_recs.appeal_rejected + eta_recs.appeal_allowed + eta_recs.appeal_dnc + eta_recs.appeal_with_direction ) Else 0 End as Flg_eta_decision_Car_Parks - - -/*onstreet ETA Decisions*/ -,Case - When - debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' and zone not like 'Car Parks' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_rejected > 0 - Then eta_recs.appeal_rejected Else 0 End as Flg_decision_appeal_rejected_onstreet -,Case - When - debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' and zone not like 'Car Parks' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_allowed > 0 - Then eta_recs.appeal_allowed Else 0 End as Flg_decision_appeal_allowed_onstreet -,Case - When - debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' and zone not like 'Car Parks' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_dnc > 0 - Then eta_recs.appeal_dnc Else 0 End as Flg_decision_appeal_dnc_onstreet -,Case - When - debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' and zone not like 'Car Parks' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_with_direction > 0 - Then eta_recs.appeal_with_direction Else 0 End as Flg_decision_appeal_with_direction_onstreet -,Case - When - debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' and zone not like 'Car Parks' - and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and (eta_recs.appeal_rejected > 0 or eta_recs.appeal_allowed > 0 or eta_recs.appeal_dnc > 0 or eta_recs.appeal_with_direction > 0) - Then (eta_recs.appeal_rejected + eta_recs.appeal_allowed + eta_recs.appeal_dnc + eta_recs.appeal_with_direction ) Else 0 End as Flg_eta_decision_onstreet - -/* All kpi ETA Decisions*/ -,Case - When - ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_rejected > 0 - Then eta_recs.appeal_rejected Else 0 End as Flg_decision_appeal_rejected_all_kpi -,Case - When - ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_allowed > 0 - Then eta_recs.appeal_allowed Else 0 End as Flg_decision_appeal_allowed_all_kpi -,Case - When - ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_dnc > 0 - Then eta_recs.appeal_dnc Else 0 End as Flg_decision_appeal_dnc_all_kpi -,Case - When - ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and eta_recs.appeal_with_direction > 0 - Then eta_recs.appeal_with_direction Else 0 End as Flg_decision_appeal_with_direction_all_kpi -,Case - When - ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - and isvoid = 0 - and warningflag = 0 - and (eta_recs.appeal_rejected > 0 or eta_recs.appeal_allowed > 0 or eta_recs.appeal_dnc > 0 or eta_recs.appeal_with_direction > 0) - Then (eta_recs.appeal_rejected + eta_recs.appeal_allowed + eta_recs.appeal_dnc + eta_recs.appeal_with_direction ) Else 0 End as Flg_eta_decision_all_kpi - -/*PCNs catergorised not eta or disputed for stacking*/ -,case -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and ((eta_recs.appeal_rejected = 0 and eta_recs.appeal_allowed = 0 and eta_recs.appeal_dnc = 0 and eta_recs.appeal_with_direction = 0) or (eta_recs.appeal_rejected is null and eta_recs.appeal_allowed is null and eta_recs.appeal_dnc is null and eta_recs.appeal_with_direction is null)) and Disputes.ticketserialnumber is null then 'Not dispute or eta' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and ((eta_recs.appeal_rejected = 0 and eta_recs.appeal_allowed = 0 and eta_recs.appeal_dnc = 0 and eta_recs.appeal_with_direction = 0) or (eta_recs.appeal_rejected is null and eta_recs.appeal_allowed is null and eta_recs.appeal_dnc is null and eta_recs.appeal_with_direction is null)) and Disputes.ticketserialnumber is not null then 'disputed' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and eta_recs.appeal_rejected = 0 and eta_recs.appeal_allowed = 0 and eta_recs.appeal_dnc = 0 and eta_recs.appeal_with_direction > 0 and Disputes.ticketserialnumber is null then 'eta with direction' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and eta_recs.appeal_rejected = 0 and eta_recs.appeal_allowed = 0 and eta_recs.appeal_with_direction = 0 and eta_recs.appeal_dnc > 0 and Disputes.ticketserialnumber is null then 'eta dnc' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and eta_recs.appeal_rejected = 0 and eta_recs.appeal_dnc = 0 and eta_recs.appeal_with_direction = 0 and eta_recs.appeal_allowed > 0 and Disputes.ticketserialnumber is null then 'eta allowed' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and eta_recs.appeal_allowed = 0 and eta_recs.appeal_dnc = 0 and eta_recs.appeal_with_direction = 0 and eta_recs.appeal_rejected > 0 and Disputes.ticketserialnumber is null then 'eta rejected' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and eta_recs.appeal_with_direction > 0 and Disputes.ticketserialnumber is not null then 'disputed and eta with direction' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and eta_recs.appeal_dnc > 0 and Disputes.ticketserialnumber is not null then 'disputed and eta dnc' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and eta_recs.appeal_allowed > 0 and Disputes.ticketserialnumber is not null then 'disputed and eta allowed' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and eta_recs.appeal_rejected > 0 and Disputes.ticketserialnumber is not null then 'disputed and eta rejected' -else 'NOT KPI' end as kpi_pcn_dispute_eta_group - -,case -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and ((eta_recs.appeal_rejected = 0 and eta_recs.appeal_allowed = 0 and eta_recs.appeal_dnc = 0 and eta_recs.appeal_with_direction = 0) or (eta_recs.appeal_rejected is null and eta_recs.appeal_allowed is null and eta_recs.appeal_dnc is null and eta_recs.appeal_with_direction is null)) and Disputes.ticketserialnumber is null then 'Y' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and ((eta_recs.appeal_rejected = 0 and eta_recs.appeal_allowed = 0 and eta_recs.appeal_dnc = 0 and eta_recs.appeal_with_direction = 0) or (eta_recs.appeal_rejected is null and eta_recs.appeal_allowed is null and eta_recs.appeal_dnc is null and eta_recs.appeal_with_direction is null)) and Disputes.ticketserialnumber is not null then 'Y' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and eta_recs.appeal_rejected = 0 and eta_recs.appeal_allowed = 0 and eta_recs.appeal_dnc = 0 and eta_recs.appeal_with_direction > 0 and Disputes.ticketserialnumber is null then 'Y' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and eta_recs.appeal_rejected = 0 and eta_recs.appeal_allowed = 0 and eta_recs.appeal_with_direction = 0 and eta_recs.appeal_dnc > 0 and Disputes.ticketserialnumber is null then 'Y' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and eta_recs.appeal_rejected = 0 and eta_recs.appeal_dnc = 0 and eta_recs.appeal_with_direction = 0 and eta_recs.appeal_allowed > 0 and Disputes.ticketserialnumber is null then 'Y' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and eta_recs.appeal_allowed = 0 and eta_recs.appeal_dnc = 0 and eta_recs.appeal_with_direction = 0 and eta_recs.appeal_rejected > 0 and Disputes.ticketserialnumber is null then 'Y' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and eta_recs.appeal_with_direction > 0 and Disputes.ticketserialnumber is not null then 'Y' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and eta_recs.appeal_dnc > 0 and Disputes.ticketserialnumber is not null then 'Y' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and eta_recs.appeal_allowed > 0 and Disputes.ticketserialnumber is not null then 'Y' -when ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and eta_recs.appeal_rejected > 0 and Disputes.ticketserialnumber is not null then 'Y' -else 'N' end as kpi_pcn_dispute_eta_flag - -/*PCNs not eta or disputed*/ -,case -when ((zone like 'Estates') or (street_location like '%Estate%') OR (usrn like 'Z%')) and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and ((eta_recs.appeal_rejected = 0 and eta_recs.appeal_allowed = 0 and eta_recs.appeal_dnc = 0 and eta_recs.appeal_with_direction = 0) or (eta_recs.appeal_rejected is null and eta_recs.appeal_allowed is null and eta_recs.appeal_dnc is null and eta_recs.appeal_with_direction is null)) and Disputes.ticketserialnumber is null Then 'Estates' -when debttype like 'CCTV%' and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and ((eta_recs.appeal_rejected = 0 and eta_recs.appeal_allowed = 0 and eta_recs.appeal_dnc = 0 and eta_recs.appeal_with_direction = 0) or (eta_recs.appeal_rejected is null and eta_recs.appeal_allowed is null and eta_recs.appeal_dnc is null and eta_recs.appeal_with_direction is null)) and Disputes.ticketserialnumber is null Then 'CCTV' -when zone like 'Car Parks' and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and ((eta_recs.appeal_rejected = 0 and eta_recs.appeal_allowed = 0 and eta_recs.appeal_dnc = 0 and eta_recs.appeal_with_direction = 0) or (eta_recs.appeal_rejected is null and eta_recs.appeal_allowed is null and eta_recs.appeal_dnc is null and eta_recs.appeal_with_direction is null)) and Disputes.ticketserialnumber is null Then 'Car_Parks' -When debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' and zone not like 'Car Parks' and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and ((eta_recs.appeal_rejected = 0 and eta_recs.appeal_allowed = 0 and eta_recs.appeal_dnc = 0 and eta_recs.appeal_with_direction = 0) or (eta_recs.appeal_rejected is null and eta_recs.appeal_allowed is null and eta_recs.appeal_dnc is null and eta_recs.appeal_with_direction is null)) and Disputes.ticketserialnumber is null Then 'onstreet' -/*disputed by kpi pcn type*/ -when ((zone like 'Estates') or (street_location like '%Estate%') OR (usrn like 'Z%')) and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and ((eta_recs.appeal_rejected > 0 or eta_recs.appeal_allowed > 0 or eta_recs.appeal_dnc > 0 or eta_recs.appeal_with_direction > 0) or (Disputes.ticketserialnumber is not null)) Then 'Estates - disputed_eta' -when debttype like 'CCTV%' and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and ((eta_recs.appeal_rejected > 0 or eta_recs.appeal_allowed > 0 or eta_recs.appeal_dnc > 0 or eta_recs.appeal_with_direction > 0) or (Disputes.ticketserialnumber is not null)) Then 'CCTV - disputed_eta' -when zone like 'Car Parks' and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and ((eta_recs.appeal_rejected > 0 or eta_recs.appeal_allowed > 0 or eta_recs.appeal_dnc > 0 or eta_recs.appeal_with_direction > 0) or (Disputes.ticketserialnumber is not null)) Then 'Car_Parks - disputed_eta' -When debttype not like 'CCTV%' and zone not like 'Estates' and street_location not like '%Estate%' and usrn not like 'Z%' and zone not like 'Car Parks' and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) and isvoid = 0 and warningflag = 0 and ((eta_recs.appeal_rejected > 0 or eta_recs.appeal_allowed > 0 or eta_recs.appeal_dnc > 0 or eta_recs.appeal_with_direction > 0) or (Disputes.ticketserialnumber is not null)) Then 'onstreet - disputed_eta' -else 'NOT KPI' end as kpi_pcn_not_dispute_eta_name - -,* -from er -left join eta_recs on substr(eta_recs.etar_pcn, 1, 10) = substr(er.er_pcn, 1, 10) -left join Disputes on Disputes.ticketserialnumber = substr(er.er_pcn, 1, 10) -left join pcn on substr(er.er_pcn, 1, 10) = pcn.pcn +SELECT -- To mitigate future side effects from * wildcard columns in the legacy queries above, the following query + -- explicitly define the output columns with data types cast to exactly match the existing target table... + --> "dataplatform-prod-liberator-refined-zone"."parking_eta_decision_records_pcn_dispute_gds" + CAST(r_zone AS VARCHAR) AS r_zone, + -->string + CAST(pcn_type AS VARCHAR) AS pcn_type, + -->string + CAST(ltn_camera_location AS VARCHAR) AS ltn_camera_location, + -->string + CAST(flg_kpi_onstreet_carparks AS INTEGER) AS flg_kpi_onstreet_carparks, + -->int + CAST(flg_kpi_estates AS INTEGER) AS flg_kpi_estates, + -->int + CAST(flg_kpi_cctv AS INTEGER) AS flg_kpi_cctv, + -->int + CAST(flg_kpi_car_parks AS INTEGER) AS flg_kpi_car_parks, + -->int + CAST(flg_kpi_onstreet AS INTEGER) AS flg_kpi_onstreet, + -->int + CAST(flg_kpi_onstreet_carparks_disputes AS INTEGER) AS flg_kpi_onstreet_carparks_disputes, + -->int + CAST(flag_kpi_estates_disputes AS INTEGER) AS flag_kpi_estates_disputes, + -->int + CAST(flag_kpi_cctv_disputes AS INTEGER) AS flag_kpi_cctv_disputes, + -->int + CAST(flag_kpi_car_parks_disputes AS INTEGER) AS flag_kpi_car_parks_disputes, + -->int + CAST(flg_kpi_onstreet_disputes AS INTEGER) AS flg_kpi_onstreet_disputes, + -->int + CAST( + flg_decision_appeal_rejected_onstreet_carparks AS BIGINT + ) AS flg_decision_appeal_rejected_onstreet_carparks, + -->bigint + CAST( + flg_decision_appeal_allowed_onstreet_carparks AS BIGINT + ) AS flg_decision_appeal_allowed_onstreet_carparks, + -->bigint + CAST( + flg_decision_appeal_dnc_onstreet_carparks AS BIGINT + ) AS flg_decision_appeal_dnc_onstreet_carparks, + -->bigint + CAST( + flg_decision_appeal_with_direction_onstreet_carparks AS BIGINT + ) AS flg_decision_appeal_with_direction_onstreet_carparks, + -->bigint + CAST(flg_eta_decision_onstreet_carparks AS BIGINT) AS flg_eta_decision_onstreet_carparks, + -->bigint + CAST(flg_decision_appeal_rejected_estates AS BIGINT) AS flg_decision_appeal_rejected_estates, + -->bigint + CAST(flg_decision_appeal_allowed_estates AS BIGINT) AS flg_decision_appeal_allowed_estates, + -->bigint + CAST(flg_decision_appeal_dnc_estates AS BIGINT) AS flg_decision_appeal_dnc_estates, + -->bigint + CAST( + flg_decision_appeal_with_direction_estates AS BIGINT + ) AS flg_decision_appeal_with_direction_estates, + -->bigint + CAST(flg_eta_decision_estates AS BIGINT) AS flg_eta_decision_estates, + -->bigint + CAST(flg_decision_appeal_rejected_cctv AS BIGINT) AS flg_decision_appeal_rejected_cctv, + -->bigint + CAST(flg_decision_appeal_allowed_cctv AS BIGINT) AS flg_decision_appeal_allowed_cctv, + -->bigint + CAST(flg_decision_appeal_dnc_cctv AS BIGINT) AS flg_decision_appeal_dnc_cctv, + -->bigint + CAST( + flg_decision_appeal_with_direction_cctv AS BIGINT + ) AS flg_decision_appeal_with_direction_cctv, + -->bigint + CAST(flg_eta_decision_cctv AS BIGINT) AS flg_eta_decision_cctv, + -->bigint + CAST(flg_decision_appeal_rejected_car_parks AS BIGINT) AS flg_decision_appeal_rejected_car_parks, + -->bigint + CAST(flg_decision_appeal_allowed_car_parks AS BIGINT) AS flg_decision_appeal_allowed_car_parks, + -->bigint + CAST(flg_decision_appeal_dnc_car_parks AS BIGINT) AS flg_decision_appeal_dnc_car_parks, + -->bigint + CAST( + flg_decision_appeal_with_direction_car_parks AS BIGINT + ) AS flg_decision_appeal_with_direction_car_parks, + -->bigint + CAST(flg_eta_decision_car_parks AS BIGINT) AS flg_eta_decision_car_parks, + -->bigint + CAST(flg_decision_appeal_rejected_onstreet AS BIGINT) AS flg_decision_appeal_rejected_onstreet, + -->bigint + CAST(flg_decision_appeal_allowed_onstreet AS BIGINT) AS flg_decision_appeal_allowed_onstreet, + -->bigint + CAST(flg_decision_appeal_dnc_onstreet AS BIGINT) AS flg_decision_appeal_dnc_onstreet, + -->bigint + CAST( + flg_decision_appeal_with_direction_onstreet AS BIGINT + ) AS flg_decision_appeal_with_direction_onstreet, + -->bigint + CAST(flg_eta_decision_onstreet AS BIGINT) AS flg_eta_decision_onstreet, + -->bigint + CAST(flg_decision_appeal_rejected_all_kpi AS BIGINT) AS flg_decision_appeal_rejected_all_kpi, + -->bigint + CAST(flg_decision_appeal_allowed_all_kpi AS BIGINT) AS flg_decision_appeal_allowed_all_kpi, + -->bigint + CAST(flg_decision_appeal_dnc_all_kpi AS BIGINT) AS flg_decision_appeal_dnc_all_kpi, + -->bigint + CAST( + flg_decision_appeal_with_direction_all_kpi AS BIGINT + ) AS flg_decision_appeal_with_direction_all_kpi, + -->bigint + CAST(flg_eta_decision_all_kpi AS BIGINT) AS flg_eta_decision_all_kpi, + -->bigint + CAST(case_reference AS VARCHAR) AS case_reference, + -->string + CAST("name" AS VARCHAR) AS "name", + -->string + CAST(er_pcn AS VARCHAR) AS er_pcn, + -->string + CAST(hearing_type AS VARCHAR) AS hearing_type, + -->string + CAST(case_status AS VARCHAR) AS case_status, + -->string + CAST( + decision_i_e_dnc_appeal_allowed_appeal_rejected AS VARCHAR + ) AS decision_i_e_dnc_appeal_allowed_appeal_rejected, + -->string + CAST(review_flag AS VARCHAR) AS review_flag, + -->string + CAST(reporting_period AS VARCHAR) AS reporting_period, + -->string + CAST(month_year AS VARCHAR) AS month_year, + -->string + CAST(er_import_datetime AS TIMESTAMP) AS er_import_datetime, + -->timestamp + CAST(er_import_timestamp AS VARCHAR) AS er_import_timestamp, + -->string + CAST(er_import_year AS VARCHAR) AS er_import_year, + -->string + CAST(er_import_month AS VARCHAR) AS er_import_month, + -->string + CAST(er_import_day AS VARCHAR) AS er_import_day, + -->string + CAST(er_import_date AS VARCHAR) AS er_import_date, + -->string + CAST(etar_pcn AS VARCHAR) AS etar_pcn, + -->string + CAST(appeal_rejected AS BIGINT) AS appeal_rejected, + -->bigint + CAST(appeal_allowed AS BIGINT) AS appeal_allowed, + -->bigint + CAST(appeal_dnc AS BIGINT) AS appeal_dnc, + -->bigint + CAST(appeal_with_direction AS BIGINT) AS appeal_with_direction, + -->bigint + CAST(ticketserialnumber AS VARCHAR) AS ticketserialnumber, + -->string + CAST(totalpcndisputed AS BIGINT) AS totalpcndisputed, + -->bigint + CAST(totaldisputed AS BIGINT) AS totaldisputed, + -->bigint + CAST(dispute_import_date AS VARCHAR) AS dispute_import_date, + -->string + CAST(pcn AS VARCHAR) AS pcn, + -->string + CAST(pcnissuedate AS DATE) AS pcnissuedate, + -->date + CAST(pcnissuedatetime AS TIMESTAMP) AS pcnissuedatetime, + -->timestamp + CAST(pcn_canx_date AS DATE) AS pcn_canx_date, + -->date + CAST(cancellationgroup AS VARCHAR) AS cancellationgroup, + -->string + CAST(cancellationreason AS VARCHAR) AS cancellationreason, + -->string + CAST(pcn_casecloseddate AS DATE) AS pcn_casecloseddate, + -->date + CAST(street_location AS VARCHAR) AS street_location, + -->string + CAST(whereonlocation AS VARCHAR) AS whereonlocation, + -->string + CAST("zone" AS VARCHAR) AS "zone", + -->string + CAST(usrn AS VARCHAR) AS usrn, + -->string + CAST(contraventioncode AS VARCHAR) AS contraventioncode, + -->string + CAST(contraventionsuffix AS VARCHAR) AS contraventionsuffix, + -->string + CAST(debttype AS VARCHAR) AS debttype, + -->string + CAST(vrm AS VARCHAR) AS vrm, + -->string + CAST(vehiclemake AS VARCHAR) AS vehiclemake, + -->string + CAST(vehiclemodel AS VARCHAR) AS vehiclemodel, + -->string + CAST(vehiclecolour AS VARCHAR) AS vehiclecolour, + -->string + CAST(ceo AS VARCHAR) AS ceo, + -->string + CAST(ceodevice AS VARCHAR) AS ceodevice, + -->string + CAST(current_30_day_flag AS INTEGER) AS current_30_day_flag, + -->int + CAST(isvda AS INTEGER) AS isvda, + -->int + CAST(isvoid AS INTEGER) AS isvoid, + -->int + CAST(isremoval AS VARCHAR) AS isremoval, + -->string + CAST(driverseen AS VARCHAR) AS driverseen, + -->string + CAST(allwindows AS VARCHAR) AS allwindows, + -->string + CAST(parkedonfootway AS VARCHAR) AS parkedonfootway, + -->string + CAST(doctor AS VARCHAR) AS doctor, + -->string + CAST(warningflag AS INTEGER) AS warningflag, + -->int + CAST(progressionstage AS VARCHAR) AS progressionstage, + -->string + CAST(nextprogressionstage AS VARCHAR) AS nextprogressionstage, + -->string + CAST(nextprogressionstagestarts AS VARCHAR) AS nextprogressionstagestarts, + -->string + CAST(holdreason AS VARCHAR) AS holdreason, + -->string + CAST(lib_initial_debt_amount AS VARCHAR) AS lib_initial_debt_amount, + -->string + CAST(lib_payment_received AS VARCHAR) AS lib_payment_received, + -->string + CAST(lib_write_off_amount AS VARCHAR) AS lib_write_off_amount, + -->string + CAST(lib_payment_void AS VARCHAR) AS lib_payment_void, + -->string + CAST(lib_payment_method AS VARCHAR) AS lib_payment_method, + -->string + CAST(lib_payment_ref AS VARCHAR) AS lib_payment_ref, + -->string + CAST(baliff_from AS VARCHAR) AS baliff_from, + -->string + CAST(bailiff_to AS VARCHAR) AS bailiff_to, + -->string + CAST(bailiff_processedon AS TIMESTAMP) AS bailiff_processedon, + -->timestamp + CAST(bailiff_redistributionreason AS VARCHAR) AS bailiff_redistributionreason, + -->string + CAST(bailiff AS VARCHAR) AS bailiff, + -->string + CAST(warrantissuedate AS TIMESTAMP) AS warrantissuedate, + -->timestamp + CAST(allocation AS INTEGER) AS allocation, + -->int + CAST(eta_datenotified AS TIMESTAMP) AS eta_datenotified, + -->timestamp + CAST(eta_packsubmittedon AS TIMESTAMP) AS eta_packsubmittedon, + -->timestamp + CAST(eta_evidencedate AS TIMESTAMP) AS eta_evidencedate, + -->timestamp + CAST(eta_adjudicationdate AS TIMESTAMP) AS eta_adjudicationdate, + -->timestamp + CAST(eta_appealgrounds AS VARCHAR) AS eta_appealgrounds, + -->string + CAST(eta_decisionreceived AS TIMESTAMP) AS eta_decisionreceived, + -->timestamp + CAST(eta_outcome AS VARCHAR) AS eta_outcome, + -->string + CAST(eta_packsubmittedby AS VARCHAR) AS eta_packsubmittedby, + -->string + CAST(cancelledby AS VARCHAR) AS cancelledby, + -->string + CAST(registered_keeper_address AS VARCHAR) AS registered_keeper_address, + -->string + CAST(current_ticket_address AS VARCHAR) AS current_ticket_address, + -->string + CAST(corresp_dispute_flag AS INTEGER) AS corresp_dispute_flag, + -->int + CAST(keyworker_corresp_dispute_flag AS INTEGER) AS keyworker_corresp_dispute_flag, + -->int + CAST(fin_year_flag AS VARCHAR) AS fin_year_flag, + -->string + CAST(fin_year AS VARCHAR) AS fin_year, + -->string + CAST(ticket_ref AS VARCHAR) AS ticket_ref, + -->string + CAST(nto_printed AS TIMESTAMP) AS nto_printed, + -->timestamp + CAST(appeal_accepted AS TIMESTAMP) AS appeal_accepted, + -->timestamp + CAST(arrived_in_pound AS TIMESTAMP) AS arrived_in_pound, + -->timestamp + CAST(cancellation_reversed AS TIMESTAMP) AS cancellation_reversed, + -->timestamp + CAST(cc_printed AS TIMESTAMP) AS cc_printed, + -->timestamp + CAST(drr AS TIMESTAMP) AS drr, + -->timestamp + CAST(en_printed AS TIMESTAMP) AS en_printed, + -->timestamp + CAST(hold_released AS TIMESTAMP) AS hold_released, + -->timestamp + CAST(dvla_response AS TIMESTAMP) AS dvla_response, + -->timestamp + CAST(dvla_request AS TIMESTAMP) AS dvla_request, + -->timestamp + CAST(full_rate_uplift AS TIMESTAMP) AS full_rate_uplift, + -->timestamp + CAST(hold_until AS TIMESTAMP) AS hold_until, + -->timestamp + CAST(lifted_at AS TIMESTAMP) AS lifted_at, + -->timestamp + CAST(lifted_by AS TIMESTAMP) AS lifted_by, + -->timestamp + CAST(loaded AS TIMESTAMP) AS loaded, + -->timestamp + CAST(nor_sent AS TIMESTAMP) AS nor_sent, + -->timestamp + CAST(notice_held AS TIMESTAMP) AS notice_held, + -->timestamp + CAST(ofr_printed AS TIMESTAMP) AS ofr_printed, + -->timestamp + CAST(pcn_printed AS TIMESTAMP) AS pcn_printed, + -->timestamp + CAST(reissue_nto_requested AS TIMESTAMP) AS reissue_nto_requested, + -->timestamp + CAST(reissue_pcn AS TIMESTAMP) AS reissue_pcn, + -->timestamp + CAST(set_back_to_pre_cc_stage AS TIMESTAMP) AS set_back_to_pre_cc_stage, + -->timestamp + CAST(vehicle_released_for_auction AS TIMESTAMP) AS vehicle_released_for_auction, + -->timestamp + CAST(warrant_issued AS TIMESTAMP) AS warrant_issued, + -->timestamp + CAST(warrant_redistributed AS TIMESTAMP) AS warrant_redistributed, + -->timestamp + CAST(warrant_request_granted AS TIMESTAMP) AS warrant_request_granted, + -->timestamp + CAST(ad_hoc_vq4_request AS TIMESTAMP) AS ad_hoc_vq4_request, + -->timestamp + CAST(paper_vq5_received AS TIMESTAMP) AS paper_vq5_received, + -->timestamp + CAST(pcn_extracted_for_buslane AS TIMESTAMP) AS pcn_extracted_for_buslane, + -->timestamp + CAST(pcn_extracted_for_pre_debt AS TIMESTAMP) AS pcn_extracted_for_pre_debt, + -->timestamp + CAST(pcn_extracted_for_collection AS TIMESTAMP) AS pcn_extracted_for_collection, + -->timestamp + CAST(pcn_extracted_for_drr AS TIMESTAMP) AS pcn_extracted_for_drr, + -->timestamp + CAST(pcn_extracted_for_cc AS TIMESTAMP) AS pcn_extracted_for_cc, + -->timestamp + CAST(pcn_extracted_for_nto AS TIMESTAMP) AS pcn_extracted_for_nto, + -->timestamp + CAST(pcn_extracted_for_print AS TIMESTAMP) AS pcn_extracted_for_print, + -->timestamp + CAST(warning_notice_extracted_for_print AS TIMESTAMP) AS warning_notice_extracted_for_print, + -->timestamp + CAST(pcn_extracted_for_ofr AS TIMESTAMP) AS pcn_extracted_for_ofr, + -->timestamp + CAST(pcn_extracted_for_warrant_request AS TIMESTAMP) AS pcn_extracted_for_warrant_request, + -->timestamp + CAST(pre_debt_new_debtor_details AS TIMESTAMP) AS pre_debt_new_debtor_details, + -->timestamp + CAST(importdattime AS TIMESTAMP) AS importdattime, + -->timestamp + CAST(importdatetime AS TIMESTAMP) AS importdatetime, + -->timestamp + CAST(kpi_pcns AS INTEGER) AS kpi_pcns, + -->int + CAST(kpi_pcn_dispute_eta_group AS VARCHAR) AS kpi_pcn_dispute_eta_group, + -->string + CAST(kpi_pcn_dispute_eta_flag AS VARCHAR) AS kpi_pcn_dispute_eta_flag, + -->string + CAST(kpi_pcn_not_dispute_eta_name AS VARCHAR) AS kpi_pcn_not_dispute_eta_name, + -->string + CAST(import_year AS VARCHAR) AS import_year, + -->string + CAST(import_month AS VARCHAR) AS import_month, + -->string + CAST(import_day AS VARCHAR) AS import_day, + -->string + CAST(import_date AS VARCHAR) AS import_date --, -->string +FROM transform; """ -ApplyMapping_node2 = sparkSqlQuery( - glueContext, - query=SqlQuery0, - mapping={ - "liberator_pcn_ic": AmazonS3Liberator_pcn_ic_node1631812698045, - "pcnfoidetails_pcn_foi_full": S3bucketpcnfoidetails_pcn_foi_full_node1, - "liberator_pcn_tickets": AmazonS3liberator_pcn_tickets_node1637153316033, - "eta_decision_records": AmazonS3parkingrawzoneparking_eta_decision_records_node1645806323578, - }, - transformation_ctx="ApplyMapping_node2", -) -# Script generated for node S3 bucket -S3bucket_node3 = glueContext.getSink( - path="s3://dataplatform-"+environment+"-refined-zone/parking/liberator/parking_eta_decision_records_pcn_dispute_gds/", - connection_type="s3", - updateBehavior="UPDATE_IN_DATABASE", - partitionKeys=["import_year", "import_month", "import_day", "import_date"], - compression="snappy", - enableUpdateCatalog=True, - transformation_ctx="S3bucket_node3", -) -S3bucket_node3.setCatalogInfo( - catalogDatabase="dataplatform-"+environment+"-liberator-refined-zone", - catalogTableName="parking_eta_decision_records_pcn_dispute_gds", +create_update_table_with_partition( + environment=environment, query_on_athena=query_on_athena, table_name=table_name ) -S3bucket_node3.setFormat("glueparquet") -S3bucket_node3.writeFrame(ApplyMapping_node2) -job.commit() diff --git a/scripts/jobs/parking/parking_open_pcns_vrms_linked_cancelled_ringer.py b/scripts/jobs/parking/parking_open_pcns_vrms_linked_cancelled_ringer.py index 9a0cf3a91..980e43f47 100644 --- a/scripts/jobs/parking/parking_open_pcns_vrms_linked_cancelled_ringer.py +++ b/scripts/jobs/parking/parking_open_pcns_vrms_linked_cancelled_ringer.py @@ -1,101 +1,138 @@ -import sys - -from awsglue import DynamicFrame -from awsglue.context import GlueContext -from awsglue.job import Job -from awsglue.transforms import * -from awsglue.utils import getResolvedOptions -from pyspark.context import SparkContext - -from scripts.helpers.helpers import ( - PARTITION_KEYS, - get_glue_env_var, - get_latest_partitions, -) - - -def sparkSqlQuery(glueContext, query, mapping, transformation_ctx) -> DynamicFrame: - for alias, frame in mapping.items(): - frame.toDF().createOrReplaceTempView(alias) - result = spark.sql(query) - return DynamicFrame.fromDF(result, glueContext, transformation_ctx) +""" +Only need to change the table name and the query prototyped on the Athena UI +by replacing table_name and query_on_athena +Note: python file name should be the same as the table name +""" +from scripts.helpers.athena_helpers import create_update_table_with_partition +from scripts.helpers.helpers import get_glue_env_var -args = getResolvedOptions(sys.argv, ["JOB_NAME"]) -sc = SparkContext() -glueContext = GlueContext(sc) -spark = glueContext.spark_session -job = Job(glueContext) -job.init(args["JOB_NAME"], args) environment = get_glue_env_var("environment") -# Script generated for node Amazon S3 - Refined - pcnfoidetails_pcn_foi_full -AmazonS3Refinedpcnfoidetails_pcn_foi_full_node1708021619806 = glueContext.create_dynamic_frame.from_catalog( - database="dataplatform-" + environment + "-liberator-refined-zone", - push_down_predicate="to_date(import_date, 'yyyyMMdd') >= date_sub(current_date, 7)", - table_name="pcnfoidetails_pcn_foi_full", - transformation_ctx="AmazonS3Refinedpcnfoidetails_pcn_foi_full_node1708021619806", -) +# The target table in liberator refined zone +table_name = "parking_open_pcns_vrms_linked_cancelled_ringer" -# Script generated for node SQL Query -SqlQuery0 = """ +# The exact same query prototyped in pre-prod(stg) or prod Athena +query_on_athena = """ /*Open PCNs linked to VRMs cancelled due to being a Ringer or Clone Created: 15/02/2024 11/03/2024 - added extracted post codes and bailiff fields to output */ With cancelled_vrm as ( -Select distinct vrm as canx_vrm -from pcnfoidetails_pcn_foi_full where import_date = (select max(import_date) from pcnfoidetails_pcn_foi_full) and (upper(cancellationgroup) like '%RINGER%' or upper(cancellationreason) like '%RINGER%') + Select distinct vrm as canx_vrm + from "dataplatform-prod-liberator-refined-zone".pcnfoidetails_pcn_foi_full + where import_date = ( + select max(import_date) + from "dataplatform-prod-liberator-refined-zone".pcnfoidetails_pcn_foi_full + ) + and ( + upper(cancellationgroup) like '%RINGER%' + or upper(cancellationreason) like '%RINGER%' + ) ) -Select cancelled_vrm.*, concat(substr(Cast(pcnissuedate as varchar(10)),1, 7), '-01') as MonthYear -,progressionstage ,debttype ,pcn ,pcnissuedate ,pcnissuedatetime ,street_location ,whereonlocation ,zone ,usrn ,contraventioncode ,contraventionsuffix ,vrm ,vehiclemake ,vehiclemodel ,vehiclecolour,corresp_dispute_flag ,registered_keeper_address ,current_ticket_address - -/*Registered extracted post codes*/ -,case when length(regexp_extract(registered_keeper_address, '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})') ) = 0 or regexp_extract(registered_keeper_address, '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})') is null or regexp_extract(registered_keeper_address, '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})') like '' or regexp_extract(registered_keeper_address, '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})') like ' ' then 'No Address' else regexp_extract(registered_keeper_address, '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})') end -as reg_add_extracted_post_code - -/*Current extracted post codes*/ -,case when length(regexp_extract(current_ticket_address, '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})') ) = 0 or regexp_extract(current_ticket_address, '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})') is null or regexp_extract(current_ticket_address, '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})') like '' or regexp_extract(current_ticket_address, '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})') like ' ' then 'No Address' else regexp_extract(current_ticket_address, '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})') end -as curr_add_extracted_post_code -,bailiff - -/*for partiion*/ -,date_format(current_date, 'yyyy') AS import_year -,date_format(current_date, 'MM') AS import_month -,date_format(current_date, 'dd') AS import_day -,date_format(current_date, 'yyyyMMdd') AS import_date - -from pcnfoidetails_pcn_foi_full -left join cancelled_vrm on cancelled_vrm.canx_vrm = pcnfoidetails_pcn_foi_full.vrm - -where pcnfoidetails_pcn_foi_full.import_date = (select max(pcnfoidetails_pcn_foi_full.import_date) from pcnfoidetails_pcn_foi_full) and (pcnfoidetails_pcn_foi_full.pcn_canx_date is null and pcnfoidetails_pcn_foi_full.pcn_casecloseddate is null) and cancelled_vrm.canx_vrm is not null and pcnfoidetails_pcn_foi_full.warningflag = 0 -order by cancelled_vrm.canx_vrm ,progressionstage ,debttype ,pcnissuedatetime desc ,pcn ,street_location +Select cancelled_vrm.*, + concat( + substr(Cast(pcnissuedate as varchar(10)), 1, 7), + '-01' + ) as MonthYear, + progressionstage, + debttype, + pcn, + pcnissuedate, + pcnissuedatetime, + street_location, + whereonlocation, + zone, + usrn, + contraventioncode, + contraventionsuffix, + vrm, + vehiclemake, + vehiclemodel, + vehiclecolour, + corresp_dispute_flag, + registered_keeper_address, + current_ticket_address + /*Registered extracted post codes*/ +, + case + when length( + regexp_extract( + registered_keeper_address, + '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})' + ) + ) = 0 + or regexp_extract( + registered_keeper_address, + '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})' + ) is null + or regexp_extract( + registered_keeper_address, + '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})' + ) like '' + or regexp_extract( + registered_keeper_address, + '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})' + ) like ' ' then 'No Address' + else regexp_extract( + registered_keeper_address, + '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})' + ) + end as reg_add_extracted_post_code + /*Current extracted post codes*/ +, + case + when length( + regexp_extract( + current_ticket_address, + '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})' + ) + ) = 0 + or regexp_extract( + current_ticket_address, + '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})' + ) is null + or regexp_extract( + current_ticket_address, + '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})' + ) like '' + or regexp_extract( + current_ticket_address, + '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})' + ) like ' ' then 'No Address' + else regexp_extract( + current_ticket_address, + '([A-Za-z][A-Ha-hJ-Yj-y]?[0-9][A-Za-z0-9]? ?[0-9][A-Za-z]{2}|[Gg][Ii][Rr] ?0[Aa]{2})' + ) + end as curr_add_extracted_post_code, + bailiff + /*for partiion*/ +, + format_datetime(current_date, 'yyyy') AS import_year, + format_datetime(current_date, 'MM') AS import_month, + format_datetime(current_date, 'dd') AS import_day, + format_datetime(current_date, 'yyyyMMdd') AS import_date +from "dataplatform-prod-liberator-refined-zone".pcnfoidetails_pcn_foi_full + left join cancelled_vrm on cancelled_vrm.canx_vrm = pcnfoidetails_pcn_foi_full.vrm +where pcnfoidetails_pcn_foi_full.import_date = ( + select max(pcnfoidetails_pcn_foi_full.import_date) + from "dataplatform-prod-liberator-refined-zone".pcnfoidetails_pcn_foi_full + ) + and ( + pcnfoidetails_pcn_foi_full.pcn_canx_date is null + and pcnfoidetails_pcn_foi_full.pcn_casecloseddate is null + ) + and cancelled_vrm.canx_vrm is not null + and pcnfoidetails_pcn_foi_full.warningflag = 0 +order by cancelled_vrm.canx_vrm, + progressionstage, + debttype, + pcnissuedatetime desc, + pcn, + street_location """ -SQLQuery_node1708021630710 = sparkSqlQuery( - glueContext, - query=SqlQuery0, - mapping={ - "pcnfoidetails_pcn_foi_full": AmazonS3Refinedpcnfoidetails_pcn_foi_full_node1708021619806 - }, - transformation_ctx="SQLQuery_node1708021630710", -) -# Script generated for node Amazon S3 -AmazonS3_node1708021659577 = glueContext.getSink( - path="s3://dataplatform-" - + environment - + "-refined-zone/parking/liberator/parking_open_pcns_vrms_linked_cancelled_ringer/", - connection_type="s3", - updateBehavior="UPDATE_IN_DATABASE", - partitionKeys=["import_year", "import_month", "import_day", "import_date"], - enableUpdateCatalog=True, - transformation_ctx="AmazonS3_node1708021659577", -) -AmazonS3_node1708021659577.setCatalogInfo( - catalogDatabase="dataplatform-" + environment + "-liberator-refined-zone", - catalogTableName="parking_open_pcns_vrms_linked_cancelled_ringer", +create_update_table_with_partition( + environment=environment, query_on_athena=query_on_athena, table_name=table_name ) -AmazonS3_node1708021659577.setFormat("glueparquet", compression="snappy") -AmazonS3_node1708021659577.writeFrame(SQLQuery_node1708021630710) -job.commit() diff --git a/scripts/jobs/parking/parking_pcn_dvla_response_no_address.py b/scripts/jobs/parking/parking_pcn_dvla_response_no_address.py index eeb7a03f0..19620de29 100644 --- a/scripts/jobs/parking/parking_pcn_dvla_response_no_address.py +++ b/scripts/jobs/parking/parking_pcn_dvla_response_no_address.py @@ -1,177 +1,181 @@ -import sys -from awsglue.transforms import * -from awsglue.utils import getResolvedOptions -from pyspark.context import SparkContext -from awsglue.context import GlueContext -from awsglue.job import Job -from awsglue import DynamicFrame -from scripts.helpers.helpers import get_glue_env_var, get_latest_partitions, PARTITION_KEYS +""" +Only need to change the table name and the query prototyped on the Athena UI +by replacing table_name and query_on_athena +Note: python file name should be the same as the table name +""" + +from scripts.helpers.athena_helpers import create_update_table_with_partition +from scripts.helpers.helpers import get_glue_env_var -def sparkSqlQuery(glueContext, query, mapping, transformation_ctx) -> DynamicFrame: - for alias, frame in mapping.items(): - frame.toDF().createOrReplaceTempView(alias) - result = spark.sql(query) - return DynamicFrame.fromDF(result, glueContext, transformation_ctx) -args = getResolvedOptions(sys.argv, ['JOB_NAME']) -sc = SparkContext() -glueContext = GlueContext(sc) -spark = glueContext.spark_session -job = Job(glueContext) -job.init(args['JOB_NAME'], args) environment = get_glue_env_var("environment") -# Script generated for node Amazon S3 - liberator-refined-zone - pcnfoidetails_pcn_foi_full -AmazonS3liberatorrefinedzonepcnfoidetails_pcn_foi_full_node1720713551944 = glueContext.create_dynamic_frame.from_catalog(database="dataplatform-"+environment+"-liberator-refined-zone", push_down_predicate="to_date(import_date, 'yyyyMMdd') >= date_sub(current_date, 7)", table_name="pcnfoidetails_pcn_foi_full", transformation_ctx="AmazonS3liberatorrefinedzonepcnfoidetails_pcn_foi_full_node1720713551944") +# The target table in liberator refined zone +table_name = "parking_pcn_dvla_response_no_address" -# Script generated for node SQL Query - PCNs DVLA response no address -SqlQuery0 = ''' +# The exact same query prototyped in pre-prod(stg) or prod Athena +query_on_athena = """ /* -All VRMs with PCNs response from DVLA has no address still open and not due to be written off - -Criteria: -All PCNs issued -and is not void -and does not have a warning flag -and is not vda and pcn issue date before '2021-06-01' or can be vda after pcn issue date '2021-05-31' -and has had a dvla_request -and has had a dvla_response -and registered_keeper_address is not null -and has not had a PCN cancelled date -and has not had a pcn_casecloseddate -and next progression stage not like 'WRITEOFF' - -11/07/2024 - Created - -*/ - + All VRMs with PCNs response from DVLA has no address still open and not due to be written off + + Criteria: + All PCNs issued + and is not void + and does not have a warning flag + and is not vda and pcn issue date before '2021-06-01' or can be vda after pcn issue date '2021-05-31' + and has had a dvla_request + and has had a dvla_response + and registered_keeper_address is not null + and has not had a PCN cancelled date + and has not had a pcn_casecloseddate + and next progression stage not like 'WRITEOFF' + + 11/07/2024 - Created + + */ with no_resp_ceo as ( -Select distinct vrm as vrm_ceo -,count(distinct pcn) as num_pcns_ceo - ---, LISTAGG(pcn, ' ') WITHIN GROUP (ORDER BY vrm) as vl_multi_pcns_ceo - ,array_join( -- concat the array - collect_list(distinct pcnfoidetails_pcn_foi_full.pcn), -- aggregate that collects the array of [code] - ' | ' -- delimiter - ) as vl_multi_pcns_ceo - -FROM pcnfoidetails_pcn_foi_full - -WHERE pcnfoidetails_pcn_foi_full.import_date = (SELECT max(pcnfoidetails_pcn_foi_full.import_date) from pcnfoidetails_pcn_foi_full) -and isvoid = 0 -and warningflag = 0 -and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - -and dvla_request is not null -and dvla_response is not null -and registered_keeper_address = '' -and pcn_canx_date is null -and pcn_casecloseddate is null -and upper(debttype) like 'CEO' -and upper(nextprogressionstage) not like 'WRITEOFF' - ---and cast(pcnissuedate as date) > cast('2019-12-31' as date) and cast(pcnissuedate as date) < cast('2024-01-01' as date)--Parking Tickets issued between 01/01/2020 and 31/12/2023. - -group by vrm -order by vrm_ceo -) -, no_resp_cctv as ( -Select distinct vrm as vrm_cctv -,count(distinct pcn) as num_pcns_cctv - ---, LISTAGG(pcn, ' ') WITHIN GROUP (ORDER BY vrm) as vl_multi_pcns_cctv - ,array_join( -- concat the array - collect_list(distinct pcnfoidetails_pcn_foi_full.pcn), -- aggregate that collects the array of [code] - ' | ' -- delimiter - ) as vl_multi_pcns_cctv - -FROM pcnfoidetails_pcn_foi_full - -WHERE pcnfoidetails_pcn_foi_full.import_date = (SELECT max(pcnfoidetails_pcn_foi_full.import_date) from pcnfoidetails_pcn_foi_full) -and isvoid = 0 -and warningflag = 0 -and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - -and dvla_request is not null -and dvla_response is not null -and registered_keeper_address = '' -and pcn_canx_date is null -and pcn_casecloseddate is null -and upper(debttype) in ('CCTV MOVING TRAFFIC','CCTV STATIC','CCTV BUS LANE') -and upper(nextprogressionstage) not like 'WRITEOFF' - ---and cast(pcnissuedate as date) > cast('2019-12-31' as date) and cast(pcnissuedate as date) < cast('2024-01-01' as date)--Parking Tickets issued between 01/01/2020 and 31/12/2023. - -group by vrm_cctv -order by vrm_cctv -) - --- summary sent to DRT -Select distinct pcnfoidetails_pcn_foi_full.vrm -,min(cast(substr(Cast(pcnissuedate as varchar(10)),1, 10) as date)) as min_pcnissuedate -,max(cast(substr(Cast(pcnissuedate as varchar(10)),1, 10) as date)) as max_pcnissuedate -,count(distinct pcn) as num_pcns_all - ---, LISTAGG(pcn, ' ') WITHIN GROUP (ORDER BY vrm) as vl_multi_pcns_all - ,array_join( -- concat the array - collect_list(distinct pcnfoidetails_pcn_foi_full.pcn), -- aggregate that collects the array of [code] - ' | ' -- delimiter - ) as vl_multi_pcns_all - ---CEO PCNs -,num_pcns_ceo -,vl_multi_pcns_ceo - ---CCTV PCNs -,num_pcns_cctv -,vl_multi_pcns_cctv - -/*Partitions*/ -, pcnfoidetails_pcn_foi_full.import_year -, pcnfoidetails_pcn_foi_full.import_month -, pcnfoidetails_pcn_foi_full.import_day -, pcnfoidetails_pcn_foi_full.import_date - -FROM pcnfoidetails_pcn_foi_full - -left join no_resp_cctv on no_resp_cctv.vrm_cctv = pcnfoidetails_pcn_foi_full.vrm -left join no_resp_ceo on no_resp_ceo.vrm_ceo = pcnfoidetails_pcn_foi_full.vrm - -WHERE pcnfoidetails_pcn_foi_full.import_date = (SELECT max(pcnfoidetails_pcn_foi_full.import_date) from pcnfoidetails_pcn_foi_full) -and isvoid = 0 -and warningflag = 0 -and ((isvda = 0 and cast(pcnissuedate as date) < cast('2021-06-01' as date)) or (cast(pcnissuedate as date) > cast('2021-05-31' as date)) ) - -and dvla_request is not null -and dvla_response is not null -and registered_keeper_address = '' -and pcn_canx_date is null -and pcn_casecloseddate is null -and upper(nextprogressionstage) not like 'WRITEOFF' - ---and cast(pcnissuedate as date) > cast('2019-12-31' as date) and cast(pcnissuedate as date) < cast('2024-01-01' as date)--Parking Tickets issued between 01/01/2020 and 31/12/2023. - -group by pcnfoidetails_pcn_foi_full.vrm ---CEO PCNs -,num_pcns_ceo -,vl_multi_pcns_ceo - ---CCTV PCNs -,num_pcns_cctv -,vl_multi_pcns_cctv - -/*Partitions*/ -, pcnfoidetails_pcn_foi_full.import_year -, pcnfoidetails_pcn_foi_full.import_month -, pcnfoidetails_pcn_foi_full.import_day -, pcnfoidetails_pcn_foi_full.import_date - + Select distinct vrm as vrm_ceo, + count(distinct pcn) as num_pcns_ceo --, LISTAGG(pcn, ' ') WITHIN GROUP (ORDER BY vrm) as vl_multi_pcns_ceo +, + array_join( + array_distinct(array_agg(pcnfoidetails_pcn_foi_full.pcn)), + -- aggregate that collects distinct values into an array + ' | ' -- delimiter + ) as vl_multi_pcns_ceo + FROM "dataplatform-prod-liberator-refined-zone".pcnfoidetails_pcn_foi_full + WHERE pcnfoidetails_pcn_foi_full.import_date = ( + SELECT max(pcnfoidetails_pcn_foi_full.import_date) + from "dataplatform-prod-liberator-refined-zone".pcnfoidetails_pcn_foi_full + ) + and isvoid = 0 + and warningflag = 0 + and ( + ( + isvda = 0 + and cast(pcnissuedate as date) < cast('2021-06-01' as date) + ) + or ( + cast(pcnissuedate as date) > cast('2021-05-31' as date) + ) + ) + and dvla_request is not null + and dvla_response is not null + and registered_keeper_address = '' + and pcn_canx_date is null + and pcn_casecloseddate is null + and upper(debttype) like 'CEO' + and upper(nextprogressionstage) not like 'WRITEOFF' --and cast(pcnissuedate as date) > cast('2019-12-31' as date) and cast(pcnissuedate as date) < cast('2024-01-01' as date)--Parking Tickets issued between 01/01/2020 and 31/12/2023. + group by vrm + order by vrm_ceo +), +no_resp_cctv as ( + Select distinct vrm as vrm_cctv, + count(distinct pcn) as num_pcns_cctv --, LISTAGG(pcn, ' ') WITHIN GROUP (ORDER BY vrm) as vl_multi_pcns_cctv +, + array_join( + array_distinct(array_agg(pcnfoidetails_pcn_foi_full.pcn)), + -- aggregate that collects distinct values into an array + ' | ' -- delimiter + ) as vl_multi_pcns_cctv + FROM "dataplatform-prod-liberator-refined-zone".pcnfoidetails_pcn_foi_full + WHERE pcnfoidetails_pcn_foi_full.import_date = ( + SELECT max(pcnfoidetails_pcn_foi_full.import_date) + from "dataplatform-prod-liberator-refined-zone".pcnfoidetails_pcn_foi_full + ) + and isvoid = 0 + and warningflag = 0 + and ( + ( + isvda = 0 + and cast(pcnissuedate as date) < cast('2021-06-01' as date) + ) + or ( + cast(pcnissuedate as date) > cast('2021-05-31' as date) + ) + ) + and dvla_request is not null + and dvla_response is not null + and registered_keeper_address = '' + and pcn_canx_date is null + and pcn_casecloseddate is null + and upper(debttype) in ( + 'CCTV MOVING TRAFFIC', + 'CCTV STATIC', + 'CCTV BUS LANE' + ) + and upper(nextprogressionstage) not like 'WRITEOFF' --and cast(pcnissuedate as date) > cast('2019-12-31' as date) and cast(pcnissuedate as date) < cast('2024-01-01' as date)--Parking Tickets issued between 01/01/2020 and 31/12/2023. + group by vrm + order by vrm +) -- summary sent to DRT +Select distinct pcnfoidetails_pcn_foi_full.vrm, + min( + cast( + substr(Cast(pcnissuedate as varchar(10)), 1, 10) as date + ) + ) as min_pcnissuedate, + max( + cast( + substr(Cast(pcnissuedate as varchar(10)), 1, 10) as date + ) + ) as max_pcnissuedate, + count(distinct pcn) as num_pcns_all --, LISTAGG(pcn, ' ') WITHIN GROUP (ORDER BY vrm) as vl_multi_pcns_all +, + array_join( + array_distinct(array_agg(pcnfoidetails_pcn_foi_full.pcn)), + -- aggregate that collects distinct values into an array + ' | ' -- delimiter + ) as vl_multi_pcns_all --CEO PCNs +, + num_pcns_ceo, + vl_multi_pcns_ceo --CCTV PCNs +, + num_pcns_cctv, + vl_multi_pcns_cctv + /*Partitions*/ +, + pcnfoidetails_pcn_foi_full.import_year, + pcnfoidetails_pcn_foi_full.import_month, + pcnfoidetails_pcn_foi_full.import_day, + pcnfoidetails_pcn_foi_full.import_date +FROM "dataplatform-prod-liberator-refined-zone".pcnfoidetails_pcn_foi_full + left join no_resp_cctv on no_resp_cctv.vrm_cctv = pcnfoidetails_pcn_foi_full.vrm + left join no_resp_ceo on no_resp_ceo.vrm_ceo = pcnfoidetails_pcn_foi_full.vrm +WHERE pcnfoidetails_pcn_foi_full.import_date = ( + SELECT max(pcnfoidetails_pcn_foi_full.import_date) + from "dataplatform-prod-liberator-refined-zone".pcnfoidetails_pcn_foi_full + ) + and isvoid = 0 + and warningflag = 0 + and ( + ( + isvda = 0 + and cast(pcnissuedate as date) < cast('2021-06-01' as date) + ) + or ( + cast(pcnissuedate as date) > cast('2021-05-31' as date) + ) + ) + and dvla_request is not null + and dvla_response is not null + and registered_keeper_address = '' + and pcn_canx_date is null + and pcn_casecloseddate is null + and upper(nextprogressionstage) not like 'WRITEOFF' --and cast(pcnissuedate as date) > cast('2019-12-31' as date) and cast(pcnissuedate as date) < cast('2024-01-01' as date)--Parking Tickets issued between 01/01/2020 and 31/12/2023. +group by pcnfoidetails_pcn_foi_full.vrm --CEO PCNs +, + num_pcns_ceo, + vl_multi_pcns_ceo --CCTV PCNs +, + num_pcns_cctv, + vl_multi_pcns_cctv + /*Partitions*/ +, + pcnfoidetails_pcn_foi_full.import_year, + pcnfoidetails_pcn_foi_full.import_month, + pcnfoidetails_pcn_foi_full.import_day, + pcnfoidetails_pcn_foi_full.import_date order by pcnfoidetails_pcn_foi_full.vrm -''' -SQLQueryPCNsDVLAresponsenoaddress_node1720713555172 = sparkSqlQuery(glueContext, query = SqlQuery0, mapping = {"pcnfoidetails_pcn_foi_full":AmazonS3liberatorrefinedzonepcnfoidetails_pcn_foi_full_node1720713551944}, transformation_ctx = "SQLQueryPCNsDVLAresponsenoaddress_node1720713555172") +""" -# Script generated for node Amazon S3 - parking_pcn_dvla_response_no_address -AmazonS3parking_pcn_dvla_response_no_address_node1720713560381 = glueContext.getSink(path="s3://dataplatform-"+environment+"-refined-zone/parking/liberator/parking_pcn_dvla_response_no_address/", connection_type="s3", updateBehavior="UPDATE_IN_DATABASE", partitionKeys=["import_year", "import_month", "import_day", "import_date"], enableUpdateCatalog=True, transformation_ctx="AmazonS3parking_pcn_dvla_response_no_address_node1720713560381") -AmazonS3parking_pcn_dvla_response_no_address_node1720713560381.setCatalogInfo(catalogDatabase="dataplatform-"+environment+"-liberator-refined-zone",catalogTableName="parking_pcn_dvla_response_no_address") -AmazonS3parking_pcn_dvla_response_no_address_node1720713560381.setFormat("glueparquet", compression="snappy") -AmazonS3parking_pcn_dvla_response_no_address_node1720713560381.writeFrame(SQLQueryPCNsDVLAresponsenoaddress_node1720713555172) -job.commit() +create_update_table_with_partition( + environment=environment, query_on_athena=query_on_athena, table_name=table_name +) diff --git a/scripts/jobs/parking/parking_pcn_ltn_report_summary.py b/scripts/jobs/parking/parking_pcn_ltn_report_summary.py index 5a5925930..d14b10f8b 100644 --- a/scripts/jobs/parking/parking_pcn_ltn_report_summary.py +++ b/scripts/jobs/parking/parking_pcn_ltn_report_summary.py @@ -1,108 +1,87 @@ -import sys - -from awsglue import DynamicFrame -from awsglue.context import GlueContext -from awsglue.job import Job -from awsglue.transforms import * -from awsglue.utils import getResolvedOptions -from pyspark.context import SparkContext +""" +Only need to change the table name and the query prototyped on the Athena UI +by replacing table_name and query_on_athena +Note: python file name should be the same as the table name +""" +from scripts.helpers.athena_helpers import create_update_table_with_partition from scripts.helpers.helpers import get_glue_env_var environment = get_glue_env_var("environment") +# The target table in liberator refined zone +table_name = "Parking_PCN_LTN_Report_Summary" -def sparkSqlQuery(glueContext, query, mapping, transformation_ctx) -> DynamicFrame: - for alias, frame in mapping.items(): - frame.toDF().createOrReplaceTempView(alias) - result = spark.sql(query) - return DynamicFrame.fromDF(result, glueContext, transformation_ctx) - - -args = getResolvedOptions(sys.argv, ["JOB_NAME"]) -sc = SparkContext() -glueContext = GlueContext(sc) -spark = glueContext.spark_session -job = Job(glueContext) -job.init(args["JOB_NAME"], args) - -# Script generated for node Amazon S3 -AmazonS3_node1625732651466 = glueContext.create_dynamic_frame.from_catalog( - database="dataplatform-" + environment + "-liberator-refined-zone", - table_name="pcnfoidetails_pcn_foi_full", - transformation_ctx="AmazonS3_node1625732651466", -) - -# Script generated for node ApplyMapping -SqlQuery0 = """ +# The exact same query prototyped in pre-prod(stg) or prod Athena +query_on_athena = """ /************************************************************************************************************************* -Parking_PCN_LTN_Report_Summary - -The SQL builds the PCN Low Traffic Network figures, for use with the answering of the LTN FOI's - -12/07/2021 - Create SQL. -*************************************************************************************************************************/ -SELECT concat(substr(Cast(pcnissuedate as varchar(10)),1, 7), '-01') AS IssueMonthYear, - street_location, - COUNT(distinct pcn) AS PCNs_Issued, - CAST(SUM(cast(lib_payment_received as double)) as decimal(11,2)) AS Total_Amount_Paid, + Parking_PCN_LTN_Report_Summary - current_timestamp() as ImportDateTime, - date_format(current_date, 'yyyy') AS import_year, - date_format(current_date, 'MM') AS import_month, - date_format(current_date, 'dd') AS import_day, - date_format(current_date, 'yyyyMMdd') AS import_date + The SQL builds the PCN Low Traffic Network figures, for use with the answering of the LTN FOI's -FROM pcnfoidetails_pcn_foi_full as A -WHERE warningflag = 0 and isvda = 0 and isvoid = 0 AND -vrm != 'T123EST' AND contraventioncode = '52' AND -street_location IN ('Allen Road', -'Ashenden Road junction of Glyn Road', -'Barnabas Road JCT Berger Road','Barnabas Road JCT Oriel Road', -'Brooke Road (E)', -'Brooke Road junction of Evering Road', -'Dove Row', -'Gore Road junction of Lauriston Road.', -'Hyde Road', -'Hyde Road JCT Northport Street', -'Lee Street junction of Stean Street', -'Maury Road junction of Evering Road', -'Meeson Street junction of Kingsmead Way', -'Nevill Road junction of Osterley Road', -'Neville Road junction of Osterley Road', -'Pitfield Street (F)', -'Pitfield Street JCT Hemsworth Street', -'Powell Road junction of Kenninghall Road', -'Pritchard`s Road', -'Pritchards Road', -'Richmond Road junction of Greenwood Road', -'Shepherdess Walk', -'Ufton Road junction of Downham Road', 'Wilton Way junction of Greenwood Road') - -GROUP BY concat(substr(Cast(pcnissuedate as varchar(10)),1, 7), '-01'), street_location, import_date, import_day, import_month, import_year + 12/07/2021 - Create SQL. + *************************************************************************************************************************/ +SELECT concat( + substr(Cast(pcnissuedate as varchar(10)), 1, 7), + '-01' + ) AS IssueMonthYear, + street_location, + COUNT(distinct pcn) AS PCNs_Issued, + CAST( + SUM(cast(lib_payment_received as double)) as decimal(11, 2) + ) AS Total_Amount_Paid, + cast(current_timestamp as timestamp) as ImportDateTime, + format_datetime(current_date, 'yyyy') AS import_year, + format_datetime(current_date, 'MM') AS import_month, + format_datetime(current_date, 'dd') AS import_day, + format_datetime(current_date, 'yyyyMMdd') AS import_date +FROM "dataplatform-prod-liberator-refined-zone".pcnfoidetails_pcn_foi_full as A +WHERE warningflag = 0 + and isvda = 0 + and isvoid = 0 + AND import_date =( + select max(import_date) + from "dataplatform-prod-liberator-refined-zone".pcnfoidetails_pcn_foi_full + ) + AND vrm != 'T123EST' + AND contraventioncode = '52' + AND street_location IN ( + 'Allen Road', + 'Ashenden Road junction of Glyn Road', + 'Barnabas Road JCT Berger Road', + 'Barnabas Road JCT Oriel Road', + 'Brooke Road (E)', + 'Brooke Road junction of Evering Road', + 'Dove Row', + 'Gore Road junction of Lauriston Road.', + 'Hyde Road', + 'Hyde Road JCT Northport Street', + 'Lee Street junction of Stean Street', + 'Maury Road junction of Evering Road', + 'Meeson Street junction of Kingsmead Way', + 'Nevill Road junction of Osterley Road', + 'Neville Road junction of Osterley Road', + 'Pitfield Street (F)', + 'Pitfield Street JCT Hemsworth Street', + 'Powell Road junction of Kenninghall Road', + 'Pritchard`s Road', + 'Pritchards Road', + 'Richmond Road junction of Greenwood Road', + 'Shepherdess Walk', + 'Ufton Road junction of Downham Road', + 'Wilton Way junction of Greenwood Road' + ) +GROUP BY concat( + substr(Cast(pcnissuedate as varchar(10)), 1, 7), + '-01' + ), + street_location, + import_date, + import_day, + import_month, + import_year; """ -ApplyMapping_node2 = sparkSqlQuery( - glueContext, - query=SqlQuery0, - mapping={"pcnfoidetails_pcn_foi_full": AmazonS3_node1625732651466}, - transformation_ctx="ApplyMapping_node2", -) -# Script generated for node S3 bucket -S3bucket_node3 = glueContext.getSink( - path="s3://dataplatform-" - + environment - + "-refined-zone/parking/liberator/Parking_PCN_LTN_Report_Summary/", - connection_type="s3", - updateBehavior="UPDATE_IN_DATABASE", - partitionKeys=["import_year", "import_month", "import_day", "import_date"], - enableUpdateCatalog=True, - transformation_ctx="S3bucket_node3", -) -S3bucket_node3.setCatalogInfo( - catalogDatabase="dataplatform-" + environment + "-liberator-refined-zone", - catalogTableName="Parking_PCN_LTN_Report_Summary", +create_update_table_with_partition( + environment=environment, query_on_athena=query_on_athena, table_name=table_name ) -S3bucket_node3.setFormat("glueparquet") -S3bucket_node3.writeFrame(ApplyMapping_node2) -job.commit() diff --git a/terraform/etl/38-aws-glue-job-parking.tf b/terraform/etl/38-aws-glue-job-parking.tf index 5638ce788..ea89c308c 100644 --- a/terraform/etl/38-aws-glue-job-parking.tf +++ b/terraform/etl/38-aws-glue-job-parking.tf @@ -159,7 +159,7 @@ module "parking_pcn_ltn_report_summary" { triggered_by_job = module.parking_pcn_denormalisation.job_name job_description = "This job creates the LTN PCN count and Total paid" workflow_name = "${local.short_identifier_prefix}parking-liberator-data-workflow" - number_of_workers_for_glue_job = 10 + number_of_workers_for_glue_job = 2 glue_job_worker_type = "G.1X" glue_version = "4.0" job_parameters = { @@ -235,26 +235,8 @@ module "parking_correspondence_performance_records_with_pcn" { } } -module "parking_disputes_kpi_gds_summary" { - source = "../modules/aws-glue-job" - is_live_environment = local.is_live_environment - is_production_environment = local.is_production_environment - department = module.department_parking_data_source - job_name = "${local.short_identifier_prefix}parking_disputes_kpi_gds_summary" - helper_module_key = data.aws_s3_object.helpers.key - pydeequ_zip_key = data.aws_s3_object.pydeequ.key - spark_ui_output_storage_id = module.spark_ui_output_storage_data_source.bucket_id - script_name = "parking_disputes_kpi_gds_summary" - job_description = "Disputes and responses for KPI reporting in Google Data Studio (GDS) summary" - trigger_enabled = false - number_of_workers_for_glue_job = 10 - glue_job_worker_type = "G.1X" - glue_version = "4.0" - job_parameters = { - "--job-bookmark-option" = "job-bookmark-disable" - "--environment" = var.environment - } -} +# parking_Disputes_KPI_GDS_Summary not in use anymore - confirmed with Davina + module "parking_foi_pcn_gds_daily_summary" { source = "../modules/aws-glue-job" is_live_environment = local.is_live_environment @@ -293,7 +275,7 @@ module "parking_eta_decision_records_pcn_dispute_gds" { job_description = "Daily summarising data from the FOI Google Data Studio dashboard as need to be under 100,000" workflow_name = "${local.short_identifier_prefix}parking-liberator-data-workflow" trigger_enabled = local.is_production_environment - number_of_workers_for_glue_job = 10 + number_of_workers_for_glue_job = 2 glue_job_worker_type = "G.1X" glue_version = "4.0" job_parameters = { @@ -451,7 +433,7 @@ module "parking_open_pcns_vrms_linked_cancelled_ringer" { job_description = "Parking Open PCNs linked to VRMs cancelled due to being a Ringer or Clone" workflow_name = "${local.short_identifier_prefix}parking-liberator-data-workflow" trigger_enabled = local.is_production_environment - number_of_workers_for_glue_job = 10 + number_of_workers_for_glue_job = 2 glue_job_worker_type = "G.1X" glue_version = "4.0" job_parameters = { @@ -480,7 +462,7 @@ module "parking_pcn_dvla_response_no_address" { job_description = "All VRMs with PCNs response from DVLA has no address still open and not due to be written off" workflow_name = "${local.short_identifier_prefix}parking-liberator-data-workflow" trigger_enabled = local.is_production_environment - number_of_workers_for_glue_job = 10 + number_of_workers_for_glue_job = 2 glue_job_worker_type = "G.1X" glue_version = "4.0" job_parameters = {