feat: compare mood presets in the UI

Add GET /api/compare with shared/unique games and Jaccard, plus a preset comparison panel on the recommendations tab.
This commit is contained in:
strsv committed 2026-11-07 00:51:01 +03:00
1 parent 9943081baa
commit 02af4bde09
10 files changed
+198 -3

No files matched your search

+16
View File
@@ -487,6 +487,22 @@ class ApiTests(unittest.TestCase):
finally:
con.close()
def test_compare_presets(self):
data = self.get("/api/compare?a=dark-fantasy&b=story-heavy&limit=5")
self.assertEqual(data["a"], "dark-fantasy")
self.assertEqual(data["b"], "story-heavy")
self.assertGreaterEqual(data["jaccard"], 0.0)
self.assertLessEqual(data["jaccard"], 1.0)
common = {game["appid"] for game in data["common"]}
only_a = {game["appid"] for game in data["only_a"]}
only_b = {game["appid"] for game in data["only_b"]}
self.assertFalse(common & only_a)
self.assertFalse(common & only_b)
self.assertFalse(only_a & only_b)
self.assertEqual(self.get("/api/compare?a=dark-fantasy", expect=400)["error"],
"two presets required")
self.get("/api/compare?a=dark-fantasy&b=missing-preset", expect=404)
def test_recommend_unknown_mood(self):
data = self.post("/api/recommend", {"preset": "no-such-mood"}, expect=400)
self.assertEqual(data["error"], "unknown mood")