feat: add solo and co-op taste profiles

Filter recommendation candidates and taste weights by play context, with taste_profile in the API, --taste in the CLI and a selector in the UI.
This commit is contained in:
strsv committed 2026-11-07 00:53:18 +03:00
1 parent 02af4bde09
commit 54a7b36aae
12 files changed
+105 -4

No files matched your search

+40 -2
View File
@@ -73,6 +73,37 @@ TIME_TAGS = {
"Atmospheric", "Relaxing"},
}
TASTE_PROFILES = {
"solo": {
"label": "соло",
"include": {"Singleplayer"},
"exclude": {"Co-op", "Online Co-Op", "Local Co-Op", "Multiplayer",
"Local Multiplayer", "MMORPG", "Massively Multiplayer", "PvP"},
},
"coop": {
"label": "с друзьями",
"include": {"Co-op", "Online Co-Op", "Local Co-Op", "Multiplayer",
"Local Multiplayer", "MMORPG", "Massively Multiplayer"},
"exclude": set(),
},
}
def taste_profile_appids(con, profile):
"""Appids matching a play-context taste profile (solo/co-op)."""
spec = TASTE_PROFILES[profile]
tags = {}
for row in con.execute("""
SELECT gt.appid, tn.name
FROM game_tags gt JOIN tag_names tn ON tn.tag_id = gt.tag_id
"""):
tags.setdefault(row["appid"], set()).add(row["name"])
return {
appid for appid, names in tags.items()
if spec["include"] & names and not (spec["exclude"] & names)
}
TIME_REASONS = {
"morning": "Хорошо для утра",
"day": "Подходит для дня",
@@ -194,10 +225,13 @@ 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,
session=None, time_of_day=None):
session=None, time_of_day=None, taste_profile=None):
allowed = set(allowed_statuses or {"backlog", "playing", "played"})
if not allowed:
allowed = {"backlog", "playing", "played"}
if taste_profile and taste_profile not in TASTE_PROFILES:
raise ValueError(f"unknown taste profile: {taste_profile}")
context_appids = taste_profile_appids(con, taste_profile) if taste_profile else None
tag_names = {r["tag_id"]: r["name"] for r in con.execute("SELECT tag_id, name FROM tag_names")}
name_to_ids = {}
@@ -223,6 +257,8 @@ def recommend(con, mood, allowed_statuses=None, unplayed_only=False,
rows = [r for r in rows if r["review_pct"] is None or r["review_pct"] >= min_review]
if not allow_unknown:
rows = [r for r in rows if r["review_pct"] is not None or r["metacritic"] is not None]
if context_appids is not None:
rows = [r for r in rows if r["appid"] in context_appids]
feedback = {}
liked_ids = set()
@@ -266,7 +302,7 @@ def recommend(con, mood, allowed_statuses=None, unplayed_only=False,
taste_weights = {}
for row in con.execute("""
SELECT gt.tag_id, COALESCE(p.minutes, 0) AS minutes,
SELECT gt.appid AS appid, gt.tag_id, COALESCE(p.minutes, 0) AS minutes,
COALESCE(pe.favorite, 0) AS favorite, COALESCE(pe.rating, 0) AS rating
FROM game_tags gt
JOIN games g ON g.appid = gt.appid
@@ -274,6 +310,8 @@ def recommend(con, mood, allowed_statuses=None, unplayed_only=False,
LEFT JOIN personal pe ON pe.appid = gt.appid
WHERE LOWER(g.type) = 'game'
"""):
if context_appids is not None and row["appid"] not in context_appids:
continue
weight = 0.0
if row["minutes"] > 0:
weight += min(2.0, math.log1p(row["minutes"] / 60))
+3
View File
@@ -39,6 +39,8 @@ def main():
help="include games kept unplayed on purpose (status=nostalgia)")
ap.add_argument("--allow-unknown", action="store_true",
help="also consider games without any review/metacritic score")
ap.add_argument("--taste", choices=sorted(reco.TASTE_PROFILES),
help="play-context taste profile (solo/coop)")
ap.add_argument("--json", action="store_true")
args = ap.parse_args()
@@ -70,6 +72,7 @@ def main():
mood, results = reco.recommend(
con, mood, allowed_statuses=allowed, unplayed_only=args.unplayed_only,
min_review=args.min_review, allow_unknown=args.allow_unknown, limit=args.limit,
taste_profile=args.taste,
)
if args.json: