from typing import Dict, Any class ConfidenceScorer: """ Computes a weighted authenticity and quality score across multiple data sources: - YouTube footprint: 40% - MusicBrainz catalog: 35% - Wikidata entity: 25% """ def __init__(self, yt_weight: float = 0.40, mb_weight: float = 0.35, wd_weight: float = 0.25): self.w_yt = yt_weight self.w_mb = mb_weight self.w_wd = wd_weight def calculate_score( self, yt_metrics: Dict[str, Any], mb_result: Dict[str, Any], wd_result: Dict[str, Any] ) -> Dict[str, Any]: # 1. YouTube sub-score (0.0 to 1.0) yt_score = 0.0 if yt_metrics.get("status") in ["live_api", "cached"]: subs = yt_metrics.get("subscribers", 0) views = yt_metrics.get("lifetime_views", 0) vids = yt_metrics.get("video_count", 0) # Baseline 0.5 for a verified channel existence yt_score = 0.5 if subs >= 1000: yt_score += 0.2 elif subs > 0: yt_score += 0.1 if views >= 50000: yt_score += 0.2 elif views > 0: yt_score += 0.1 if vids >= 5: yt_score += 0.1 # 2. MusicBrainz sub-score mb_score = mb_result.get("confidence", 0.0) if mb_result.get("verified") else 0.0 # 3. Wikidata sub-score wd_score = wd_result.get("confidence", 0.0) if wd_result.get("verified") else 0.0 # Aggregated composite score composite = (yt_score * self.w_yt) + (mb_score * self.w_mb) + (wd_score * self.w_wd) composite = round(min(1.0, max(0.0, composite)), 2) # Confidence category if composite >= 0.75: tier = "High" elif composite >= 0.45: tier = "Medium" else: tier = "Low / Emerging" return { "composite_confidence": composite, "confidence_tier": tier, "sub_scores": { "youtube": round(yt_score, 2), "musicbrainz": round(mb_score, 2), "wikidata": round(wd_score, 2) } } if __name__ == "__main__": scorer = ConfidenceScorer() dummy_yt = {"status": "live_api", "subscribers": 5000, "lifetime_views": 250000, "video_count": 18} dummy_mb = {"verified": True, "confidence": 1.0} dummy_wd = {"verified": True, "confidence": 1.0} print("Test Scorer Output:") print(scorer.calculate_score(dummy_yt, dummy_mb, dummy_wd))