Thomas Eapen · Selected work

Time buckets & boundary rules

Turn individual samples into reporting intervals while making the treatment of boundary values explicit.

Synthetic example · independently invented dataOne-page print edition · A3 landscape
01 Inspect the inputs02 Apply the method03 Check the result

INVENTED INPUTS

Eight samples on one timeline

Invented elapsed minutes and sample values
MinuteValue
02
21
54
73
92
105
141
152

Minute 0 is the start of the demonstration. Values are arbitrary units; no date or operational timeseries is used.

SELECTED PYTHON

The working calculation

Pandas is imported as pd. The lists minutes and values contain the inputs at left.

samples = pd.Series(
    values, index=pd.to_timedelta(minutes, unit='min')
)
totals = samples.resample(
    '5min', closed='left', label='left'
).sum()
assert totals.sum() == samples.sum()

The code shown here is executed to calculate this example’s results.

COMPUTED RESULT

Four reporting buckets

20units retainedInput total = output total
Sum in each five-minute bucket0–5 min: 3; 5–10 min: 9; 10–15 min: 6; 15–20 min: 2.0–5 min35–10 min910–15 min615–20 min2

The first bucket contains minutes 0 and 2. The sample at minute 5 belongs to the next bucket.

What this demonstratesA reporting interval needs an explicit start, width and boundary convention. Resampling keeps the aggregation separate from presentation.

Check the boundaryThese bins are left-closed: [0, 5), [5, 10), [10, 15), [15, 20). A boundary sample appears exactly once.