This is quiet long. I have a table (tblSchedule). It has fields for anticipated and actual dates related to the delivery, unloading, etc. of coal. I want to determine the "scheduling accuracy" of each phase.
tblSchedule
ScheduleID - autonum
TrainID - autonum
TrainPartID - autonum (1,2,3 or 4)
DateTypeID - text (1 or 2)
DateID - text (1,2,3 or 4)
ScheduleDate - date
TStamp - date (Time stamp)
tblDateTypeID
1 = Anticipated
2 = Actual
DateID
1 = Load
2 = Arrive
3 = Empty
4 = Remove
The date info can be considered to be in sets of DateTypeID and DateID, i.e.
1,1 = Anticipated Load
2,1 = Actual Load
1,2 = Anticiapted Arrive
2,2 = Actual Arrive
1,3 = Anticipated Empty
2,3 = Actual Empty
1,4 = Anticipated Remove
2,4 = Actual Remove
For each TrainID-TrainPartID set, I want to find the scheduling accuracy for each phase (Load, Arrive, Empty, Remove). The accuracy will be defined as follows:
LoadAcc = (Earliest(1,1)ScheduleDate - Earliest(1,1)TStamp) divided by ((2,1)SchduleDate - Earliest(1,1) TStamp)
ArriveAcc = (Earliest(1,2)ScheduleDate - Earliest(1,2)TStamp) divided by ((2,2)SchduleDate - Earliest(1,2)TStamp)
EmptyAcc = (Earliest(1,3)ScheduleDate - Earliest(1,3)TStamp) divided by ((2,3)SchduleDate - Earliest(1,3)TStamp)
RemoveAcc = (Earliest(1,4)ScheduleDate - Earliest(1,4)TStamp) divided by ((2,4)SchduleDate - Earliest(1,4)TStamp)
Example:
For a particular TrainID-TrainPartID
DateTypeID DateID ScheduleDate TStamp
1 1 10/21/07 10/19/07
1 1 10/22/07 10/20/07
2 1 10/23/07 10/23/07
1 2 10/26/07 10/23/07
2 2 10/26/07 10/26/07
1 3 10/29/07 10/26/07
1 3 10/30/07 10/29/07
2 3 10/31/07 10/31/07
1 4 11/1/07 10/31/07
1 4 11/2/07 11/1/07
2 4 11/3/07 11/3/07
Desired result
LoadAcc = (10/21 - 10/19) / (10/23 - 10/19) = 2/4 = .5
ArriveAcc = (10/26 - 10/23) / (10/26 - 10/23) = 3/3 = 1
EmptyAcc = (10/29 - 10/26) / (10/31 - 10/26) = 3/5 = .6
RemoveAcc = (11/1 - 10/31) / ( 11/3 - 10/31) = 1/3 = .33
All the phases may not be complete for the trains in the date range, or there may be no trains in the date range. the query should only determine accuracies for the completed phases of each train, i.e. there is an actual (DateTypeID =2)for the phase (load, arrive, empty or remove) for the TrainID-TrainPartID set.
I would like to be able to report on a selected range of ScheduleDate dates.
I have the following query to find the trains-parts that have a load DateID = 1.
I anticipate using a form frmSchedulingAccuracy that will be used to select the start and end dates, and the phase (Load, Arrive, Empty, Remove).
From there I'm pretty much lost how to get the accuracy values.
Any suggestions?
Thanks,
Brian
tblSchedule
ScheduleID - autonum
TrainID - autonum
TrainPartID - autonum (1,2,3 or 4)
DateTypeID - text (1 or 2)
DateID - text (1,2,3 or 4)
ScheduleDate - date
TStamp - date (Time stamp)
tblDateTypeID
1 = Anticipated
2 = Actual
DateID
1 = Load
2 = Arrive
3 = Empty
4 = Remove
The date info can be considered to be in sets of DateTypeID and DateID, i.e.
1,1 = Anticipated Load
2,1 = Actual Load
1,2 = Anticiapted Arrive
2,2 = Actual Arrive
1,3 = Anticipated Empty
2,3 = Actual Empty
1,4 = Anticipated Remove
2,4 = Actual Remove
For each TrainID-TrainPartID set, I want to find the scheduling accuracy for each phase (Load, Arrive, Empty, Remove). The accuracy will be defined as follows:
LoadAcc = (Earliest(1,1)ScheduleDate - Earliest(1,1)TStamp) divided by ((2,1)SchduleDate - Earliest(1,1) TStamp)
ArriveAcc = (Earliest(1,2)ScheduleDate - Earliest(1,2)TStamp) divided by ((2,2)SchduleDate - Earliest(1,2)TStamp)
EmptyAcc = (Earliest(1,3)ScheduleDate - Earliest(1,3)TStamp) divided by ((2,3)SchduleDate - Earliest(1,3)TStamp)
RemoveAcc = (Earliest(1,4)ScheduleDate - Earliest(1,4)TStamp) divided by ((2,4)SchduleDate - Earliest(1,4)TStamp)
Example:
For a particular TrainID-TrainPartID
DateTypeID DateID ScheduleDate TStamp
1 1 10/21/07 10/19/07
1 1 10/22/07 10/20/07
2 1 10/23/07 10/23/07
1 2 10/26/07 10/23/07
2 2 10/26/07 10/26/07
1 3 10/29/07 10/26/07
1 3 10/30/07 10/29/07
2 3 10/31/07 10/31/07
1 4 11/1/07 10/31/07
1 4 11/2/07 11/1/07
2 4 11/3/07 11/3/07
Desired result
LoadAcc = (10/21 - 10/19) / (10/23 - 10/19) = 2/4 = .5
ArriveAcc = (10/26 - 10/23) / (10/26 - 10/23) = 3/3 = 1
EmptyAcc = (10/29 - 10/26) / (10/31 - 10/26) = 3/5 = .6
RemoveAcc = (11/1 - 10/31) / ( 11/3 - 10/31) = 1/3 = .33
All the phases may not be complete for the trains in the date range, or there may be no trains in the date range. the query should only determine accuracies for the completed phases of each train, i.e. there is an actual (DateTypeID =2)for the phase (load, arrive, empty or remove) for the TrainID-TrainPartID set.
I would like to be able to report on a selected range of ScheduleDate dates.
I have the following query to find the trains-parts that have a load DateID = 1.
Code:
SELECT tblSchedule.ScheduleID, tblSchedule.TrainID, tblSchedule.TrainPartID, tblSchedule.DateTypeID, tblSchedule.DateID, tblSchedule.ScheduleDate, tblSchedule.Notes, tblSchedule.TStamp
FROM tblSchedule
WHERE tblSchedule.DateID = "1"
ORDER BY TrainID, TrainPartID;
I anticipate using a form frmSchedulingAccuracy that will be used to select the start and end dates, and the phase (Load, Arrive, Empty, Remove).
From there I'm pretty much lost how to get the accuracy values.
Any suggestions?
Thanks,
Brian