"""
Practice: measuring a live speech-to-text stream.

A stream sends a series of SCREENS: what the captions show after each update.
Each screen is a list of words, e.g. ["Sancho", "got", "up"].

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


def send_times(n_chunks: int, chunk_ms: int = 80) -> list[float]:
    """When each audio chunk should leave the client, in seconds, to stream in REAL TIME:
    chunk k leaves at k * chunk_ms. Sending faster makes results arrive "before" a live
    speaker would even have finished, which is fiction.

    TODO 1
    """
    return []


def rewrites(screens: list[list[str]]) -> tuple[int, int]:
    """(words shown and later changed or removed, words shown in total).

    Compare each screen with the previous one, position by position:
      - a word on the old screen that is different or missing on the new one was REWRITTEN
      - a word on the new screen that is different from (or beyond) the old one was SHOWN
    New words appended at the end are shown, but they aren't rewrites.
    (The lab aligns screens with edit distance; position by position is enough here.)

    TODO 2
    """
    return 0, 0


def local_agreement(screens: list[list[str]]) -> list[list[str]]:
    """Buy stability with latency: show a word only once two CONSECUTIVE screens agree on it,
    and never take a shown word back.

    For each screen: the agreed words are the common prefix of this screen and the previous one.
    If the agreed prefix is longer than what's committed AND starts with what's committed,
    commit it. Return the committed words after each screen (one list per input screen).

    TODO 3
    """
    return [[] for _ in screens]


def cut_offs(pauses_s: list[float], timer_ms: int) -> list[bool]:
    """A silence timer ends the turn after timer_ms of silence. For each pause in the middle
    of a sentence, return True if the timer would cut the speaker off (pause longer than the timer).

    TODO 4
    """
    return [False for _ in pauses_s]
