Query editor
with ml_requests as (selectblock_time, varbinary_substring(topic1,1+12,20) as account -- 可以理解成calling contract, varbinary_to_uint256(topic2) as requestId, varbinary_to_uint256(varbinary_substring(data,1,32)) as modelId-- , varbinary_substring(data,1+2*32+12,20) as callbackContract -- 目前来看和topic1 account相同from {{blockchain}}.logswhere block_time between current_date - interval '{{backdays}}' day and current_date -- 选取最近几天的记录就可以and contract_address = 0x0A0f4321214BB6C7811dD8a71cF587bdaF03f0A0 -- OAO Proxyand topic0 = 0x849aa5adc3bf6a75cb08afbf31d88d1528c274e5d84e3d4355d23d8e9ebd649b -- AICallbackRequest), ml_result_back as (selectblock_time, varbinary_substring(topic1,1+12,20) as account -- 可以理解成calling contract, varbinary_to_uint256(topic2) as requestIdfrom {{blockchain}}.logswhere block_time between current_date - interval '{{backdays}}' day and current_date -- 选取最近几天的记录就可以and contract_address = 0x0A0f4321214BB6C7811dD8a71cF587bdaF03f0A0 -- OAO Proxyand topic0 = 0xb7b413554c4e94c80cfbb175a0e4727f2f425d29b980195c49dac293c2914fc0 -- AICallbackResult), time_cost_each_req as (selectreq.modelId, req.block_time as req_time, recv.block_time as recv_time, date_diff('second',req.block_time,recv.block_time) as cost_secondsfrom ml_requests reqinner join ml_result_back recv -- left join找到一个没有response的没意义,所以用inner joinusing (account,requestId))select'{{blockchain}}' as blockchain, modelId, min(cost_seconds) as min_cost_seconds, approx_percentile(cost_seconds, 0.5) as med_cost_seconds, max(cost_seconds) as max_cost_secondsfrom time_cost_each_reqgroup by 1,2