feat: use recency and completion in recommendations

Boost recently played playing/backlog games, penalize completed ones, and explain both in recommendation reasons.
This commit is contained in:
strsv committed 2026-11-07 00:56:33 +03:00
1 parent 4566066f2b
commit 6a1b3aadfc
6 files changed
+67 -3

No files matched your search

+25
View File
@@ -4,6 +4,7 @@ import hashlib
import json
import math
import re
from datetime import date
TAG_KEYWORDS = {
"рпг": ["RPG"], "ролев": ["RPG"], "rpg": ["RPG"],
@@ -89,6 +90,26 @@ TASTE_PROFILES = {
}
def recency_bonus(last_played, status):
"""Score adjustment from the last launch and completion status."""
if not last_played:
return 0.0, None
try:
last = date.fromisoformat(str(last_played)[:10])
except ValueError:
return 0.0, None
days = (date.today() - last).days
if days < 0:
return 0.0, None
if status == "played":
return -4.0, "Уже пройдена"
if status == "playing" and days <= 30:
return 3.0, "Недавно играли"
if status == "backlog" and days <= 14:
return 2.0, "Недавно запускали"
return 0.0, None
def taste_profile_appids(con, profile):
"""Appids matching a play-context taste profile (solo/co-op)."""
spec = TASTE_PROFILES[profile]
@@ -354,6 +375,8 @@ def recommend(con, mood, allowed_statuses=None, unplayed_only=False,
score += 2 if r["installed"] else 0
score += 3 if r["status"] == "backlog" else 0
score += 4 if r["status"] == "playing" else 0
recency_add, recency_reason = recency_bonus(r["last_played"], r["status"])
score += recency_add
like_hit = len(liked_tags & tags)
taste_hit = sum(taste_weights.get(tag, 0.0) for tag in tags)
session_add, session_reason = session_bonus(
@@ -372,6 +395,8 @@ def recommend(con, mood, allowed_statuses=None, unplayed_only=False,
reasons.append(session_reason)
if time_reason:
reasons.append(time_reason)
if recency_reason:
reasons.append(recency_reason)
if matched:
reasons.append("Теги: " + ", ".join(matched[:3]))
if r["minutes"] == 0: