Ejemplo n.º 1
0
def test_norm_regression():
    stats = Stats(NORM_DATA)

    assert stats.format_histogram(width=80) == NORM_DATA_FREEDMAN_OUTPUT
    assert stats.format_histogram(10, width=80) == NORM_DATA_TEN_BIN_OUTPUT

    subpar_bin_out = stats.format_histogram([12.0], width=80)
    assert subpar_bin_out == NORM_DATA_SINGLE_SUBPAR_BIN_OUTPUT

    format_bin_out = stats.format_histogram(5,
                                            width=80,
                                            format_bin=lambda b: '%sms' % b)
    assert format_bin_out == NORM_DATA_FORMAT_BIN_OUTPUT
Ejemplo n.º 2
0
def test_check_sum():
    for data in ALL_DATASETS:
        for bin_size in [0, 1, 10, 99]:
            # bin_size=0 tests freedman
            stats = Stats(data)
            hist_counts = stats.get_histogram_counts()
            hist_counts_sum = sum([c for _, c in hist_counts])
            assert len(data) == hist_counts_sum
            if not data:
                continue

            assert min(data) >= hist_counts[0][0]
            assert max(data) >= hist_counts[-1][0]
    return
Ejemplo n.º 3
0
def test_check_sum():
    for data in ALL_DATASETS:
        for bin_size in [0, 1, 10, 99]:
            # bin_size=0 tests freedman
            stats = Stats(data)
            hist_counts = stats.get_histogram_counts()
            hist_counts_sum = sum([c for _, c in hist_counts])
            assert len(data) == hist_counts_sum
            if not data:
                continue

            assert min(data) >= hist_counts[0][0]
            assert max(data) >= hist_counts[-1][0]
    return
Ejemplo n.º 4
0
def _get_route_stats(rt_hits):
    ret = {}
    for status, hits in rt_hits.items():
        ret[status] = cur = {}
        durs = [round(h.duration * 1000, 2) for h in hits]
        stats = Stats(durs, use_copy=False)
        desc_dict = stats.describe(quantiles=[0.25, 0.5, 0.75, 0.95, 0.99],
                                   format="dict")
        desc_dict[
            'count'] = hits.total_count  # need to account for reservoir count
        desc_dict['last_hit'] = datetime.datetime.fromtimestamp(
            hits.last_hit).isoformat()
        desc_dict['total_duration'] = round(hits.total_duration * 1000, 2)
        cur.update(desc_dict)
    return ret
Ejemplo n.º 5
0
def test_stats_basic():
    da = Stats(range(20))
    assert da.mean == 9.5
    assert round(da.std_dev, 2) == 5.77
    assert da.variance == 33.25
    assert da.skewness == 0
    assert round(da.kurtosis, 1) == 1.9
    assert da.median == 9.5
Ejemplo n.º 6
0
def test_norm_regression():
    stats = Stats(NORM_DATA)

    assert stats.format_histogram(width=80) == NORM_DATA_FREEDMAN_OUTPUT
    assert stats.format_histogram(10, width=80) == NORM_DATA_TEN_BIN_OUTPUT

    subpar_bin_out = stats.format_histogram([12.0], width=80)
    assert subpar_bin_out == NORM_DATA_SINGLE_SUBPAR_BIN_OUTPUT

    format_bin_out = stats.format_histogram(5,
                                            width=80,
                                            format_bin=lambda b: '%sms' % b)
    assert format_bin_out == NORM_DATA_FORMAT_BIN_OUTPUT
Ejemplo n.º 7
0
def main():
    print(Stats(NORM_DATA).format_histogram(10))