From e9fd381ef90991ab0d44167fd212ed26ccff31cf Mon Sep 17 00:00:00 2001 From: Fizzlepoof Date: Sat, 16 May 2026 16:00:41 +0000 Subject: [PATCH] Diversify Doris Dashboard topic selection --- .../doris-dashboard/bin/generate_dashboard.py | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/home/doris-dashboard/bin/generate_dashboard.py b/home/doris-dashboard/bin/generate_dashboard.py index 1e810b5..fb12d51 100755 --- a/home/doris-dashboard/bin/generate_dashboard.py +++ b/home/doris-dashboard/bin/generate_dashboard.py @@ -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() - 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 + + out=[]; seen=set(); sources=Counter(); categories=Counter() + + def consider(limit_per_category:int|None)->None: + for i in recent: + 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: