keshanPolygon performance 3
    Updated 2022-07-24
    SELECT
    hour,
    avg(timediff) as "Average Time difference",
    COUNT(block_number) as "Number of blocks",
    avg(moving_average) as "Rolling average time difference"
    FROM
    (SELECT
    date_trunc(hour, block_timestamp) as hour,
    timediff,
    block_number,
    avg(timediff) OVER(ORDER BY block_timestamp
    ROWS BETWEEN 100 PRECEDING AND CURRENT ROW )
    as moving_average
    FROM
    (SELECT
    block_number,
    block_timestamp,
    lag(block_timestamp, 1) OVER (ORDER BY block_timestamp) AS prev_time,
    timediff('second', prev_time, block_timestamp) AS timediff
    FROM polygon.core.fact_blocks
    ORDER BY block_number)
    WHERE prev_time is not null)
    group by hour
    Run a query to Download Data