def __reduce_metrics_by(metrics):
    """
    Auxiliary function used to reduce the metrics by the keys in a dictionary
    Example reduce by turn or by query_type
    metrics - dict with keys as the reduce type and each value is a tuple (dict_metrics, number_turns),
    dic_metrics is a dict with the name of the metric as key and a value
    """
    final_metrics = {}
    for turn, value in metrics.items():
        if turn not in final_metrics:
            final_metrics[turn] = {}
        for k, v in value[0].items():  # value[0] is the metrics
            final_metrics[turn][k] = v / value[1]  # value[1] is the number turns
        final_metrics[turn]["number_tuns"] = value[1]
    return final_metrics