MCPcopy Index your code
hub / github.com/idank/explainshell / show_stats

Function show_stats

explainshell/manager.py:1158–1190  ·  view source on GitHub ↗

Print aggregate database statistics.

(ctx: click.Context)

Source from the content-addressed store, hash-verified

1156@show.command("stats")
1157@click.pass_context
1158def show_stats(ctx: click.Context) -> None:
1159 """Print aggregate database statistics."""
1160 import sqlite3
1161
1162 db_path = _require_db(ctx, must_exist=True)
1163 conn = sqlite3.connect(db_path)
1164 conn.row_factory = sqlite3.Row
1165
1166 n_manpages = conn.execute("SELECT COUNT(*) AS c FROM manpages").fetchone()["c"]
1167 n_parsed = conn.execute("SELECT COUNT(*) AS c FROM parsed_manpages").fetchone()["c"]
1168 n_mappings = conn.execute("SELECT COUNT(*) AS c FROM mappings").fetchone()["c"]
1169 click.echo(f"manpages (raw): {n_manpages}")
1170 click.echo(f"parsed_manpages: {n_parsed}")
1171 click.echo(f"mappings: {n_mappings}")
1172
1173 # Per-distro breakdown.
1174 rows = conn.execute("""
1175 SELECT
1176 SUBSTR(source, 1, INSTR(source, '/') - 1) as distro,
1177 SUBSTR(source, INSTR(source, '/') + 1,
1178 INSTR(SUBSTR(source, INSTR(source, '/') + 1), '/') - 1) as release,
1179 COUNT(*) as cnt
1180 FROM parsed_manpages
1181 GROUP BY distro, release
1182 ORDER BY distro, release
1183 """).fetchall()
1184 if rows:
1185 click.echo("")
1186 click.echo("per distro/release:")
1187 for row in rows:
1188 click.echo(f" {row['distro']}/{row['release']}: {row['cnt']}")
1189
1190 conn.close()
1191
1192
1193@show.command("events")

Callers

nothing calls this directly

Calls 2

_require_dbFunction · 0.85
closeMethod · 0.45

Tested by

no test coverage detected