feat: localize tags and genres; improve search, duration and sorting
CI / test (push) Successful in 27s

This commit is contained in:
strsv committed 2026-11-09 08:13:00 +03:00
1 parent ea3074e0a9
commit be4fbf6864
31 files changed
+1126 -145

No files matched your search

+69 -6
View File
@@ -8,7 +8,33 @@ from datetime import datetime, timezone
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
DEFAULT_DB = os.path.join(BASE_DIR, "steam.db")
SCHEMA_PATH = os.path.join(BASE_DIR, "tools", "schema.sql")
SCHEMA_VERSION = 10
SCHEMA_VERSION = 12
GENRE_NAMES_RU = {
"Action": "Экшены",
"Adventure": "Приключенческие игры",
"Strategy": "Стратегии",
"RPG": "Ролевые игры",
"Indie": "Инди",
"Simulation": "Симуляторы",
"Casual": "Казуальные игры",
"Free To Play": "Бесплатные",
"Massively Multiplayer": "Многопользовательские игры",
"Racing": "Гонки",
"Sports": "Спорт",
"Early Access": "Ранний доступ",
"Accounting": "Бухгалтерия",
"Animation & Modeling": "Анимация и моделирование",
"Audio Production": "Работа со звуком",
"Design & Illustration": "Дизайн и иллюстрация",
"Education": "Образование",
"Photo Editing": "Обработка фото",
"Software Training": "Обучение работе с ПО",
"Utilities": "Утилиты",
"Video Production": "Создание видео",
"Web Publishing": "Веб-разработка",
"Game Development": "Разработка игр",
}
MOOD_PRESETS = {
"adventure-rpg-party": {
@@ -329,11 +355,16 @@ def _plain_text(*parts):
def _search_tags(con, appid):
row = con.execute(
"""SELECT GROUP_CONCAT(tn.name, ' ') AS names
tag_row = con.execute(
"""SELECT GROUP_CONCAT(tn.name || ' ' || COALESCE(tn.name_ru, ''), ' ') AS names
FROM game_tags gt JOIN tag_names tn ON tn.tag_id = gt.tag_id
WHERE gt.appid = ?""", (appid,)).fetchone()
return (row[0] if row and row[0] else "") if row else ""
genre_row = con.execute(
"""SELECT GROUP_CONCAT(gg.genre || ' ' || COALESCE(gn.name_ru, ''), ' ') AS names
FROM game_genres gg LEFT JOIN genre_names gn ON gn.name = gg.genre
WHERE gg.appid = ?""", (appid,)).fetchone()
return " ".join(part for part in (
tag_row[0] if tag_row else "", genre_row[0] if genre_row else "") if part)
def refresh_search_index(con):
@@ -347,16 +378,22 @@ def refresh_search_index(con):
WHERE LOWER(g.type) = 'game'
""").fetchall()
tags = {r[0]: r[1] for r in con.execute("""
SELECT gt.appid, GROUP_CONCAT(tn.name, ' ')
SELECT gt.appid, GROUP_CONCAT(tn.name || ' ' || COALESCE(tn.name_ru, ''), ' ')
FROM game_tags gt JOIN tag_names tn ON tn.tag_id = gt.tag_id
GROUP BY gt.appid
""")}
genres = {r[0]: r[1] for r in con.execute("""
SELECT gg.appid, GROUP_CONCAT(gg.genre || ' ' || COALESCE(gn.name_ru, ''), ' ')
FROM game_genres gg LEFT JOIN genre_names gn ON gn.name = gg.genre
GROUP BY gg.appid
""")}
con.execute("DELETE FROM game_fts")
con.executemany(
"INSERT INTO game_fts(rowid, appid, name, description, tags) VALUES (?, ?, ?, ?, ?)",
[(r["appid"], r["appid"], r["name"],
_plain_text(r["short_description"], r["about"], r["short_ru"], r["about_ru"]),
tags.get(r["appid"], "")) for r in rows],
" ".join(part for part in (tags.get(r["appid"], ""),
genres.get(r["appid"], "")) if part)) for r in rows],
)
con.commit()
@@ -600,6 +637,22 @@ def _migration_10(con):
"ON game_ownership(owned)")
def _migration_11(con):
"""Store localized (Russian) tag names next to the canonical English ones."""
_ensure_column(con, "tag_names", "name_ru", "TEXT")
def _migration_12(con):
"""Add localized genre names."""
con.execute("""
CREATE TABLE IF NOT EXISTS genre_names (
name TEXT PRIMARY KEY,
name_ru TEXT
)
""")
seed_genre_names(con)
MIGRATIONS = {
1: _migration_1,
2: _migration_2,
@@ -611,9 +664,18 @@ MIGRATIONS = {
8: _migration_8,
9: _migration_9,
10: _migration_10,
11: _migration_11,
12: _migration_12,
}
def seed_genre_names(con):
con.executemany(
"""INSERT INTO genre_names (name, name_ru) VALUES (?, ?)
ON CONFLICT(name) DO UPDATE SET name_ru = excluded.name_ru""",
GENRE_NAMES_RU.items())
def init(con):
"""Create or upgrade the database schema.
@@ -629,6 +691,7 @@ def init(con):
con.executescript(f.read())
for target in range(version + 1, SCHEMA_VERSION + 1):
MIGRATIONS[target](con)
seed_genre_names(con)
con.execute("INSERT OR REPLACE INTO schema_meta (key, value) VALUES ('schema_version', ?)",
(str(SCHEMA_VERSION),))
con.commit()