Dmitry Beresnev commited on
Commit ·
0e4b579
1
Parent(s): 4257ee1
fix news stats calcualtion
Browse filesFiles changed (4)
123 unmodified lines124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155123 unmodified linesst.markdown("---")st.markdown("### 📊 Feed Statistics")# Calculate combined statstotal_stories = 0high_impact_count = 0breaking_count = 0if twitter_monitor:twitter_stats = twitter_monitor.get_statistics()total_stories += twitter_stats['total']high_impact_count += twitter_stats['high_impact']breaking_count += twitter_stats['breaking']if reddit_monitor:reddit_stats = reddit_monitor.get_statistics()total_stories += reddit_stats['total']high_impact_count += reddit_stats['high_impact']breaking_count += reddit_stats['breaking']if rss_monitor:rss_stats = rss_monitor.get_statistics()total_stories += rss_stats['total']high_impact_count += rss_stats['high_impact']breaking_count += rss_stats['breaking']st.metric("Total Stories", total_stories)st.metric("High Impact", high_impact_count)st.metric("Breaking News", breaking_count)st.markdown("---")st.markdown("### ℹ️ Sources")123 unmodified lines124125126127128129130131132133134135136137138139140141142143144145146147148149123 unmodified linesst.markdown("---")st.markdown("### 📊 Feed Statistics")# Get cache statistics from cache managercache_stats = cache_manager.get_statistics()# Calculate totals from cachetotal_stories = (cache_stats['twitter']['items'] +cache_stats['reddit']['items'] +cache_stats['rss']['items'])# Display metricsst.metric("Total Stories", total_stories)st.metric("Cache Status", "✅ Active" if total_stories > 0 else "⏳ Loading")# Show cache age for transparencyif cache_stats['twitter']['is_valid']:age = int(cache_stats['twitter']['age_seconds'])st.caption(f"🕐 Cache age: {age}s / 180s")else:st.caption("🔄 Fetching fresh data...")st.markdown("---")st.markdown("### ℹ️ Sources")
536 unmodified lines537538539540541542543544545546547548549550551552553554555556557536 unmodified linesreturn self.get_news(impact='high')def get_statistics(self) -> Dict:"""Get feed statistics"""if not self.news_cache:return {'total': 0,'high_impact': 0,'breaking': 0,'last_update': 'Never','by_category': {}}df = pd.DataFrame(self.news_cache)return {'total': len(df),'high_impact': len(df[df['impact'] == 'high']),'breaking': len(df[df['is_breaking'] == True]),'last_update': self.last_fetch.strftime('%H:%M:%S') if self.last_fetch else 'Never','by_category': df['category'].value_counts().to_dict()}536 unmodified lines537538539540541542543544545546547548549550551536 unmodified linesreturn self.get_news(impact='high')def get_statistics(self) -> Dict:"""Get feed statisticsNote: Statistics are now managed by NewsCacheManagerThis method returns empty stats for backward compatibility"""return {'total': 0,'high_impact': 0,'breaking': 0,'last_update': 'Managed by cache','by_category': {}}
294 unmodified lines295296297298299300301302303304305306307308309310311312313314315316294 unmodified linesreturn all_posts[:max_posts]def get_statistics(self) -> Dict:"""Get statistics about scraped Reddit posts"""if not self.news_cache:posts = self.scrape_reddit_news()self.news_cache = poststotal = len(self.news_cache)high_impact = len([p for p in self.news_cache if p['impact'] == 'high'])breaking = len([p for p in self.news_cache if p.get('is_breaking', False)])return {'total': total,'high_impact': high_impact,'breaking': breaking,'by_category': {'macro': len([p for p in self.news_cache if p['category'] == 'macro']),'markets': len([p for p in self.news_cache if p['category'] == 'markets']),'geopolitical': len([p for p in self.news_cache if p['category'] == 'geopolitical'])}}294 unmodified lines295296297298299300301302303304305306307308309310311312294 unmodified linesreturn all_posts[:max_posts]def get_statistics(self) -> Dict:"""Get statistics about scraped Reddit postsNote: Statistics are now managed by NewsCacheManagerThis method returns empty stats for backward compatibility"""return {'total': 0,'high_impact': 0,'breaking': 0,'by_category': {'macro': 0,'markets': 0,'geopolitical': 0}}
474 unmodified lines475476477478479480481482483484485486487488489490491492493494495474 unmodified linesreturn mock_newsdef get_statistics(self) -> Dict:"""Get statistics about cached news"""if not self.news_cache:return {'total': 0,'high_impact': 0,'breaking': 0,'last_update': 'Never','by_category': {}}df = pd.DataFrame(self.news_cache)return {'total': len(df),'high_impact': len(df[df['impact'] == 'high']),'breaking': len(df[df['is_breaking'] == True]),'last_update': self.last_fetch.strftime('%H:%M:%S') if self.last_fetch else 'Never','by_category': df['category'].value_counts().to_dict()}474 unmodified lines475476477478479480481482483484485486487488489474 unmodified linesreturn mock_newsdef get_statistics(self) -> Dict:"""Get statistics about cached newsNote: Statistics are now managed by NewsCacheManagerThis method returns empty stats for backward compatibility"""return {'total': 0,'high_impact': 0,'breaking': 0,'last_update': 'Managed by cache','by_category': {}}
app/pages/05_Dashboard.py+18-24
app/services/news_scraper.py+10-16
app/services/reddit_news.py+11-15
app/services/twitter_news_playwright.py+10-16