Build a minimal graph.json + analysis/labels files in tmp_path/graphify-out/.
(tmp_path: Path)
| 27 | |
| 28 | |
| 29 | def _make_graph(tmp_path: Path) -> Path: |
| 30 | """Build a minimal graph.json + analysis/labels files in tmp_path/graphify-out/.""" |
| 31 | out = tmp_path / "graphify-out" |
| 32 | out.mkdir() |
| 33 | |
| 34 | extraction = json.loads((FIXTURES / "extraction.json").read_text()) |
| 35 | from graphify.build import build_from_json |
| 36 | from graphify.cluster import cluster, score_all |
| 37 | from graphify.analyze import god_nodes, surprising_connections |
| 38 | from graphify.export import to_json |
| 39 | |
| 40 | G = build_from_json(extraction) |
| 41 | communities = cluster(G) |
| 42 | cohesion = score_all(G, communities) |
| 43 | gods = god_nodes(G) |
| 44 | surprises = surprising_connections(G, communities) |
| 45 | labels = {cid: f"Community {cid}" for cid in communities} |
| 46 | |
| 47 | to_json(G, communities, str(out / "graph.json")) |
| 48 | |
| 49 | analysis = { |
| 50 | "communities": {str(k): v for k, v in communities.items()}, |
| 51 | "cohesion": {str(k): v for k, v in cohesion.items()}, |
| 52 | "gods": gods, |
| 53 | "surprises": surprises, |
| 54 | } |
| 55 | (out / ".graphify_analysis.json").write_text(json.dumps(analysis)) |
| 56 | (out / ".graphify_labels.json").write_text( |
| 57 | json.dumps({str(k): v for k, v in labels.items()}) |
| 58 | ) |
| 59 | return out |
| 60 | |
| 61 | |
| 62 | # ── graphify export html ───────────────────────────────────────────────────── |
no test coverage detected