34 lines
1008 B
Python
34 lines
1008 B
Python
import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
class SocialAgent:
|
|
def analyze(self, sentiment: dict, mention_trend: float = 1.0) -> float:
|
|
total = sentiment.get("total", 0)
|
|
if total == 0:
|
|
return 50.0
|
|
try:
|
|
pos = sentiment.get("positive", 0)
|
|
ratio = pos / total
|
|
sentiment_score = ratio * 100
|
|
|
|
if mention_trend > 2.0:
|
|
trend_bonus = 15
|
|
elif mention_trend > 1.5:
|
|
trend_bonus = 10
|
|
elif mention_trend > 1.0:
|
|
trend_bonus = 5
|
|
elif mention_trend < 0.5:
|
|
trend_bonus = -10
|
|
else:
|
|
trend_bonus = 0
|
|
|
|
if ratio < 0.4 and mention_trend > 1.5:
|
|
trend_bonus = -15
|
|
|
|
score = sentiment_score + trend_bonus
|
|
return round(max(0, min(100, score)), 1)
|
|
except Exception as e:
|
|
logger.error(f"Social analysis error: {e}")
|
|
return 50.0
|