def parse_locust_stats(env):
    """
    Turn the locust stats into more print-friendly data.
    """
    stats = env.runner.stats
    statistics = {
        "requests": {},
        "failures": {},
        "num_requests": stats.num_requests,
        "num_requests_fail": stats.num_failures,
    }

    for name, value in stats.entries.items():
        locust_task_name = "{0}_{1}".format(name[1], name[0])
        statistics["requests"][locust_task_name] = {
            "num_requests": value.num_requests,
            "min_response_time": value.min_response_time,
            "median_response_time": value.median_response_time,
            "avg_response_time": value.avg_response_time,
            "max_response_time": value.max_response_time,
            "total_rps": value.total_rps,
        }

    for id, error in env.runner.errors.items():
        error_dict = error.to_dict()
        locust_task_name = "{0}_{1}".format(
            error_dict["method"], error_dict["name"]
        )
        statistics["failures"][locust_task_name] = error_dict

    return statistics