Dmitry Beresnev commited on
Commit
0e4b579
ยท
1 Parent(s): 4257ee1

fix news stats calcualtion

Browse files
app/pages/05_Dashboard.py CHANGED
@@ -124,32 +124,26 @@ with st.sidebar:
124
  st.markdown("---")
125
  st.markdown("### ๐Ÿ“Š Feed Statistics")
126
 
127
- # Calculate combined stats
128
- total_stories = 0
129
- high_impact_count = 0
130
- breaking_count = 0
131
-
132
- if twitter_monitor:
133
- twitter_stats = twitter_monitor.get_statistics()
134
- total_stories += twitter_stats['total']
135
- high_impact_count += twitter_stats['high_impact']
136
- breaking_count += twitter_stats['breaking']
137
-
138
- if reddit_monitor:
139
- reddit_stats = reddit_monitor.get_statistics()
140
- total_stories += reddit_stats['total']
141
- high_impact_count += reddit_stats['high_impact']
142
- breaking_count += reddit_stats['breaking']
143
-
144
- if rss_monitor:
145
- rss_stats = rss_monitor.get_statistics()
146
- total_stories += rss_stats['total']
147
- high_impact_count += rss_stats['high_impact']
148
- breaking_count += rss_stats['breaking']
149
 
 
150
  st.metric("Total Stories", total_stories)
151
- st.metric("High Impact", high_impact_count)
152
- st.metric("Breaking News", breaking_count)
 
 
 
 
 
 
153
 
154
  st.markdown("---")
155
  st.markdown("### โ„น๏ธ Sources")
 
124
  st.markdown("---")
125
  st.markdown("### ๐Ÿ“Š Feed Statistics")
126
 
127
+ # Get cache statistics from cache manager
128
+ cache_stats = cache_manager.get_statistics()
129
+
130
+ # Calculate totals from cache
131
+ total_stories = (
132
+ cache_stats['twitter']['items'] +
133
+ cache_stats['reddit']['items'] +
134
+ cache_stats['rss']['items']
135
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
136
 
137
+ # Display metrics
138
  st.metric("Total Stories", total_stories)
139
+ st.metric("Cache Status", "โœ… Active" if total_stories > 0 else "โณ Loading")
140
+
141
+ # Show cache age for transparency
142
+ if cache_stats['twitter']['is_valid']:
143
+ age = int(cache_stats['twitter']['age_seconds'])
144
+ st.caption(f"๐Ÿ• Cache age: {age}s / 180s")
145
+ else:
146
+ st.caption("๐Ÿ”„ Fetching fresh data...")
147
 
148
  st.markdown("---")
149
  st.markdown("### โ„น๏ธ Sources")
app/services/news_scraper.py CHANGED
@@ -537,21 +537,15 @@ class FinanceNewsScraper:
537
  return self.get_news(impact='high')
538
 
539
  def get_statistics(self) -> Dict:
540
- """Get feed statistics"""
541
- if not self.news_cache:
542
- return {
543
- 'total': 0,
544
- 'high_impact': 0,
545
- 'breaking': 0,
546
- 'last_update': 'Never',
547
- 'by_category': {}
548
- }
549
-
550
- df = pd.DataFrame(self.news_cache)
551
  return {
552
- 'total': len(df),
553
- 'high_impact': len(df[df['impact'] == 'high']),
554
- 'breaking': len(df[df['is_breaking'] == True]),
555
- 'last_update': self.last_fetch.strftime('%H:%M:%S') if self.last_fetch else 'Never',
556
- 'by_category': df['category'].value_counts().to_dict()
557
  }
 
537
  return self.get_news(impact='high')
538
 
539
  def get_statistics(self) -> Dict:
540
+ """
541
+ Get feed statistics
542
+ Note: Statistics are now managed by NewsCacheManager
543
+ This method returns empty stats for backward compatibility
544
+ """
 
 
 
 
 
 
545
  return {
546
+ 'total': 0,
547
+ 'high_impact': 0,
548
+ 'breaking': 0,
549
+ 'last_update': 'Managed by cache',
550
+ 'by_category': {}
551
  }
app/services/reddit_news.py CHANGED
@@ -295,22 +295,18 @@ class RedditFinanceMonitor:
295
  return all_posts[:max_posts]
296
 
297
  def get_statistics(self) -> Dict:
298
- """Get statistics about scraped Reddit posts"""
299
- if not self.news_cache:
300
- posts = self.scrape_reddit_news()
301
- self.news_cache = posts
302
-
303
- total = len(self.news_cache)
304
- high_impact = len([p for p in self.news_cache if p['impact'] == 'high'])
305
- breaking = len([p for p in self.news_cache if p.get('is_breaking', False)])
306
-
307
  return {
308
- 'total': total,
309
- 'high_impact': high_impact,
310
- 'breaking': breaking,
311
  'by_category': {
312
- 'macro': len([p for p in self.news_cache if p['category'] == 'macro']),
313
- 'markets': len([p for p in self.news_cache if p['category'] == 'markets']),
314
- 'geopolitical': len([p for p in self.news_cache if p['category'] == 'geopolitical'])
315
  }
316
  }
 
295
  return all_posts[:max_posts]
296
 
297
  def get_statistics(self) -> Dict:
298
+ """
299
+ Get statistics about scraped Reddit posts
300
+ Note: Statistics are now managed by NewsCacheManager
301
+ This method returns empty stats for backward compatibility
302
+ """
 
 
 
 
303
  return {
304
+ 'total': 0,
305
+ 'high_impact': 0,
306
+ 'breaking': 0,
307
  'by_category': {
308
+ 'macro': 0,
309
+ 'markets': 0,
310
+ 'geopolitical': 0
311
  }
312
  }
app/services/twitter_news_playwright.py CHANGED
@@ -475,21 +475,15 @@ class TwitterFinanceMonitor:
475
  return mock_news
476
 
477
  def get_statistics(self) -> Dict:
478
- """Get statistics about cached news"""
479
- if not self.news_cache:
480
- return {
481
- 'total': 0,
482
- 'high_impact': 0,
483
- 'breaking': 0,
484
- 'last_update': 'Never',
485
- 'by_category': {}
486
- }
487
-
488
- df = pd.DataFrame(self.news_cache)
489
  return {
490
- 'total': len(df),
491
- 'high_impact': len(df[df['impact'] == 'high']),
492
- 'breaking': len(df[df['is_breaking'] == True]),
493
- 'last_update': self.last_fetch.strftime('%H:%M:%S') if self.last_fetch else 'Never',
494
- 'by_category': df['category'].value_counts().to_dict()
495
  }
 
475
  return mock_news
476
 
477
  def get_statistics(self) -> Dict:
478
+ """
479
+ Get statistics about cached news
480
+ Note: Statistics are now managed by NewsCacheManager
481
+ This method returns empty stats for backward compatibility
482
+ """
 
 
 
 
 
 
483
  return {
484
+ 'total': 0,
485
+ 'high_impact': 0,
486
+ 'breaking': 0,
487
+ 'last_update': 'Managed by cache',
488
+ 'by_category': {}
489
  }