Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
I am trying to calculate run time per our Location using our labor transactions. More than one employee might be clocked into the same work type at the same time and that would be a duplication of hours if they worked the same amount of time.
I hope this is an easy fix.
I hope this is easy. Thanks!
This is the table that is extracted: (the time stamp comes out like 42539.5625 but used date and time format for visibility)
Labor_Table:
LOAD * INLINE [
RowNo, Work_Type, Employee, Clock_In, Clock_Out
1, Cut, Mike, 6/18/2016 5:00:00 AM, 6/18/2016 12:00:00 PM
2, Machine, John, 6/19/2016 5:00:00 AM, 6/19/2016 1:00:00 PM
3, Machine, Tim, 6/19/2016 5:00:00 AM, 6/19/2016 3:00:00 PM
4, Machine, John, 6/20/2016 4:00:00 AM, 6/20/2016 12:00:00 PM
5, Machine, Tim, 6/20/2016 7:00:00 AM, 6/20/2016 11:00:00 AM
6, Machine, Phil, 6/20/2016 5:00:00 AM, 6/20/2016 3:00:00 PM
7, Machine,, John, 6/21/2016 6:00:00 AM, 6/21/2016 12:00:00 PM
8, Paint, Tom, 6/25/2016 8:00:00 AM, 6/20/2016 8:00:00 PM
9, Paint, Chris, 6/25/2016 7:00:00 AM, 6/20/2016 3:00:00 PM
];
This is the Table I want created:
Run_Table:
LOAD * INLINE [
RowNo, Work_Type, Clock_In, Clock_Out, Run_Hr
1, Cut, 6/18/2016 5:00:00 AM, 6/18/2016 12:00:00 PM, 7
2, Machine, 6/19/2016 5:00:00 AM, 6/19/2016 3:00:00 PM, 10
3, Machine, 6/20/2016 4:00:00 AM, 6/20/2016 3:00:00 PM, 11
4, Machine, 6/21/2016 6:00:00 AM, 6/21/2016 12:00:00 PM, 6
5, Paint, 6/25/2016 7:00:00 AM, 6/20/2016 8:00:00 PM, 13
];
Try the script
Labor_Table:
LOAD
RowNo, Work_Type, Employee, Time(Time#(Clock_In,'MM/DD/YYYY hh:mm:ss TT'),'MM/DD/YYYY hh:mm:ss TT') as Clock_In,
Time(Time#(Clock_Out,'MM/DD/YYYY hh:mm:ss TT'),'MM/DD/YYYY hh:mm:ss TT') as Clock_Out ,
Interval( Time#(Clock_Out,'MM/DD/YYYY hh:mm:ss TT')-Time#(Clock_In,'MM/DD/YYYY hh:mm:ss TT') ,'h') AS Run_Hr
INLINE [
RowNo, Work_Type, Employee, Clock_In, Clock_Out
1, Cut, Mike, 6/18/2016 5:00:00 AM, 6/18/2016 12:00:00 PM
2, Machine, John, 6/19/2016 5:00:00 AM, 6/19/2016 1:00:00 PM
3, Machine, Tim, 6/19/2016 5:00:00 AM, 6/19/2016 3:00:00 PM
4, Machine, John, 6/20/2016 4:00:00 AM, 6/20/2016 12:00:00 PM
5, Machine, Tim, 6/20/2016 7:00:00 AM, 6/20/2016 11:00:00 AM
6, Machine, Phil, 6/20/2016 5:00:00 AM, 6/20/2016 3:00:00 PM
7, Machine, John, 6/21/2016 6:00:00 AM, 6/21/2016 12:00:00 PM
8, Paint, Tom, 6/25/2016 8:00:00 AM, 6/20/2016 8:00:00 PM
9, Paint, Chris, 6/25/2016 7:00:00 AM, 6/20/2016 3:00:00 PM
];
final:
load RowNo(),
Work_Type, Clock_In, Clock_Out,
Run_Hr
;
load Work_Type,Employee, max(Clock_In) as Clock_In, Max(Clock_Out)as Clock_Out,
sum(Run_Hr) as Run_Hr
resident Labor_Table
group by Work_Type,Employee ;
drop Table Labor_Table;
This works perfect. But that is for total run hours worked on the machine.
What I am trying to do is remove the overlap. so if 2 people are working at the same time for 8 hours the machine is only running for 8 hours and not 16.
Thank you so much.
maybe helpful:
IntervalMatch and Slowly Changing Dimensions
(see page 17 for interval partitioning)
regards
Marco