diff --git a/abogen/pronunciation_store.py b/abogen/pronunciation_store.py index b8f0300..14b2419 100644 --- a/abogen/pronunciation_store.py +++ b/abogen/pronunciation_store.py @@ -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() diff --git a/abogen/web/routes/entities.py b/abogen/web/routes/entities.py index 0bc62ef..6a6b93a 100644 --- a/abogen/web/routes/entities.py +++ b/abogen/web/routes/entities.py @@ -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, )