POTE/scripts/daily_update.sh
ilia 34aebb1c2e PR4: Phase 2 Analytics Foundation
Complete analytics module with returns, benchmarks, and performance metrics.

New Modules:
- src/pote/analytics/returns.py: Return calculator for trades
- src/pote/analytics/benchmarks.py: Benchmark comparison & alpha
- src/pote/analytics/metrics.py: Performance aggregations

Scripts:
- scripts/analyze_official.py: Analyze specific official
- scripts/calculate_all_returns.py: System-wide analysis

Tests:
- tests/test_analytics.py: Full coverage of analytics

Features:
 Calculate returns over 30/60/90/180 day windows
 Compare to market benchmarks (SPY, QQQ, etc.)
 Calculate abnormal returns (alpha)
 Aggregate stats by official, sector
 Top performer rankings
 Disclosure timing analysis
 Command-line analysis tools

~1,210 lines of new code, all tested
2025-12-15 11:33:21 -05:00

77 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
# Daily update script for POTE
# Run this via cron to automatically fetch new data
set -e
# Configuration
POTE_DIR="/home/poteapp/pote"
LOG_DIR="/home/poteapp/logs"
LOG_FILE="$LOG_DIR/daily_update_$(date +%Y%m%d).log"
# Ensure log directory exists
mkdir -p "$LOG_DIR"
echo "=== POTE Daily Update: $(date) ===" | tee -a "$LOG_FILE"
cd "$POTE_DIR"
source venv/bin/activate
# 1. Fetch new congressional trades (if House Stock Watcher is back up)
echo "[1/4] Fetching congressional trades..." | tee -a "$LOG_FILE"
if python scripts/fetch_congressional_trades.py --days 7 >> "$LOG_FILE" 2>&1; then
echo "✓ Trades fetched successfully" | tee -a "$LOG_FILE"
else
echo "✗ Trade fetch failed (API might be down)" | tee -a "$LOG_FILE"
fi
# 2. Enrich any new securities
echo "[2/4] Enriching securities..." | tee -a "$LOG_FILE"
if python scripts/enrich_securities.py >> "$LOG_FILE" 2>&1; then
echo "✓ Securities enriched" | tee -a "$LOG_FILE"
else
echo "✗ Security enrichment failed" | tee -a "$LOG_FILE"
fi
# 3. Update prices for all securities
echo "[3/4] Fetching price data..." | tee -a "$LOG_FILE"
if python scripts/fetch_sample_prices.py >> "$LOG_FILE" 2>&1; then
echo "✓ Prices updated" | tee -a "$LOG_FILE"
else
echo "✗ Price fetch failed" | tee -a "$LOG_FILE"
fi
# 4. Generate summary
echo "[4/4] Generating summary..." | tee -a "$LOG_FILE"
python << 'EOF' | tee -a "$LOG_FILE"
from sqlalchemy import text
from pote.db import engine
from datetime import datetime, timedelta
with engine.connect() as conn:
# Get counts
officials = conn.execute(text("SELECT COUNT(*) FROM officials")).scalar()
trades = conn.execute(text("SELECT COUNT(*) FROM trades")).scalar()
securities = conn.execute(text("SELECT COUNT(*) FROM securities")).scalar()
# Get new trades in last 7 days
week_ago = (datetime.now() - timedelta(days=7)).strftime('%Y-%m-%d')
new_trades = conn.execute(
text(f"SELECT COUNT(*) FROM trades WHERE created_at >= '{week_ago}'")
).scalar()
print(f"\n📊 Database Summary:")
print(f" Officials: {officials:,}")
print(f" Securities: {securities:,}")
print(f" Trades: {trades:,}")
print(f" New (7d): {new_trades:,}")
EOF
echo "" | tee -a "$LOG_FILE"
echo "=== Update Complete: $(date) ===" | tee -a "$LOG_FILE"
echo "" | tee -a "$LOG_FILE"
# Keep only last 30 days of logs
find "$LOG_DIR" -name "daily_update_*.log" -mtime +30 -delete