Building Entry Time Calculation

2 weeks ago 13
ARTICLE AD BOX

I have a scenario to extract the hours inside a building along with the first in-time and last out-time for a particular day from the building access card reader report.

Sample Report:

Emp ID DATE Type Time
ABC 18-12-2025 Entry 12:41:21
ABC 18-12-2025 Exit 13:40:12
ABC 18-12-2025 Entry 14:11:41
ABC 18-12-2025 Exit 16:59:53
DEF 08-12-2025 Entry 09:58:48
DEF 08-12-2025 Exit 15:41:35
DEF 08-12-2025 Entry 15:41:46
DEF 08-12-2025 Exit 16:59:55
IJK 09-12-2025 Entry 10:10:56
IJK 09-12-2025 Exit 12:37:18
IJK 11-12-2025 Entry 10:01:44
IJK 11-12-2025 Exit 12:18:00
IJK 15-12-2025 Entry 09:49:50
IJK 15-12-2025 Exit 11:08:56
IJK 15-12-2025 Entry 11:29:32
IJK 15-12-2025 Exit 12:47:01
IJK 15-12-2025 Entry 12:47:16
IJK 15-12-2025 Exit 12:47:57
XYZ 16-12-2025 Entry 10:38:58
XYZ 16-12-2025 Exit 11:15:20
XYZ 16-12-2025 Entry 16:27:28

Expected Output:

Emp ID DATE Type Time First InTime Last Out Time Total Hours Hours Inside
ABC 18-12-2025 Entry 12:41:21 12:41:21 16:59:53 04:18:32 03:18:00
ABC 18-12-2025 Exit 13:40:12 12:41:21 16:59:53 04:18:32 03:18:00
ABC 18-12-2025 Entry 14:11:41 12:41:21 16:59:53 04:18:32 03:18:00
ABC 18-12-2025 Exit 16:59:53 12:41:21 16:59:53 04:18:32 03:18:00
DEF 08-12-2025 Entry 09:58:48 09:58:48 16:59:55 07:01:07 05:01:00
DEF 08-12-2025 Exit 15:41:35 09:58:48 16:59:55 07:01:07 05:01:00
DEF 08-12-2025 Entry 15:41:46 09:58:48 16:59:55 07:01:07 05:01:00
DEF 08-12-2025 Exit 16:59:55 09:58:48 16:59:55 07:01:07 05:01:00
IJK 09-12-2025 Entry 10:10:56 10:10:56 12:37:18 02:26:22 00:52:00
IJK 09-12-2025 Exit 12:37:18 10:10:56 12:37:18 02:26:22 00:52:00
IJK 11-12-2025 Entry 10:01:44 10:01:44 12:18:00 02:16:16 01:23:00
IJK 11-12-2025 Exit 12:18:00 10:01:44 12:18:00 02:16:16 01:23:00
IJK 15-12-2025 Entry 09:49:50 09:49:50 12:47:57 02:58:07 01:30:00
IJK 15-12-2025 Exit 11:08:56 09:49:50 12:47:57 02:58:07 01:30:00
IJK 15-12-2025 Entry 11:29:32 09:49:50 12:47:57 02:58:07 01:30:00
IJK 15-12-2025 Exit 12:47:01 09:49:50 12:47:57 02:58:07 01:30:00
IJK 15-12-2025 Entry 12:47:16 09:49:50 12:47:57 02:58:07 01:30:00
IJK 15-12-2025 Exit 12:47:57 09:49:50 12:47:57 02:58:07 01:30:00
XYZ 16-12-2025 Entry 10:38:58 10:38:58 11:15:20 00:36:22 01:30:00
XYZ 16-12-2025 Exit 11:15:20 10:38:58 11:15:20 00:36:22 01:30:00
XYZ 16-12-2025 Entry 16:27:28 10:38:58 11:15:20 00:36:22 01:30:00

I was able to do the coding for getting the first and last access details using the below script:

def compute_day(group: pd.DataFrame): # First Entry / Last Exit first_entry = group['ENTRY_TS'].min() last_exit = group['ENTRY_TS'].max()

I am unable to get a logic/ code for checking the hours inside the building. It should be - differential time between Exit and Entry in between the first Entry and the Last Exit.

Please help

Read Entire Article