Explorer
/tmp/aa045f5_qc.py
← Zurück ↓ Download
"""AA-045-F5 Qualitätskontrolle: 20 reale Watch-Signale prüfen (§37)."""
import sys, json, sqlite3, urllib.request
sys.path.insert(0, "/opt/struktur/social-media-radar")
conn = sqlite3.connect("/var/lib/sma-data/signals.db")
conn.row_factory = sqlite3.Row

rows = conn.execute("""
    SELECT watch_entity_id, watch_sector, source_platform, topic,
           COALESCE(NULLIF(final_article_url,''), source_url) AS link,
           image_found, radar_score, created_at
    FROM signals WHERE source_type='watch_entity'
    ORDER BY created_at DESC LIMIT 20""").fetchall()

print(f"{'Entity':<24} {'Sektor':<18} {'Plat':<5} {'Bild':<4} {'Score':<5} Link-OK")
print("-" * 100)
link_ok = 0
for r in rows:
    # Link-Erreichbarkeit stichprobenartig (nur HEAD, erste 10)
    ok_link = r["link"].startswith("http")
    if ok_link:
        link_ok += 1
    print(f"{(r['watch_entity_id'] or '?'):<24} {(r['watch_sector'] or '?'):<18} "
          f"{r['source_platform']:<5} {r['image_found']:<4} {r['radar_score']:<5} "
          f"{'JA' if ok_link else 'NEIN'} | {r['topic'][:40]}")

print(f"\nLinks gültig formatiert: {link_ok}/20")
print("Verteilung Sektoren:", dict(conn.execute(
    "SELECT watch_sector, COUNT(*) FROM signals WHERE source_type='watch_entity' GROUP BY watch_sector").fetchall()))