Ejemplo n.º 1
0
def print_stats(stats):
    """Prints table of game results."""
    table = []

    config = wpm.config.Config()
    percent = config.wpm.confidence_level
    assert (0.0 <= percent <= 1.0)

    for tag in sorted(stats.games.keys()):
        name = tag if tag is not None else "n/a"

        for last_n in [0, 10, 50, 100, 500, 1000]:
            results = stats.results(tag, last_n=last_n)

            if len(results) >= last_n:
                if last_n == 0:
                    label = len(results)
                else:
                    label = "n-%d" % last_n

                wpm_avg, acc_avg = results.averages()
                wpm_sd, acc_sd = results.stddevs()

                alpha = 1.0 - percent
                wpm_ci = confidence_interval(wpm_avg, wpm_sd, len(results),
                                             alpha)
                wpm_pi = prediction_interval(wpm_avg, wpm_sd, alpha)

                table.append([
                    name, label, wpm_avg, wpm_sd, 100.0 * acc_avg,
                    100.0 * acc_sd, wpm_ci[0], wpm_ci[1], wpm_pi[0], wpm_pi[1]
                ])

    if table:
        width = max(max(len(e[0]) for e in table), 11)
    else:
        width = 0

    head0 = "Tag          Games    WPM                                     Accuracy"
    head1 = "                      avg     sd     %2d%% ci      %2d%% pi       avg     sd   " % (
        100 * percent, 100 * percent)

    print("=" * len(head1))
    print(head0)
    print(head1)
    print("-" * len(head1))

    for entry in table:
        label, count, wpm_avg, wpm_sd, acc_avg, acc_sd, ci0, ci1, pi0, pi1 = entry
        print(
            "%-*s   %6s  %5.1f  %5.1f   %5.1f-%5.1f %5.1f-%5.1f %5.1f%%  %5.1f%%"
            % (width, label, count, wpm_avg, wpm_sd, ci0, ci1, pi0, pi1,
               acc_avg, acc_sd))

    print("=" * len(head1))
Ejemplo n.º 2
0
def print_stats(stats, cpm):
    """Prints table of game results."""
    table = []

    config = wpm.config.Config()
    percent = config.wpm.confidence_level

    for tag in sorted(stats.games.keys()):
        name = tag if tag is not None else "n/a"

        for last_n in [0, 10, 50, 100, 500, 1000]:
            results = stats.results(tag, last_n=last_n)

            if len(results) >= last_n:
                if last_n == 0:
                    label = len(results)
                else:
                    label = "n-%d" % last_n

                avg, acc_avg = results.averages()
                sd, acc_sd = results.stddevs()

                if cpm:
                    avg = wpm_to_cpm(avg)
                    sd = wpm_to_cpm(sd)

                alpha = 1.0 - percent
                ci = confidence_interval(avg, sd, len(results), alpha)
                pi = prediction_interval(avg, sd, alpha)

                table.append([name,
                              label,
                              avg,
                              sd,
                              100.0*acc_avg,
                              100.0*acc_sd,
                              ci[0],
                              ci[1],
                              pi[0],
                              pi[1]])

    if table:
        width = max(max(len(e[0]) for e in table), 11)
    else:
        width = 0

    head0 = "Tag          Games    %s                                     Accuracy" % ("CPM" if cpm else "WPM")
    head1 = "                      avg     sd     %2d%% ci      %2d%% pi       avg     sd   " % (100*percent, 100*percent)

    if cpm:
        head0 += "            "
        head1 += "            "

    print("="*len(head1))
    print(head0)
    print(head1)
    print("-"*len(head1))

    for entry in table:
        label, count, avg, sd, acc_avg, acc_sd, ci0, ci1, pi0, pi1 = entry
        if cpm:
            print("%-*s   %6s  %7.1f  %7.1f   %7.1f-%7.1f %7.1f-%7.1f %5.1f%%  %5.1f%%" %
                  (width, label, count, avg, sd, ci0, ci1, pi0, pi1, acc_avg, acc_sd))
        else:
            print("%-*s   %6s  %5.1f  %5.1f   %5.1f-%5.1f %5.1f-%5.1f %5.1f%%  %5.1f%%" %
                  (width, label, count, avg, sd, ci0, ci1, pi0, pi1, acc_avg, acc_sd))

    print("="*len(head1))
Ejemplo n.º 3
0
def print_stats(stats, cpm):
    """Prints table of game results."""
    table = []

    config = wpm.config.Config()
    percent = config.wpm.confidence_level

    for tag in sorted(stats.games.keys()):
        name = tag if tag is not None else "n/a"

        for last_n in [0, 10, 50, 100, 500, 1000]:
            results = stats.results(tag, last_n=last_n)

            if len(results) >= last_n:
                if last_n == 0:
                    label = len(results)
                else:
                    label = "n-%d" % last_n

                avg, acc_avg = results.averages()
                sd, acc_sd = results.stddevs()

                if cpm:
                    avg = wpm_to_cpm(avg)
                    sd = wpm_to_cpm(sd)

                alpha = 1.0 - percent
                ci = confidence_interval(avg, sd, len(results), alpha)
                pi = prediction_interval(avg, sd, alpha)

                table.append([name,
                              label,
                              avg,
                              sd,
                              100.0*acc_avg,
                              100.0*acc_sd,
                              ci[0],
                              ci[1],
                              pi[0],
                              pi[1]])

    if table:
        width = max(max(len(e[0]) for e in table), 11)
    else:
        width = 0

    head0 = "Tag          Gajes    %s                                     Accuracy" % ("CPM" if cpm else "WPM")
    head1 = "                      avg     sd     %2d%% ci      %2d%% pi       avg     sd   " % (100*percent, 100*percent)

    if cpm:
        head0 += "            "
        head1 += "            "

    print("="*len(head1))
    print(head0)
    print(head1)
    print("-"*len(head1))

    for entry in table:
        label, count, avg, sd, acc_avg, acc_sd, ci0, ci1, pi0, pi1 = entry
        if cpm:
            print("%-*s   %6s  %7.1f  %7.1f   %7.1f-%7.1f %7.1f-%7.1f %5.1f%%  %5.1f%%" %
                  (width, label, count, avg, sd, ci0, ci1, pi0, pi1, acc_avg, acc_sd))
        else:
            print("%-*s   %6s  %5.1f  %5.1f   %5.1f-%5.1f %5.1f-%5.1f %5.1f%%  %5.1f%%" %
                  (width, label, count, avg, sd, ci0, ci1, pi0, pi1, acc_avg, acc_sd))

    print("="*len(head1))