Query editor
WITH r AS (SELECT json_parse(http_get('https://data.doublezero.xyz/api/dz/contributors?limit=100&offset=0')) AS j),c AS (SELECT itemFROM rCROSS JOIN UNNEST(CAST(json_extract(j, '$.items') AS array(json))) AS t(item)),parsed AS (SELECTjson_extract_scalar(item, '$.pk') AS contributor_pk,json_extract_scalar(item, '$.code') AS code,COALESCE(NULLIF(json_extract_scalar(item, '$.name'), ''), json_extract_scalar(item, '$.code')) AS contributor,CAST(json_extract_scalar(item, '$.metro_count') AS bigint) AS metros,CAST(json_extract_scalar(item, '$.facility_count') AS bigint) AS facilities,CAST(json_extract_scalar(item, '$.device_count') AS bigint) AS devices,CAST(json_extract_scalar(item, '$.side_a_devices') AS bigint) AS side_a_devices,CAST(json_extract_scalar(item, '$.side_z_devices') AS bigint) AS side_z_devices,CAST(json_extract_scalar(item, '$.link_count') AS bigint) AS links,CAST(json_extract_scalar(item, '$.user_count') AS bigint) AS users,CAST(json_extract_scalar(item, '$.max_users') AS bigint) AS max_usersFROM c)SELECTCURRENT_DATE AS snapshot_date,contributor,code,metros,facilities,devices,side_a_devices,side_z_devices,links,users,max_users,CAST(users AS double) / NULLIF(max_users, 0) AS utilization,CAST(users AS double) / SUM(users) OVER () AS share_of_users,CAST(devices AS double) / SUM(devices) OVER () AS share_of_devices,contributor_pkFROM parsedORDER BY devices DESC, users DESC