-
Notifications
You must be signed in to change notification settings - Fork 7
WIP: Automation for Open Interface tests #34
base: master
Are you sure you want to change the base?
Conversation
fbcb97d
to
3bae733
Compare
@@ -0,0 +1,31 @@ | |||
select veh.registration, date_format(mtc.issued_date,'%Y%m%d') as issued_date, mtc.number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an alternative interpretation of what I think this SQL is trying to achieve:
select veh.registration, date_format(t.issued_date,'%Y%m%d') as issued_date, t.number
from mot_test_emergency_reason e
join mot_test_current t on t.id = e.id
join vehicle veh on t.vehicle_id = veh.id
where e.created_on > date_sub(curdate(), interval 31 day)
and t.status_id = 6 -- only consider passsed tests
and t.id = (select max(id) as id -- and only if latest test is the pass
from mot_test_current mtc
where mtc.vehicle_id = t.vehicle_id
group by vehicle_id
)
and t.odometer_result_type = 'OK'
and veh.registration not like "%-%" -- exclude registration with hyphon - these are likely foreign plates
and veh.registration not like "@%" -- exclude deleted vehicles
and veh.registration is not null -- nullable in PP/Prod
and veh.vin is not null -- nullable in PP/Prod
and not exists (
select 1 from vehicle v
where v.registration = veh.registration
group by v.registration
having count(v.registration) > 1 -- exclude where same registration has been entered as different vehicles
)
and not exists (
select 1 from vehicle v
where v.vin = veh.vin
group by v.vin
having count(v.vin) > 1 -- exclude where same vin has been entered as different vehicles
)
order by t.issued_date asc -- Not sure why an order by would need to be included here??
limit 50
;
I will make a couple of specific comments on the original in a minute.
group by v.vin | ||
having count(v.vin) > 1 -- exclude where same vin has been entered as different vehicles | ||
) | ||
group by mtc.issued_date asc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This group by does not look correct - and order by may have been intended, though I am unsure what the value of either is.
and mter.id = mtc.id | ||
and veh.id = latest_mot.vehicle_id | ||
and mtc.id = latest_mot.id | ||
and mtc.status_id not in (4,5) -- exclude vehicles whose latest status is under test or failed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
excluding active and failed still leaves other aborted status - my thinking is that you are only interested in the latest tests that are passes i.e. status_id = 6.
@@ -0,0 +1,31 @@ | |||
select veh.registration, date_format(mtc.issued_date,'%Y%m%d') as issued_date, mtc.number | |||
from vehicle veh, model_detail md, | |||
(select max(id) as id, vehicle_id from mot_test_current |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I include this as a sub query in a different way in my alternative query - since the query appears to only need 50 rows based on the limit this seems a bit of a heavy way to get 50 rows.
and veh.id = latest_mot.vehicle_id | ||
and mtc.id = latest_mot.id | ||
and mtc.status_id not in (4,5) -- exclude vehicles whose latest status is under test or failed | ||
and date_add(mtc.issued_date, interval 31 day) > curdate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I take this to mean that you are only considering contingency tests entered in the last 31 days.
This will not work too well with anonymised data sets since they age and will quickly have no rows satisfying this condition.
@@ -0,0 +1,31 @@ | |||
select veh.registration, date_format(mtc.issued_date,'%Y%m%d') as issued_date, mtc.number | |||
from vehicle veh, model_detail md, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no apparent need to model_detail in the query.
@@ -0,0 +1,29 @@ | |||
select veh.registration, date_format(mtc.issued_date,'%Y%m%d') as issued_date, mtc.number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A possible alternative query for this is as follows:
select veh.registration, date_format(t.issued_date,'%Y%m%d') as issued_date, t.number
from mot_test_current t
join vehicle veh on t.vehicle_id = veh.id
where
t.status_id = 6 -- only consider passed tests
and t.expiry_date > CURRENT_DATE -- that have not expired
and t.id = (select max(id) as id -- and only if latest test is the pass
from mot_test_current mtc
where mtc.vehicle_id = t.vehicle_id
group by vehicle_id
)
and t.odometer_result_type = 'OK'
and veh.registration not like "%-%" -- exclude registration with hyphon - these are likely foreign plates
and veh.registration not like "@%" -- exclude deleted vehicles
and veh.registration is not null -- exclude null even though it's nullable
and veh.vin is not null -- exclude null even though it's nullable
and not exists (
select 1 from vehicle v
where v.registration = veh.registration
group by v.registration
having count(v.registration) > 1 -- exclude where same registration has been entered as different vehicles
)
and not exists (
select 1 from vehicle v
where v.vin = veh.vin
group by v.vin
having count(v.vin) > 1 -- exclude where same vin has been entered as different vehicles
)
limit 50 ;
select veh.registration | ||
from vehicle as veh | ||
left join mot_test_current as mtc on veh.id = mtc.vehicle_id | ||
and veh.registration not like "%-%" -- exclude dodgy test data on ACPT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first 'and' after the left join should have been a WHERE.
This script looks flawed. At the time it was written there would have been few [DVSA] vehicles in existence that did not have a test associated with them - I'd expect the majority of these would have been vehicles that TSS moved tests away from due to tester errors (or possibly migrated vehicles). The MTS system had no means of creating a vehicle without a test - which is the condition this SQL is expecting.
Since then, the DQ team did create a bunch of vehicles (or at least planned to create vehicles) before they were tested so these may actually exist presently.
If the intention of this is to find vehicles with no valid MOT, then I expect a different query is required here.
Maybe something like this:
select veh.registration
/* , date_format(t.issued_date,'%Y%m%d') as issued_date, t.number, t.expiry_date */
from mot_test_current t
join vehicle veh on t.vehicle_id = veh.id
where
t.status_id = 6 -- only consider passsed tests
and t.expiry_date < CURRENT_DATE
and t.expiry_date > DATE_SUB(CURRENT_DATE, interval 1 year)
and t.id = (select max(id) as id -- and only if latest test is the pass
from mot_test_current mtc
where mtc.vehicle_id = t.vehicle_id
group by vehicle_id
)
and veh.registration not like "%-%" -- exclude registration with hyphon - these are likely foreign plates
and veh.registration not like "@%" -- exclude deleted vehicles
and veh.registration is not null -- exclude null even though it's nullable
and veh.vin is not null -- exclude null even though it's nullable
and not exists (
select 1 from vehicle v
where v.registration = veh.registration
group by v.registration
having count(v.registration) > 1 -- exclude where same registration has been entered as different vehicles
)
and not exists (
select 1 from vehicle v
where v.vin = veh.vin
group by v.vin
having count(v.vin) > 1 -- exclude where same vin has been entered as different vehicles
)
limit 50
;
92e6c36
to
69be378
Compare
48e5c7d
to
d6b7716
Compare
No description provided.