This commit is contained in:
1 parent
88c4beabcd
commit
419bd12dec
8 files changed
+57
-24
No files matched your search
+23
-11
@@ -238,14 +238,26 @@ def recommend(con, mood, allowed_statuses=None, unplayed_only=False,
|
||||
liked_tags = {r["tag_id"] for r in con.execute(
|
||||
f"SELECT tag_id FROM game_tags WHERE appid IN ({liked_ph})", list(liked_ids))}
|
||||
|
||||
taste_ids = {r["appid"] for r in con.execute(
|
||||
"""SELECT appid FROM personal
|
||||
WHERE COALESCE(favorite, 0) = 1 OR COALESCE(rating, 0) >= 8""")}
|
||||
taste_tags = set()
|
||||
if taste_ids:
|
||||
taste_ph = ",".join("?" * len(taste_ids))
|
||||
taste_tags = {r["tag_id"] for r in con.execute(
|
||||
f"SELECT tag_id FROM game_tags WHERE appid IN ({taste_ph})", list(taste_ids))}
|
||||
taste_weights = {}
|
||||
for row in con.execute("""
|
||||
SELECT 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
|
||||
LEFT JOIN game_playtime p ON p.appid = gt.appid
|
||||
LEFT JOIN personal pe ON pe.appid = gt.appid
|
||||
WHERE LOWER(g.type) = 'game'
|
||||
"""):
|
||||
weight = 0.0
|
||||
if row["minutes"] > 0:
|
||||
weight += min(2.0, math.log1p(row["minutes"] / 60))
|
||||
if row["favorite"]:
|
||||
weight += 1.0
|
||||
if row["rating"] >= 8:
|
||||
weight += 0.5 + (row["rating"] - 8) * 0.25
|
||||
if weight:
|
||||
tag_id = row["tag_id"]
|
||||
taste_weights[tag_id] = max(taste_weights.get(tag_id, 0.0), min(4.0, weight))
|
||||
|
||||
mood_tags = {k: float(v) for k, v in mood["tags"].items()}
|
||||
denom = 0.0
|
||||
@@ -279,17 +291,17 @@ def recommend(con, mood, allowed_statuses=None, unplayed_only=False,
|
||||
score += 3 if r["status"] == "backlog" else 0
|
||||
score += 4 if r["status"] == "playing" else 0
|
||||
like_hit = len(liked_tags & tags)
|
||||
taste_hit = len(taste_tags & tags)
|
||||
taste_hit = sum(taste_weights.get(tag, 0.0) for tag in 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 += min(10.0, taste_hit)
|
||||
score += session_add
|
||||
reasons = []
|
||||
if like_hit:
|
||||
reasons.append("Похоже на игры, отмеченные «в точку»")
|
||||
elif taste_hit:
|
||||
reasons.append("Похоже на избранное и высокие оценки")
|
||||
reasons.append("Похоже на ваш вкус")
|
||||
if session_reason:
|
||||
reasons.append(session_reason)
|
||||
if matched:
|
||||
|
||||
Reference in new issue
Block a user