Aggregate statistics across skills.
(self, *, active_only: bool = True)
| 928 | |
| 929 | @_db_retry() |
| 930 | def get_stats(self, *, active_only: bool = True) -> Dict[str, Any]: |
| 931 | """Aggregate statistics across skills.""" |
| 932 | with self._reader() as conn: |
| 933 | where = " WHERE is_active=1" if active_only else "" |
| 934 | total = conn.execute( |
| 935 | f"SELECT COUNT(*) FROM skill_records{where}" |
| 936 | ).fetchone()[0] |
| 937 | |
| 938 | by_category = { |
| 939 | r["category"]: r["cnt"] |
| 940 | for r in conn.execute( |
| 941 | f"SELECT category, COUNT(*) AS cnt " |
| 942 | f"FROM skill_records{where} GROUP BY category" |
| 943 | ).fetchall() |
| 944 | } |
| 945 | by_origin = { |
| 946 | r["lineage_origin"]: r["cnt"] |
| 947 | for r in conn.execute( |
| 948 | f"SELECT lineage_origin, COUNT(*) AS cnt " |
| 949 | f"FROM skill_records{where} GROUP BY lineage_origin" |
| 950 | ).fetchall() |
| 951 | } |
| 952 | n_analyses = conn.execute( |
| 953 | "SELECT COUNT(*) FROM execution_analyses" |
| 954 | ).fetchone()[0] |
| 955 | n_candidates = conn.execute( |
| 956 | "SELECT COUNT(*) FROM execution_analyses " |
| 957 | "WHERE candidate_for_evolution=1" |
| 958 | ).fetchone()[0] |
| 959 | n_unprocessed_candidates = conn.execute( |
| 960 | "SELECT COUNT(*) FROM execution_analyses " |
| 961 | "WHERE candidate_for_evolution=1 " |
| 962 | "AND evolution_processed_at IS NULL" |
| 963 | ).fetchone()[0] |
| 964 | agg = conn.execute( |
| 965 | f""" |
| 966 | SELECT SUM(total_selections) AS sel, |
| 967 | SUM(total_applied) AS app, |
| 968 | SUM(total_completions) AS comp, |
| 969 | SUM(total_fallbacks) AS fb |
| 970 | FROM skill_records{where} |
| 971 | """ |
| 972 | ).fetchone() |
| 973 | |
| 974 | # Also report total (including inactive) for context |
| 975 | total_all = conn.execute( |
| 976 | "SELECT COUNT(*) FROM skill_records" |
| 977 | ).fetchone()[0] |
| 978 | |
| 979 | return { |
| 980 | "total_skills": total, |
| 981 | "total_skills_all": total_all, |
| 982 | "by_category": by_category, |
| 983 | "by_origin": by_origin, |
| 984 | "total_analyses": n_analyses, |
| 985 | "evolution_candidates": n_candidates, |
| 986 | "unprocessed_evolution_candidates": n_unprocessed_candidates, |
| 987 | "total_selections": agg["sel"] or 0, |
no test coverage detected