Query editor
WITHprogram_compute AS (SELECTsplit(log, ' ')[2] AS program_id,CAST(split(log, ' ')[4] AS BIGINT) AS computed_units_spent,CAST(split(log, ' ')[6] AS BIGINT) AS computed_units_allocated,block_slot,block_time,id,fee,successFROM solana.transactions tCROSS JOIN UNNEST(log_messages) AS l(log)WHERE log LIKE 'Program % consumed % of % compute units'AND t.block_time >= now() - INTERVAL '{{hours}}' HOUR),block_cu AS (SELECTr.blockslot AS slot,reduce(transform(r.transactions,x -> coalesce(x.meta.computeunitsconsumed, 0)),BIGINT '0',(s, x) -> s + x,s -> s) AS total_block_cuFROM solana.raw_0003 rJOIN solana.blocks bON b.slot = r.blockslotWHERE b.time > now() - INTERVAL '{{hours}}' HOUR),avg_block AS (SELECTprogram_id,avg(total_cu) AS average_compute_per_block,avg(CAST(total_cu AS DOUBLE)/ nullif(CAST(total_block_cu AS DOUBLE), 0)) AS average_percent_compute_per_blockFROM (SELECTpc.program_id,pc.block_slot,bc.total_block_cu,sum(pc.computed_units_spent) AS total_cuFROM program_compute pcLEFT JOIN block_cu bcON pc.block_slot = bc.slotGROUP BYpc.program_id,pc.block_slot,bc.total_block_cu)GROUP BY program_id)