Find the most connected nodes (highest in+out degree), excluding File nodes. Returns list of dicts with: name, qualified_name, kind, file, in_degree, out_degree, total_degree, community_id
(store: GraphStore, top_n: int = 10)
| 12 | |
| 13 | |
| 14 | def find_hub_nodes(store: GraphStore, top_n: int = 10) -> list[dict]: |
| 15 | """Find the most connected nodes (highest in+out degree), excluding File nodes. |
| 16 | |
| 17 | Returns list of dicts with: name, qualified_name, kind, file, |
| 18 | in_degree, out_degree, total_degree, community_id |
| 19 | """ |
| 20 | # Build degree counts from all edges |
| 21 | edges = store.get_all_edges() |
| 22 | in_degree: dict[str, int] = Counter() |
| 23 | out_degree: dict[str, int] = Counter() |
| 24 | for e in edges: |
| 25 | out_degree[e.source_qualified] += 1 |
| 26 | in_degree[e.target_qualified] += 1 |
| 27 | |
| 28 | # Get all non-File nodes |
| 29 | nodes = store.get_all_nodes(exclude_files=True) |
| 30 | community_map = store.get_all_community_ids() |
| 31 | |
| 32 | scored = [] |
| 33 | for n in nodes: |
| 34 | qn = n.qualified_name |
| 35 | ind = in_degree.get(qn, 0) |
| 36 | outd = out_degree.get(qn, 0) |
| 37 | total = ind + outd |
| 38 | if total == 0: |
| 39 | continue |
| 40 | scored.append({ |
| 41 | "name": _sanitize_name(n.name), |
| 42 | "qualified_name": n.qualified_name, |
| 43 | "kind": n.kind, |
| 44 | "file": n.file_path, |
| 45 | "in_degree": ind, |
| 46 | "out_degree": outd, |
| 47 | "total_degree": total, |
| 48 | "community_id": community_map.get(qn), |
| 49 | }) |
| 50 | |
| 51 | scored.sort( |
| 52 | key=lambda x: x.get("total_degree", 0), # type: ignore[arg-type,return-value] |
| 53 | reverse=True, |
| 54 | ) |
| 55 | return scored[:top_n] |
| 56 | |
| 57 | |
| 58 | def find_bridge_nodes( |
no test coverage detected