monkey_wrench.query._base module

class monkey_wrench.query._base.LogMixin(log_context: str = '')[source]

Bases: object

__init__(log_context: str = '') None[source]

Make an instance of the class.

Parameters:

log_context – A string that will be used in log messages to determine the context. Defaults to an empty string.

property log_context: str

Get the log context as a string.

log_message(start_datetime: datetime, end_datetime: datetime, other: str = '') None[source]

Log a query message including the start and end datetime values as well as other information (if any).

class monkey_wrench.query._base.Query(*args, **kwargs)[source]

Bases: ABC, LogMixin

Abstract base class for queries.

__init__(*args, **kwargs) None[source]

Make an instance of the class.

abstractmethod static len(items: Any) Annotated[int, Ge(ge=0)][source]

Get the size (number) of items, e.g. the Python built-in len() function in case of a list.

abstractmethod query(datetime_period: DateTimePeriod) Any[source]

Query the specified time period.

query_in_batches(datetime_range_in_batches: DateTimeRangeInBatches, expected_total_count: Annotated[int, Ge(ge=0)] | None = None) Generator[tuple[T, int], None, None][source]

Divide the specified time range into smaller intervals (batches) and perform queries on them.

The arguments are the same as DatetimeRangeInBatches. If expected_total_count is given, it will be compared with total_retrieved_count and if they are not equal, a warning will be logged. It defaults to None which means no comparison is made.

Yields:

The result of queries, in the form of 2-tuples in which the first element is the retrieved items from the query() function in each batch and the second element is the size of the items in the batch.