Dmitry Beresnev commited on
Commit
07b3173
·
1 Parent(s): 444359f

fix breaking news scorer

Browse files
Files changed (1) hide show
  1. app/utils/breaking_news_scorer.py +19 -15
app/utils/breaking_news_scorer.py CHANGED
@@ -243,31 +243,35 @@ class BreakingNewsScorer:
243
 
244
  def _score_engagement(self, news_item: Dict) -> float:
245
  """Score based on social engagement metrics"""
246
- engagement = news_item.get('engagement', {})
247
-
248
- if not engagement:
249
- return 5.0 # Default score if no engagement data
250
-
251
  score = 0.0
 
252
 
253
- # Twitter engagement
254
- if 'likes' in engagement:
255
- likes = engagement['likes']
 
256
  score += min(likes / 1000, 5.0) # Max 5 points for likes
257
 
258
- if 'retweets' in engagement:
259
- retweets = engagement['retweets']
 
260
  score += min(retweets / 500, 5.0) # Max 5 points for retweets
261
 
262
- # Reddit engagement
263
- if 'score' in engagement:
264
- reddit_score = engagement['score']
 
265
  score += min(reddit_score / 1000, 5.0) # Max 5 points for score
266
 
267
- if 'comments' in engagement:
268
- comments = engagement['comments']
 
269
  score += min(comments / 200, 5.0) # Max 5 points for comments
270
 
 
 
 
 
271
  return min(score, 15.0)
272
 
273
  def _score_sentiment(self, sentiment: str) -> float:
 
243
 
244
  def _score_engagement(self, news_item: Dict) -> float:
245
  """Score based on social engagement metrics"""
 
 
 
 
 
246
  score = 0.0
247
+ has_engagement = False
248
 
249
+ # Twitter engagement (top-level fields)
250
+ likes = news_item.get('likes', 0)
251
+ if likes > 0:
252
+ has_engagement = True
253
  score += min(likes / 1000, 5.0) # Max 5 points for likes
254
 
255
+ retweets = news_item.get('retweets', 0)
256
+ if retweets > 0:
257
+ has_engagement = True
258
  score += min(retweets / 500, 5.0) # Max 5 points for retweets
259
 
260
+ # Reddit engagement (top-level fields)
261
+ reddit_score = news_item.get('reddit_score', 0)
262
+ if reddit_score > 0:
263
+ has_engagement = True
264
  score += min(reddit_score / 1000, 5.0) # Max 5 points for score
265
 
266
+ comments = news_item.get('reddit_comments', 0)
267
+ if comments > 0:
268
+ has_engagement = True
269
  score += min(comments / 200, 5.0) # Max 5 points for comments
270
 
271
+ # If no engagement data, return default score
272
+ if not has_engagement:
273
+ return 5.0
274
+
275
  return min(score, 15.0)
276
 
277
  def _score_sentiment(self, sentiment: str) -> float: