feat: add table sorting, accessibility and session filters
CI / test (push) Successful in 3m18s

This commit is contained in:
strsv committed 2026-11-06 19:20:18 +03:00
1 parent a6db306847
commit 7e4fa74cd6
13 files changed
+363 -63

No files matched your search

+36 -1
View File
@@ -47,6 +47,31 @@ TAG_KEYWORDS = {
"ферм": ["Farming Sim"], "farming": ["Farming Sim"],
}
SESSION_TAGS = {
"short": {"Short", "Casual", "Puzzle", "Relaxing", "Roguelike", "Roguelite",
"Minimalist", "Point & Click"},
"evening": {"Story Rich", "Atmospheric", "Choices Matter", "Narrative",
"Adventure", "Mystery", "Detective"},
"weekend": {"Open World", "RPG", "Sandbox", "Survival", "Strategy",
"Simulation", "Colony Sim", "City Builder"},
}
SESSION_REASONS = {
"short": "Подходит для короткой сессии",
"evening": "Хорошо для вечерней сессии",
"weekend": "Подходит для выходных",
}
def session_bonus(tag_names, session):
if session not in SESSION_TAGS:
return 0.0, None
hits = SESSION_TAGS[session] & set(tag_names)
if not hits:
return 0.0, None
return min(8.0, 2.0 * len(hits)), SESSION_REASONS[session]
GENRE_KEYWORDS = {
"экшен": "Action", "action": "Action",
"стратег": "Strategy", "strategy": "Strategy",
@@ -141,7 +166,8 @@ def load_mood(con, preset=None, text=None):
def recommend(con, mood, allowed_statuses=None, unplayed_only=False,
min_review=65, allow_unknown=False, limit=20, feedback_key=None):
min_review=65, allow_unknown=False, limit=20, feedback_key=None,
session=None):
allowed = set(allowed_statuses or {"backlog", "playing", "played"})
if not allowed:
allowed = {"backlog", "playing", "played"}
@@ -193,6 +219,10 @@ def recommend(con, mood, allowed_statuses=None, unplayed_only=False,
game_genres = {i: set() for i in ids}
for r in con.execute(f"SELECT appid, genre FROM game_genres WHERE appid IN ({placeholders})", ids):
game_genres[r["appid"]].add(r["genre"])
game_tag_names = {
appid: {tag_names[t] for t in tags if t in tag_names}
for appid, tags in game_tags.items()
}
total = len(ids)
df = {}
@@ -249,13 +279,18 @@ def recommend(con, mood, allowed_statuses=None, unplayed_only=False,
score += 4 if r["status"] == "playing" else 0
like_hit = len(liked_tags & tags)
taste_hit = len(taste_tags & tags)
session_add, session_reason = session_bonus(
game_tag_names.get(r["appid"], set()), session)
score += min(8.0, 1.5 * like_hit)
score += min(6.0, 1.0 * taste_hit)
score += session_add
reasons = []
if like_hit:
reasons.append("Похоже на игры, отмеченные «в точку»")
elif taste_hit:
reasons.append("Похоже на избранное и высокие оценки")
if session_reason:
reasons.append(session_reason)
if matched:
reasons.append("Теги: " + ", ".join(matched[:3]))
if r["minutes"] == 0: