Diversify Doris Dashboard topic selection
This commit is contained in:
@@ -245,12 +245,22 @@ def select_items(items:list[dict[str,Any]],prefs:dict[str,Any],max_items:int=14)
|
||||
for i in items:
|
||||
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)
|
||||
out=[]; seen=set(); sources=Counter()
|
||||
|
||||
out=[]; seen=set(); sources=Counter(); categories=Counter()
|
||||
|
||||
def consider(limit_per_category:int|None)->None:
|
||||
for i in recent:
|
||||
url=i.get('url',''); src=i.get('source','')
|
||||
if url in seen or sources[src]>=2: continue
|
||||
out.append(i); seen.add(url); sources[src]+=1
|
||||
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
|
||||
|
||||
def label(cat:str)->str:
|
||||
|
||||
Reference in New Issue
Block a user