Dmitry Beresnev
commited on
Commit
ยท
0e4b579
1
Parent(s):
4257ee1
fix news stats calcualtion
Browse files- 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
app/pages/05_Dashboard.py
CHANGED
|
@@ -124,32 +124,26 @@ with st.sidebar:
|
|
| 124 |
st.markdown("---")
|
| 125 |
st.markdown("### ๐ Feed Statistics")
|
| 126 |
|
| 127 |
-
#
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 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("
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
"""
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
'breaking': 0,
|
| 546 |
-
'last_update': 'Never',
|
| 547 |
-
'by_category': {}
|
| 548 |
-
}
|
| 549 |
-
|
| 550 |
-
df = pd.DataFrame(self.news_cache)
|
| 551 |
return {
|
| 552 |
-
'total':
|
| 553 |
-
'high_impact':
|
| 554 |
-
'breaking':
|
| 555 |
-
'last_update':
|
| 556 |
-
'by_category':
|
| 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 |
-
"""
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 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':
|
| 309 |
-
'high_impact':
|
| 310 |
-
'breaking':
|
| 311 |
'by_category': {
|
| 312 |
-
'macro':
|
| 313 |
-
'markets':
|
| 314 |
-
'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 |
-
"""
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
'breaking': 0,
|
| 484 |
-
'last_update': 'Never',
|
| 485 |
-
'by_category': {}
|
| 486 |
-
}
|
| 487 |
-
|
| 488 |
-
df = pd.DataFrame(self.news_cache)
|
| 489 |
return {
|
| 490 |
-
'total':
|
| 491 |
-
'high_impact':
|
| 492 |
-
'breaking':
|
| 493 |
-
'last_update':
|
| 494 |
-
'by_category':
|
| 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 |
}
|