import texttable

from wally.utils import ssize2b
from wally.statistic import round_3_digit
from .fio_task_parser import get_test_sync_mode


def getconc(data):
    th_count = data.params.vals.get('numjobs')

    if th_count is None:
        th_count = data.params.vals.get('concurence', 1)
    return th_count


def key_func(data):
    p = data.params.vals

    th_count = getconc(data)

    return (data.name.rsplit("_", 1)[0],
            p['rw'],
            get_test_sync_mode(data.params),
            ssize2b(p['blocksize']),
            int(th_count) * data.testnodes_count)


def format_results_for_console(dinfo):
    """
    create a table with io performance report
    for console
    """
    tab = texttable.Texttable(max_width=120)
    tab.set_deco(tab.HEADER | tab.VLINES | tab.BORDER)
    tab.set_cols_align(["l", "l", "r", "r", "r", "r", "r", "r", "r"])

    items = sorted(dinfo.values(), key=key_func)

    prev_k = None
    header = ["Name", "Description", "iops\ncum", "KiBps\ncum",
              "Cnf\n95%", "Dev%", "iops\nper vm", "KiBps\nper vm", "lat\nms"]

    for data in items:
        curr_k = key_func(data)[:4]

        if prev_k is not None:
            if prev_k != curr_k:
                tab.add_row(
                    ["-------", "-----------", "-----", "------",
                     "---", "----", "------", "---", "-----"])

        prev_k = curr_k

        test_dinfo = dinfo[(data.name, data.summary)]

        iops, _ = test_dinfo.iops.rounded_average_conf()

        bw, bw_conf = test_dinfo.bw.rounded_average_conf()
        _, bw_dev = test_dinfo.bw.rounded_average_dev()
        conf_perc = int(round(bw_conf * 100 / bw))
        dev_perc = int(round(bw_dev * 100 / bw))

        lat, _ = test_dinfo.lat.rounded_average_conf()
        lat = round_3_digit(int(lat) // 1000)

        iops_per_vm = round_3_digit(iops / data.testnodes_count)
        bw_per_vm = round_3_digit(bw / data.testnodes_count)

        iops = round_3_digit(iops)
        bw = round_3_digit(bw)

        params = (data.name.rsplit('_', 1)[0],
                  data.summary, int(iops), int(bw), str(conf_perc),
                  str(dev_perc),
                  int(iops_per_vm), int(bw_per_vm), lat)
        tab.add_row(params)

    tab.header(header)

    return tab.draw()
