Diversify Doris Dashboard topic selection

This commit is contained in:
Fizzlepoof
2026-05-16 16:00:41 +00:00
parent ecf44fe65f
commit e9fd381ef9

View File

@@ -245,12 +245,22 @@ def select_items(items:list[dict[str,Any]],prefs:dict[str,Any],max_items:int=14)
for i in items: for i in items:
if (now-parse_time(i.get('published_at',''))).total_seconds()<96*3600: recent.append(i) if (now-parse_time(i.get('published_at',''))).total_seconds()<96*3600: recent.append(i)
recent.sort(key=lambda i:(score_item(i,prefs),i.get('published_at','')),reverse=True) recent.sort(key=lambda i:(score_item(i,prefs),i.get('published_at','')),reverse=True)
out=[]; seen=set(); sources=Counter()
for i in recent: out=[]; seen=set(); sources=Counter(); categories=Counter()
url=i.get('url',''); src=i.get('source','')
if url in seen or sources[src]>=2: continue def consider(limit_per_category:int|None)->None:
out.append(i); seen.add(url); sources[src]+=1 for i in recent:
if len(out)>=max_items: break if len(out)>=max_items: break
url=i.get('url',''); src=i.get('source',''); cat=(i.get('category') or 'other').strip() or 'other'
if url in seen or sources[src]>=2: continue
if limit_per_category is not None and categories[cat] >= limit_per_category: continue
out.append(i); seen.add(url); sources[src]+=1; categories[cat]+=1
# First fill favors breadth across categories, then allows a second item per
# category, and only then permits a small spillover from the strongest buckets.
consider(1)
consider(2)
consider(3)
return out return out
def label(cat:str)->str: def label(cat:str)->str: