Пример #1
0
def _aggregate_miner_data(raw_data):
    data_by_miner = groupby(0, raw_data)

    for miner, miner_data in data_by_miner.items():
        _, block_hashes, gas_prices = map(set, zip(*miner_data))
        try:
            price_percentile = percentile(gas_prices, percentile=20)
        except InsufficientData:
            price_percentile = min(gas_prices)
        yield MinerData(miner, len(set(block_hashes)), min(gas_prices),
                        price_percentile)
Пример #2
0
def _aggregate_miner_data(
    raw_data: Iterable[Tuple[ChecksumAddress, Hash32, Wei]]
) -> Iterable[MinerData]:
    data_by_miner = groupby(0, raw_data)

    for miner, miner_data in data_by_miner.items():
        _, block_hashes, gas_prices = map(set, zip(*miner_data))
        try:
            price_percentile = percentile(gas_prices, percentile=20)
        except InsufficientData:
            price_percentile = min(gas_prices)
        yield MinerData(miner, len(set(block_hashes)), min(gas_prices),
                        price_percentile)
Пример #3
0
def _aggregate_miner_data(
    raw_data: Iterable[Tuple[ChecksumAddress, HexBytes, Wei]]
) -> Iterable[MinerData]:
    data_by_miner = groupby(0, raw_data)

    for miner, miner_data in data_by_miner.items():
        _, block_hashes, gas_prices = map(set, zip(*miner_data))
        try:
            # types ignored b/c mypy has trouble inferring gas_prices: Sequence[Wei]
            price_percentile = percentile(gas_prices,
                                          percentile=20)  # type: ignore
        except InsufficientData:
            price_percentile = min(gas_prices)  # type: ignore
        yield MinerData(miner, len(set(block_hashes)), min(gas_prices),
                        price_percentile)
Пример #4
0
def test_fuzz_test_percentiles(values, p):
    if not values:
        with pytest.raises(ValueError):
            percentile(values, p)
    else:
        percentile(values, p)
Пример #5
0
def test_percentiles_with_out_of_bounds_fractions():
    assert 1 == percentile([1, 2, 3, 4], percentile=10)
    assert 1 == percentile([1, 2, 3, 4], percentile=15)
    assert 1 == percentile([1, 2, 3, 4], percentile=20)
    assert 1 == percentile([1, 2, 3, 4], percentile=25)
    assert 1 < percentile([1, 2, 3, 4], percentile=30)
Пример #6
0
def test_percentiles_with_no_values():
    with pytest.raises(InsufficientData):
        percentile([], 1)
Пример #7
0
def test_percentiles_out_of_one_hundred(p, expected):
    assert percentile(values, p) == expected