Пример #1
0
    def show_score(self, head, wpm_score, stats, cpm_flag):
        """Show score screen after typing has finished."""
        if not self.redraw:
            return

        self.update_header(head)
        self.update_quote(Screen.COLOR_CORRECT)
        self.update_author()

        # Highlight score
        if cpm_flag:
            wpm_score = wpm_to_cpm(wpm_score)
            score = "You scored %.1f CPM!" % wpm_score
        else:
            score = "You scored %.1f WPM!" % wpm_score

        self.update_prompt(score)
        if len(score) < self.columns:
            self.chgat(11, self.cheight, len(str("%.1f" % wpm_score)),
                       Screen.COLOR_HISCORE)

        self.show_help()
        self.show_stats(stats, cpm_flag)
        self.set_cursor(0, 2)
        self.redraw = False
Пример #2
0
    def show_stats(self, stats, cpm_flag):
        """Shows statistics for the current quote."""
        results = stats.text_id_results(stats.tag, self.quote_id)

        if len(results) < 2:
            return

        percent = self.config.wpm.confidence_level
        assert 0.0 <= percent <= 1.0
        alpha = 1.0 - percent
        samples = len(results)

        wpm_avg, acc_avg = results.averages()
        wpm_sd, acc_sd = results.stddevs()
        wpm_min, wpm_max, acc_min, acc_max = results.extremals()

        wpm_ci0, wpm_ci1 = confidence_interval(wpm_avg, wpm_sd, samples, alpha)
        wpm_pi0, wpm_pi1 = prediction_interval(wpm_avg, wpm_sd, alpha)

        acc_ci0, acc_ci1 = confidence_interval(acc_avg, acc_sd, samples, alpha)
        acc_pi0, acc_pi1 = prediction_interval(acc_avg, acc_sd, alpha)

        if cpm_flag:
            wpm_avg = wpm_to_cpm(wpm_avg)
            wpm_sd = wpm_to_cpm(wpm_sd)
            wpm_min = wpm_to_cpm(wpm_min)
            wpm_max = wpm_to_cpm(wpm_max)
            wpm_ci0 = wpm_to_cpm(wpm_ci0)
            wpm_ci1 = wpm_to_cpm(wpm_ci1)
            wpm_pi0 = wpm_to_cpm(wpm_pi0)
            wpm_pi1 = wpm_to_cpm(wpm_pi1)

        if cpm_flag:
            msg = "cpm %5.1f min %5.1f avg %5.1f max %5.1f sd %2d%% ci [%5.1f-%5.1f] [%5.1f-%5.1f] pi (n=%d)"
        else:
            msg = "wpm %5.1f min %5.1f avg %5.1f max %5.1f sd %2d%% ci [%5.1f-%5.1f] [%5.1f-%5.1f] pi (n=%d)"
        msg %= (wpm_min, wpm_avg, wpm_max, wpm_sd, 100 * percent, wpm_ci0,
                wpm_ci1, wpm_pi0, wpm_pi1, samples)
        self.cheight += 2
        self.addstr(0, self.cheight, msg, Screen.COLOR_CORRECT)

        msg = "acc %5.1f min %5.1f avg %5.1f max %5.1f sd %2d%% ci [%5.1f %5.1f] [%5.1f %5.1f] pi (n=%d)" % (
            100 * acc_min, 100 * acc_avg, 100 * acc_max, 100 * acc_sd,
            100 * percent, 100 * acc_ci0, 100 * acc_ci1, 100 * acc_pi0,
            100 * acc_pi1, samples)
        self.cheight += 1
        self.addstr(0, self.cheight, msg, Screen.COLOR_CORRECT)
        self.cheight += 1

        if devfeature.histogram:
            self.show_histogram(stats)
Пример #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          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))
Пример #4
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))