flipsidecryptoBlocks, Bsc, Current
    Updated 2023-12-20
    -- forked from Blocks, Avalanche, Current @ https://flipsidecrypto.xyz/edit/queries/bfd435ee-cb8e-4323-993f-d52d4670181d

    with test_data as (
    select
    *,
    max(max_block) over (order by test_timestamp) -
    min(min_block) over (order by test_timestamp) + 1 as total_blocks_at_time
    from
    bi_analytics.core.fact_data_observability_results

    ),
    proportions as (
    select
    blockchain,
    test_name,
    test_timestamp,
    blocks_impacted_count / total_blocks_at_time as proportion_impacted
    from
    test_data
    )
    select
    blockchain,
    test_name,
    max(test_timestamp) as latest_test,
    proportion_impacted as incomplete,
    1 - proportion_impacted as complete
    from proportions
    where blockchain = 'bsc' and test_name = 'blocks'
    group by 1,2,4,5