Query editor
/* ==========================================================================L2b — CONNECTED COMPONENTS + CLUSTER SCORECARDSource: L2a evidence table (query 8386684, inlined by DuneSQL)Algorithm note: attribute edges (shared owner / shared funder / co-tradegroup) form CLIQUES, so one MIN-over-{self + neighbours} round alreadygives every member the same label. Long transfer CHAINS would need morerounds -- export L2a and run networkx.connected_components for those.========================================================================== */WITH ev AS (SELECT * FROM query_8386684),nodes AS (SELECT a AS wallet, yes_shares, no_shares, usdc_net, n_fills, best_rank,first_trade, evidence AS owner_eoa, first_funded_by, funder_fanoutFROM ev WHERE row_type = 'node'),sym AS (SELECT a AS src, b AS dst, edge_type, weight FROM ev WHERE row_type = 'edge'UNION ALLSELECT b, a, edge_type, weight FROM ev WHERE row_type = 'edge'),lab AS (SELECT n.wallet,/* self MUST be part of the min, otherwise a 2-node componentswaps labels with itself and never converges */LEAST(n.wallet, MIN(COALESCE(s.dst, n.wallet))) AS cluster_key,COUNT(DISTINCT s.dst) AS peer_count,COALESCE(array_join(array_agg(DISTINCT s.edge_type), ' + '), '-') AS evidence_types,COALESCE(MAX(s.weight), 0) AS best_edge_weightFROM nodes nLEFT JOIN sym s ON s.src = n.walletGROUP BY n.wallet),scored AS (SELECT l.cluster_key, n.*, l.peer_count, l.evidence_types, l.best_edge_weight,COUNT(*) OVER (PARTITION BY l.cluster_key) AS cluster_size,SUM(n.yes_shares) OVER (PARTITION BY l.cluster_key) AS c_yes,SUM(n.no_shares) OVER (PARTITION BY l.cluster_key) AS c_no,SUM(n.usdc_net) OVER (PARTITION BY l.cluster_key) AS c_usdc,SUM(n.yes_shares) OVER () AS tot_yes,SUM(n.no_shares) OVER () AS tot_noFROM nodes nJOIN lab l ON l.wallet = n.wallet)SELECTDENSE_RANK() OVER (ORDER BY c_yes + c_no DESC, cluster_key) AS cluster_id,cluster_size,round(c_yes, 0) AS cluster_yes_shares,round(c_no, 0) AS cluster_no_shares,round(100.0 * c_yes / NULLIF(tot_yes, 0), 2) AS pct_of_topN_yes,round(100.0 * c_no / NULLIF(tot_no, 0), 2) AS pct_of_topN_no,round(c_usdc, 0) AS cluster_usdc_net,wallet AS proxy_wallet,best_rank,round(yes_shares, 0) AS yes_shares,round(no_shares, 0) AS no_shares,