feat: Add get_override_stats function to retrieve statistics for pronunciation overrides

This commit is contained in:
JB
2025-12-01 20:08:01 -08:00
parent aa53438acf
commit a14469c1d0
2 changed files with 32 additions and 0 deletions
+27
View File
@@ -238,3 +238,30 @@ def increment_usage(*, language: str, token: str, amount: int = 1) -> None:
conn.commit()
finally:
conn.close()
def get_override_stats(language: str) -> Dict[str, int]:
with _DB_LOCK:
conn = _connect()
try:
_ensure_schema(conn)
cursor = conn.execute(
"""
SELECT
COUNT(*) as total,
COUNT(CASE WHEN pronunciation IS NOT NULL AND pronunciation != '' THEN 1 END) as with_pronunciation,
COUNT(CASE WHEN voice IS NOT NULL AND voice != '' THEN 1 END) as with_voice
FROM overrides
WHERE language=?
""",
(language,),
)
row = cursor.fetchone()
return {
"total": row[0],
"filtered": row[0],
"with_pronunciation": row[1],
"with_voice": row[2],
}
finally:
conn.close()
+5
View File
@@ -15,6 +15,7 @@ from abogen.web.routes.utils.voice import template_options
from abogen.pronunciation_store import (
delete_override as delete_pronunciation_override,
save_override as save_pronunciation_override,
get_override_stats,
)
entities_bp = Blueprint("entities", __name__)
@@ -128,8 +129,12 @@ def entities_page() -> str:
settings = load_settings()
lang = request.args.get("lang") or settings.get("language", "en")
options = template_options()
stats = get_override_stats(lang)
language_label = options["languages"].get(lang, lang)
return render_template(
"entities.html",
language=lang,
language_label=language_label,
languages=options["languages"].items(),
stats=stats,
)