tessl install tessl/pypi-pyrate-limiter@3.9.0Python Rate-Limiter using Leaky-Bucket Algorithm for controlling request rates in applications with multiple backend storage options.
Agent Success
Agent success rate when using this tile
81%
Improvement
Agent success rate improvement when using this tile compared to baseline
1.45x
Baseline
Agent success rate without this tile
56%
Build a simple request timing monitor that tracks elapsed time between requests using a monotonic clock source to ensure accuracy even when system time changes.
Your task is to implement a RequestMonitor class that:
The monitor should work correctly even if the system clock is adjusted (e.g., due to NTP synchronization or daylight saving time changes).
Create a RequestMonitor class with the following behavior:
record_request(): Records the timestamp of a new requestget_last_elapsed(): Returns the elapsed time in milliseconds since the previous request, or None if this is the first requestget_average_interval(): Returns the average time interval in milliseconds between all recorded requests, or None if fewer than 2 requests have been recordedget_request_count(): Returns the total number of recorded requests@generates
class RequestMonitor:
"""Monitors request timing using monotonic clock source."""
def __init__(self):
"""Initialize a new request monitor."""
pass
def record_request(self) -> None:
"""Record a new request timestamp."""
pass
def get_last_elapsed(self) -> float | None:
"""
Get elapsed time in milliseconds since the previous request.
Returns:
Elapsed time in milliseconds, or None if this is the first request.
"""
pass
def get_average_interval(self) -> float | None:
"""
Get average time interval in milliseconds between all requests.
Returns:
Average interval in milliseconds, or None if fewer than 2 requests.
"""
pass
def get_request_count(self) -> int:
"""
Get the total number of recorded requests.
Returns:
Number of recorded requests.
"""
passProvides monotonic clock implementation for accurate timing.
@satisfied-by