This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

at main 1.2 kB View raw
1"""Derive the user's interest chips from their seed repos' topics. 2 3The contract's `profile.interests` are shown in the onboarding reveal. We build 4them from the most frequent `record_raw.topics` across the user's seed repos — 5grounded in real data rather than invented cluster labels. 6""" 7 8from __future__ import annotations 9 10from collections import Counter 11 12from app.links import slugify 13 14 15def build_interests(seed_rows: list[dict], max_interests: int) -> list[dict]: 16 """seed_rows: dicts with a `topics` field (list[str] | None). Returns 17 [{label, slug}] ordered by frequency, de-duplicated by slug.""" 18 counter: Counter[str] = Counter() 19 label_for_slug: dict[str, str] = {} 20 for row in seed_rows: 21 topics = row.get("topics") or [] 22 for topic in topics: 23 if not topic or not str(topic).strip(): 24 continue 25 label = str(topic).strip() 26 slug = slugify(label) 27 if not slug: 28 continue 29 counter[slug] += 1 30 label_for_slug.setdefault(slug, label) 31 32 interests = [] 33 for slug, _count in counter.most_common(max_interests): 34 interests.append({"label": label_for_slug[slug], "slug": slug}) 35 return interests