I've been working on this problem for a few days now and cannot find a way to solve it.
blockstart | blockend | next_blockstart | ADUserGuid | DispositionId | WorkflowId | StartDate | EndDate |
---|---|---|---|---|---|---|---|
2023-10-01 05:00:00.00 | 2023-10-01 05:14:59.000 | 2023-10-01 05:15:00.000 | 123e4567-e89b-12d3-a456-426614174000 | 101 | 1001 | 2023-10-01 05:00:01.00 | 2023-10-01 05:14:58.000 |
2023-10-01 05:15:00.00 | 2023-10-01 05:29:59.000 | 2023-10-01 05:30:00.000 | 123e4567-e89b-12d3-a456-426614174001 | 102 | 1002 | 2023-10-01 05:15:01.00 | 2023-10-01 05:29:58.000 |
2023-10-01 05:30:00.00 | 2023-10-01 05:44:59.000 | 2023-10-01 05:45:00.000 | 123e4567-e89b-12d3-a456-426614174002 | 103 | 1003 | 2023-10-01 05:30:01.00 | 2023-10-01 05:44:58.000 |
2023-10-01 05:30:00.00 | 2023-10-01 05:59:59.000 | 2023-10-01 06:00:00.000 | 123e4567-e89b-12d3-a456-426614174003 | 104 | 1004 | 2023-10-01 05:30:01.00 | 2023-10-01 05:59:58.000 |
Above is a small sample of some of the data I am working with.
Basically, I am working with a full years worth of data that is recording technician productivity. Technicians will begin work on a report that comes in to our system denoted by StartDate, and complete the report denoted by EndDate.
The BlockStart and BlockEnd columns are two columns I have created. The purpose of the columns is to divide a 24 hour day into 15 minute blocks of time so that we can determine "in this quarter hour window, how many reports did a technician complete? How many did they begin? How many did they finish? What was their productivity? How many minutes were they not actively working on reports (i.e. bathroom breaks, lunch, etc.).
A 15 minute block of time translates into 900 seconds (here I am using 899).
There are a couple scenarios here:
- A technician starts and finishes a report within one quarter hour block
- A technician starts a report in one quarter hour block and finishes in another (later) quarter hour block.
Reports can take anywhere from 5 minutes to over an hour (60 minutes would be 4 quarter hour blocks (4 x 15 = 60 min).
My job is to create a new column and calculate the time it takes a technician to complete a report, this field will be called "ElapsedSeconds" and is the difference in seconds between the StartDate and the EndDate.
However, let's say a technician starts a report at 7:10PM (falls within the 7:00 quarter hour block) and doesn't finish until 7:55PM -> 45 minutes have elapsed starting in the 7:00PM quarter hour block and ending in the 7:45PM quarter hour block. ElapsedSeconds would then be 45 x 60 = 2700 seconds.
BUT! How would I show actual ElapsedSeconds across the multiple quarter hour blocks?
For example, if the report was started at 7:10 in the 7:00 quarter hour block, they would have worked 5 minutes (or 300 seconds) in that block, the 7:15-7:30 blocks would be the full 900 seconds (a technician cannot possibly have more productive seconds than 900 per quarter hour block).
So at the beginning of the 7:15 quarter hour block, we would subtract the 300 seconds that have elapsed from the 2700 total for a difference of 2400 seconds remaining. This remaining time should then be allocated to the next quarter hour block, and any remaining time (time exceeding 900 seconds) should be allocated to the next block, etc.
How can I do this?
Another caveat is that sometimes technicians open multiple reports, in which case they will have multiple elapsed times for each quarter hour block that exceeds 900 seconds, in which case I need to record those and allocate any excess to the next block as with the above.
I have been on ChatGPT, and worked various ways of accomplishing this. My boss has been pressuring me to complete this as I have been working on it all week but I feel like I am at a loss.
Example output:
TechnicianID | StartTime | EndTime | BlockStart | BlockEnd | TotalDurationSeconds | ProductiveSeconds |
---|---|---|---|---|---|---|
1 | 2023-10-01 05:00:00 | 2023-10-01 05:10:00 | 2023-10-01 05:00:00 | 2023-10-01 05:15:00 | 600 | 600 |
1 | 2023-10-01 05:10:00 | 2023-10-01 05:25:00 | 2023-10-01 05:00:00 | 2023-10-01 05:15:00 | 900 | 300 |
1 | 2023-10-01 05:15:00 | 2023-10-01 05:25:00 | 2023-10-01 05:15:00 | 2023-10-01 05:30:00 | 900 | 600 |
1 | 2023-10-01 06:00:00 | 2023-10-01 06:45:00 | 2023-10-01 06:00:00 | 2023-10-01 06:15:00 | 2700 | 900 |
1 | 2023-10-01 06:15:00 | 2023-10-01 06:45:00 | 2023-10-01 06:15:00 | 2023-10-01 06:30:00 | 2700 | 900 |
1 | 2023-10-01 06:30:00 | 2023-10-01 06:45:00 | 2023-10-01 06:30:00 | 2023-10-01 06:45:00 | 2700 | 900 |
2 | 2023-10-01 05:05:00 | 2023-10-01 05:20:00 | 2023-10-01 05:00:00 | 2023-10-01 05:15:00 | 900 | 600 |
2 | 2023-10-01 05:15:00 | 2023-10-01 05:20:00 | 2023-10-01 05:15:00 | 2023-10-01 05:30:00 | 900 | 300 |
2 | 2023-10-01 05:30:00 | 2023-10-01 05:35:00 | 2023-10-01 05:30:00 | 2023-10-01 05:45:00 | 300 | 300 |
2 | 2023-10-01 07:00:00 | 2023-10-01 07:50:00 | 2023-10-01 07:00:00 | 2023-10-01 07:15:00 | 3000 | 900 |
2 | 2023-10-01 07:15:00 | 2023-10-01 07:50:00 | 2023-10-01 07:15:00 | 2023-10-01 07:30:00 | 3000 | 900 |
2 | 2023-10-01 07:30:00 | 2023-10-01 07:50:00 | 2023-10-01 07:30:00 | 2023-10-01 07:45:00 | 3000 | 900 |
2 | 2023-10-01 07:45:00 | 2023-10-01 07:50:00 | 2023-10-01 07:45:00 | 2023-10-01 08:00:00 | 3000 | 300 |
3 | 2023-10-01 05:45:00 | 2023-10-01 06:00:00 | 2023-10-01 05:45:00 | 2023-10-01 06:00:00 | 900 | 900 |
3 | 2023-10-01 08:15:00 | 2023-10-01 09:00:00 | 2023-10-01 08:15:00 | 2023-10-01 08:30:00 | 2700 | 900 |
3 | 2023-10-01 08:30:00 | 2023-10-01 09:00:00 | 2023-10-01 08:30:00 | 2023-10-01 08:45:00 | 2700 | 900 |
3 | 2023-10-01 08:45:00 | 2023-10-01 09:00:00 | 2023-10-01 08:45:00 | 2023-10-01 09:00:00 | 2700 | 900 |
Something like this (this is the result of one of my attempts)
Except, there would only be one litem per UserId/QuarterHourBlock/DispositionId/WorkflowId