Class ConnectionLimitCalculation

java.lang.Object
energy.eddie.aiida.utils.ConnectionLimitCalculation

public final class ConnectionLimitCalculation extends Object
Provides effectiveLimits() to calculate which limits apply when during the requested time frame and scope.

Limits are scoped by permission id and meter id and may overlap within the same scope. When multiple limits overlap, the limit with the newest createdAt timestamp takes precedence.

The calculation is performed independently for each scope using a sweep-line algorithm:

  1. Create start and end events for all limits.
  2. Sweep chronologically through the requested interval.
  3. Maintain the currently active limits per event.
  4. Select the active limit with the newest createdAt.
  5. Emit effective time segments.

If no limit is active for a segment, the scope default is used when available. If neither limits nor a default exist for a scope, no segment is emitted.

If multiple active limits share the same newest creation timestamp, the most recently inserted is used.