def sumstat(fh, delimiter, reverse=False, **kwargs):
    counts = []
    N, M = 0, 0

    for line in imap(lambda x: x.strip(), fh):
        try:
            row = line.split(delimiter, 1)
            count = row[0]
        except ValueError:
            logging.exception("Exception while trying to parse log line: '%s', skipping", line)  # noqa
        else:
            count = int(count)
            counts.append(count)
            M += 1
            N += count

    if reverse is True:
        logging.info("Reversing row ordering")
        counts.reverse()

    avg = arith_mean(counts)
    minv, maxv = min(counts), max(counts)

    # Percentiles
    percentiles_idx = [M/10, M/4, M/2, 3*M/4, 9*M/10, 95*M/100, 99*M/100, 999*M/1000]  # noqa
    percentiles = map(lambda x: "%d (Idx: %s)" %
                      (counts[x], locale.format('%d', x, True)),
                      percentiles_idx)

    S10th, S25th, S40th, S50th, S75th, S90th = None, None, None, None, None, None  # noqa
    accum = 0.
    for idx, c in enumerate(reversed(counts)):
        accum += c
        if not S10th and accum/N >= 0.1:
            S10th = idx+1
        elif not S25th and accum/N >= 0.25:
            S25th = idx+1
        elif not S40th and accum/N >= 0.4:
            S40th = idx+1
        elif not S50th and accum/N >= 0.5:
            S50th = idx+1
        elif not S75th and accum/N >= 0.75:
            S75th = idx+1
        elif not S90th and accum/N >= 0.9:
            S90th = idx+1

    return {
        "M": M,
        "N": N,
        "avg": avg,
        "min": minv,
        "max": maxv,
        "percentiles": percentiles,
        "cover": [S10th, S25th, S40th, S50th, S75th, S90th]
        }
dataset/ETHPy150Open adamhadani/logtools/logtools/_sumstat.py/sumstat/original