Budget#

class council.contexts.Budget(duration: float, limits: List[Consumption] | None = None)[source]#

Bases: object

A class representing a budget with duration, limits, and consumption events.

__init__(duration: float, limits: List[Consumption] | None = None) None[source]#

Initialize the Budget object

Parameters:
  • duration (float) – The duration of the budget in some time unit (e.g., days, months, etc.).

  • limits (List[Consumption]) – Optional. A list of Consumption objects representing the budget limits. Each Consumption object contains a value, unit, and kind.

add_consumption(value: float, unit: str, kind: str)[source]#

adds/registers a consumption into the budget

add_consumptions(consumptions: Iterable[Consumption]) None[source]#

adds/registers many consumptions into the budget

can_consume(value: float, unit: str, kind: str) bool[source]#

returns True if the given consumption is allowed (will not exhaust the budget). False otherwise

property deadline: float#

the deadline of the budget, which when the budget expires

static default() Budget[source]#

Helper function that create a new Budget with a default value.

Returns:

Budget

property duration: float#

the initial duration of the budget

is_expired() bool[source]#

Check if the budget is expired :returns: True is the budget is expired. Otherwise False

property remaining_duration: float#

the remaining duration in the budget