Thomas Eapen · Selected work

From absence intervals to a clear report

A worked example that clips records to the reporting window, removes overlap within each person and allocates their absence to time periods.

Original report: Excel · Example calculations: PythonSynthetic example · independently invented data · One-page A3 landscape
570minutes in the five raw records
20minutes outside the reporting window
30overlapping minutes counted once

INVENTED INPUTS

Five records, four people

Synthetic intervals; analysis window 08:00–14:00
PersonStartEnd
A08:2010:20
A09:5010:50
B09:3012:10
C11:1513:45
D13:0014:20

Person A’s two records overlap by 30 minutes. Person D’s record extends 20 minutes beyond 14:00. Convert times to minute offsets before calculating.

Reporting periods are 08:00–10:00, 10:00–12:00 and 12:00–14:00.

SELECTED PYTHON

The calculation

records contains the input rows in minutes after 08:00. periods contains the three boundary pairs. merged_intervals merges overlapping records within one person. defaultdict is imported from collections.

def allocate_absence(records, periods):
    grouped = defaultdict(list)
    for record in records:
        grouped[record['person']].append(
            (record['start'], record['end'])
        )
    result = {}
    for person, intervals in sorted(grouped.items()):
        spans = merged_intervals(intervals)
        result[person] = [
            sum(max(0, min(end, right) - max(start, left))
                for start, end in spans)
            for left, right in periods
        ]
    return result

Extracted from the new helper that computes this example.

COMPUTED RESULT

Keep each person’s contribution

520person-minutes of absence
Person-minutes of absence in three reporting periodsThe periods contain 130, 215, 175 person-minutes, totalling 520. Person A contributes 100, 50, 0 minutes across the three periods; Person B contributes 30, 120, 10 minutes across the three periods; Person C contributes 0, 45, 105 minutes across the three periods; Person D contributes 0, 0, 60 minutes across the three periods. Overlaps within Person A’s records are counted once; different people contribute separately.08:00–10:0013010:00–12:0021512:00–14:00175Person-minutes · contributions by personPerson APerson BPerson CPerson D
Person-minutes of absence in three reporting periodsThe periods contain 130, 215, 175 person-minutes, totalling 520. Person A contributes 100, 50, 0 minutes across the three periods; Person B contributes 30, 120, 10 minutes across the three periods; Person C contributes 0, 45, 105 minutes across the three periods; Person D contributes 0, 0, 60 minutes across the three periods. Overlaps within Person A’s records are counted once; different people contribute separately.08:00–10:0013010:00–12:0021512:00–14:00175Person-minutes by personPerson APerson BPerson CPerson D

570 − 20 − 30 = 520. The three reporting periods sum to the same total.

Clip, deduplicate, then allocateThe interval calculation is max(0, min(end, period end) − max(start, period start)). Boundaries are half-open, so adjacent periods do not count the same minute twice.

Measure person-timeOverlapping records for one person count once. Absences of different people are summed separately, even when their clock times overlap. This is not the union of the whole team’s clock time.