activity.matching.utils

Attributes

OrderT

Classes

LoopBudget

Helps ensure that a loop doesn't overreach its complexity budget.

HashableID

Functions

overlaps(→ bool)

Returns true if the given booking overlaps with the given booking

booking_order(→ tuple[decimal.Decimal, int, uuid.UUID])

Keeps the bookings predictably sorted from highest to lowest priority.

unblockable(→ SortedKeySet[Booking, OrderT])

Returns a set of items in the blocked set which do not block

Module Contents

activity.matching.utils.OrderT[source]
activity.matching.utils.overlaps(booking: onegov.activity.models.Booking, other: Booking | Occasion, minutes_between: float = 0, alignment: Literal['day', 'week', 'month'] | None = None, with_anti_affinity_check: bool = False) bool[source]

Returns true if the given booking overlaps with the given booking or occasion.

class activity.matching.utils.LoopBudget(max_ticks: int)[source]

Helps ensure that a loop doesn’t overreach its complexity budget.

For example:

budget = LoopBudget(max_ticks=10)

while True:
    if budget.limit_reached():
        break
ticks = 0[source]
max_ticks[source]
limit_reached(as_exception: bool = False) bool | None[source]
class activity.matching.utils.HashableID[source]
id: collections.abc.Hashable[source]
__hash__() int[source]
__eq__(other: object) bool[source]
activity.matching.utils.booking_order(booking: onegov.activity.models.Booking) tuple[decimal.Decimal, int, uuid.UUID][source]

Keeps the bookings predictably sorted from highest to lowest priority.

activity.matching.utils.unblockable(accepted: Iterable[Booking], blocked: Iterable[Booking], key: Callable[[Booking], OrderT] = booking_order, with_anti_affinity_check: bool = False) SortedKeySet[Booking, OrderT][source]

Returns a set of items in the blocked set which do not block with anything. The set is ordered using booking_order().