<commit_before>#!/usr/bin/env python3
import os
import json
import uncertain
import sys

TIMINGS_DIR = 'collected'


def mean_latency(data):
    """Summarize the data from a single run."""
    all_latencies = []
    for msg in data['messages']:
        # As a sanity check, we can get an average frame latency for the
        # entire message with:
        # avg_latency = msg['ms'] / msg['frames']

        latencies = msg['latencies']
        all_latencies += latencies

        # TODO Skip the first message as a "warmup" period.

    return uncertain.umean(latencies)


def summarize(as_json):
    """Summarize all the collected data."""
    out = []
    for fn in os.listdir(TIMINGS_DIR):
        path = os.path.join(TIMINGS_DIR, fn)
        with open(path) as f:
            data = json.load(f)
        mean = mean_latency(data)

        if as_json:
            # Emit a Vega-ready data record.
            name, _ = os.path.splitext(os.path.basename(data['fn']))
            out.append({
                'name': name,
                'value': mean.value,
                'error': mean.error,
                'err_min': mean.value - mean.error,
                'err_max': mean.value + mean.error,
            })
        else:
            # Human-readable.
            print(data['fn'])
            print('frame latency:', mean, 'ms')
            print('fps:', 1000.0 / mean)

    if as_json:<commit_msg>Fix mean range<commit_after>#!/usr/bin/env python3
import os
import json
import uncertain
import sys

TIMINGS_DIR = 'collected'


def mean_latency(data):
    """Summarize the data from a single run."""
    all_latencies = []
    all_draw_latencies = []
    for msg in data['messages']:
        # As a sanity check, we can get an average frame latency for the
        # entire message with:
        # avg_latency = msg['ms'] / msg['frames']

        all_latencies += msg['latencies']
        all_draw_latencies += msg['draw_latencies']

        # TODO Skip the first message as a "warmup" period.

    return uncertain.umean(all_latencies)


def summarize(as_json):
    """Summarize all the collected data."""
    out = []
    for fn in os.listdir(TIMINGS_DIR):
        path = os.path.join(TIMINGS_DIR, fn)
        with open(path) as f:
            data = json.load(f)
        mean = mean_latency(data)

        if as_json:
            # Emit a Vega-ready data record.
            name, _ = os.path.splitext(os.path.basename(data['fn']))
            out.append({
                'name': name,
                'value': mean.value,
                'error': mean.error,
                'err_min': mean.value - mean.error,
                'err_max': mean.value + mean.error,
            })
        else:
            # Human-readable.
            print(data['fn'])
            print('frame latency:', mean, 'ms')
            print('fps:', 1000.0 / mean)

    if as_json:
{'fraction_non_alphanumeric': 0.1211277410372433, 'fraction_numerical': 0.004176818656456666, 'mean_word_length': 1.9148073022312373, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5859863', 'n_tokens_mistral': 908, 'n_tokens_neox': 861, 'n_words': 236}