mirror of
https://github.com/denizsafak/abogen.git
synced 2026-07-18 05:40:26 +02:00
feat: Add get_override_stats function to retrieve statistics for pronunciation overrides
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user