"""
Practice: describe response time the way Lab 12's script 02 does. One average hides the slow
answers, so you'll compute percentiles, count who the average misleads, check a timeout against
another run, estimate an answer's total time, and measure how far thinking pushes the slow end.

Fill in the TODOs, then run the tests:
    pytest test_latency_practice.py        (locally)
or press "Run tests" on the chapter page.
"""


def percentile(times: list[float], pct: float) -> float:
    """The lab's nearest-rank percentile: sort the times, then take the one at rank
    round(pct / 100 * n), counting from 1 (at least 1, at most n). p50 is the middle,
    p95 the answer only 1 in 20 is slower than."""
    # TODO
    raise NotImplementedError


def slower_than_average(times: list[float]) -> int:
    """How many answers took longer than the average of all of them?"""
    # TODO
    raise NotImplementedError


def cut_off(times: list[float], timeout: float) -> int:
    """With the app giving up after `timeout` seconds, how many of these answers would it cut off?
    An answer that took exactly the timeout still arrives."""
    # TODO
    raise NotImplementedError


def total_time(first_token: float, output_tokens: int, tokens_per_s: float) -> float:
    """Roughly how long a whole answer takes: the wait for the first token, plus the time to
    write every token at a steady speed."""
    # TODO
    raise NotImplementedError


def slow_end(times: list[float]) -> float:
    """How far the slow end sits past the typical answer: p95 minus p50, in seconds,
    rounded to 2 decimals."""
    # TODO
    raise NotImplementedError
