def parse_wrk_output(output: str) -> dict:
    """
    Parse the terminal output of wrk into a dictionary. The output format is
    defined by write_lua() in the tests.

    Args:
        output (str): Raw terminal output from wrk

    Returns:
        dict: Organized results from wrk
    """
    lines = output.split("\n")
    raw_stats = lines[-4:-1]

    latencies = raw_stats[0].split(",")
    requests = raw_stats[1].split(",")
    summaries = raw_stats[2].split(",")

    stats = {
        "latencies": {},
        "requests": {},
        "summaries": {},
    }

    metrics = ["min", "max", "mean", "stdev"]
    metrics_summary = ["duration", "requests", "bytes"]

    for latency, label in zip(latencies[:2], metrics[:2]):
        stats["latencies"][label] = int(latency)
    for latency, label in zip(latencies[2:], metrics[2:]):
        stats["latencies"][label] = float(latency)

    for request, label in zip(requests[:2], metrics[:2]):
        stats["requests"][label] = int(request)
    for request, label in zip(requests[2:], metrics[2:]):
        stats["requests"][label] = float(request)

    for summary, label in zip(summaries, metrics_summary):
        stats["summaries"][label] = int(summary)

    return stats