Return aggregate statistics about the graph.
(self)
| 832 | return {"nodes": nodes, "edges": edges} |
| 833 | |
| 834 | def get_stats(self) -> GraphStats: |
| 835 | """Return aggregate statistics about the graph.""" |
| 836 | total_nodes = self._conn.execute("SELECT COUNT(*) FROM nodes").fetchone()[0] |
| 837 | total_edges = self._conn.execute("SELECT COUNT(*) FROM edges").fetchone()[0] |
| 838 | |
| 839 | nodes_by_kind: dict[str, int] = {} |
| 840 | for row in self._conn.execute("SELECT kind, COUNT(*) as cnt FROM nodes GROUP BY kind"): |
| 841 | nodes_by_kind[row["kind"]] = row["cnt"] |
| 842 | |
| 843 | edges_by_kind: dict[str, int] = {} |
| 844 | for row in self._conn.execute("SELECT kind, COUNT(*) as cnt FROM edges GROUP BY kind"): |
| 845 | edges_by_kind[row["kind"]] = row["cnt"] |
| 846 | |
| 847 | languages = [ |
| 848 | r["language"] for r in self._conn.execute( |
| 849 | "SELECT DISTINCT language FROM nodes WHERE language IS NOT NULL AND language != ''" |
| 850 | ) |
| 851 | ] |
| 852 | |
| 853 | files_count = self._conn.execute( |
| 854 | "SELECT COUNT(*) FROM nodes WHERE kind = 'File'" |
| 855 | ).fetchone()[0] |
| 856 | |
| 857 | last_updated = self.get_metadata("last_updated") |
| 858 | |
| 859 | return GraphStats( |
| 860 | total_nodes=total_nodes, |
| 861 | total_edges=total_edges, |
| 862 | nodes_by_kind=nodes_by_kind, |
| 863 | edges_by_kind=edges_by_kind, |
| 864 | languages=languages, |
| 865 | files_count=files_count, |
| 866 | last_updated=last_updated, |
| 867 | ) |
| 868 | |
| 869 | def get_nodes_by_size( |
| 870 | self, |