Hello there,
It is good fun figuring this out - I am building my own project too.
For this weeks service, those services have been amended to start or terminate at Exeter Central.
Thus they will be still be running, but as an amended schedule.
The permanent schedule will have a combination of days run and date validity - the thing to match on is the schedule uid.
For example...
2R91 1733 Barnstaple to Exeter Central Permanent schedule with UID P33293 has been amended to start at Exeter St Davids today.
This is known as an overlay.
To pick up an overlay (or cancellation), comparison needs to be done again the uid for a P schedule and the dates that P schedule is valid for.
Thus is you look for a uid of P33293 valid for today, you will pick the permanent version and tne amended version.
This is also true of cancellations:
2E95 2141 Barnstaple to Exeter St Davids is cancelled throughout - if you match on its uid of P31559 for today, you will pick up the P schedule and it's cancellation.
A quick guide on stp indicators
P = Permanent
O = Overlay
C = Cancellation
N = New
Permanent can be overlaid or cancelled. Thus if you match two schedules on a day, to select the one which actually applies some logic is needed to sort that out.
For P, O, or C schedules, I have seen the lowest letter in the alphabet wins (whether this is by design or not, it makes the logic a little easier to think about).
New schedules are not associated with a permanent schedule - so the logic is simple.
Thus performing the query as you have it will look like permanent schedules have not been cancelled, but in fact the still operate between Exeter St Davids and Exeter Central which is an amendment rather than a cancellation.
It is a lot to get your head around. It was for me!
Kind regards