Bidirektionale Monitor-Verbindung + Klick-Zusammenfassungen
GLOBE -> MONITOR (Auto-Push): - Alle 10min werden NASA EONET + USGS M4.5+ Erdbeben automatisch als Artikel in die Naturkatastrophen-Lage (ID 45) gepusht - Monitor verifiziert und erstellt Zusammenfassung - Duplikat-Check verhindert doppelte Eintraege MONITOR -> GLOBE (Klick-Summaries): - Katastrophen-Layer holt Monitor-Daten beim Start - Klick auf Katastrophe/Erdbeben zeigt: 1. Ereignis-Details (Typ, Ort, Magnitude) 2. Monitor-Zusammenfassung (wenn Lage in der Region existiert) - Naechsten Monitor-Punkt im 5-Grad-Radius gesucht - Summary gekuerzt auf 600 Zeichen, Markdown bereinigt
Dieser Commit ist enthalten in:
121
src/data_push.py
Normale Datei
121
src/data_push.py
Normale Datei
@@ -0,0 +1,121 @@
|
|||||||
|
"""Auto-Push: Sendet Globe-Ereignisse an den AegisSight Monitor."""
|
||||||
|
import asyncio
|
||||||
|
import logging
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
|
||||||
|
import httpx
|
||||||
|
|
||||||
|
logger = logging.getLogger("globe.push")
|
||||||
|
|
||||||
|
_MONITOR_URL = os.getenv("MONITOR_API_URL", "https://monitor.aegis-sight.de/api/public")
|
||||||
|
_MONITOR_KEY = os.getenv("MONITOR_API_KEY", "")
|
||||||
|
_DISASTER_INCIDENT_ID = int(os.getenv("DISASTER_INCIDENT_ID", "0"))
|
||||||
|
|
||||||
|
_task = None
|
||||||
|
_last_push: dict = {"eonet": 0, "usgs": 0}
|
||||||
|
|
||||||
|
|
||||||
|
async def _push_to_monitor(events: list):
|
||||||
|
"""Sendet Events an den Monitor-Ingest-Endpoint."""
|
||||||
|
if not _DISASTER_INCIDENT_ID or not _MONITOR_KEY or not events:
|
||||||
|
return 0
|
||||||
|
try:
|
||||||
|
async with httpx.AsyncClient(timeout=15) as client:
|
||||||
|
r = await client.post(
|
||||||
|
f"{_MONITOR_URL}/globe-ingest",
|
||||||
|
json={"incident_id": _DISASTER_INCIDENT_ID, "events": events},
|
||||||
|
headers={"X-API-Key": _MONITOR_KEY},
|
||||||
|
)
|
||||||
|
if r.status_code == 200:
|
||||||
|
data = r.json()
|
||||||
|
inserted = data.get("inserted", 0)
|
||||||
|
if inserted > 0:
|
||||||
|
logger.info(f"Push: {inserted} Ereignisse an Monitor gesendet")
|
||||||
|
return inserted
|
||||||
|
else:
|
||||||
|
logger.warning(f"Push Fehler: {r.status_code} {r.text[:200]}")
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Push Fehler: {e}")
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
async def _push_loop():
|
||||||
|
"""Periodisch EONET + USGS Daten an Monitor pushen."""
|
||||||
|
await asyncio.sleep(30) # Warten bis Daten geladen
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
events = []
|
||||||
|
|
||||||
|
# NASA EONET Katastrophen
|
||||||
|
try:
|
||||||
|
async with httpx.AsyncClient(timeout=10) as client:
|
||||||
|
r = await client.get("https://eonet.gsfc.nasa.gov/api/v3/events?status=open&limit=50")
|
||||||
|
if r.status_code == 200:
|
||||||
|
for evt in r.json().get("events", []):
|
||||||
|
geom = evt.get("geometry", [])
|
||||||
|
if not geom:
|
||||||
|
continue
|
||||||
|
latest = geom[-1]
|
||||||
|
coords = latest.get("coordinates", [])
|
||||||
|
if len(coords) < 2:
|
||||||
|
continue
|
||||||
|
cats = evt.get("categories", [])
|
||||||
|
cat_name = cats[0]["title"] if cats else "Unbekannt"
|
||||||
|
events.append({
|
||||||
|
"title": f"[{cat_name}] {evt.get('title', '?')}",
|
||||||
|
"source": "NASA EONET",
|
||||||
|
"url": evt.get("link", ""),
|
||||||
|
"description": f"Naturereignis: {evt.get('title', '')}. "
|
||||||
|
f"Kategorie: {cat_name}. "
|
||||||
|
f"Quellen: {', '.join(s.get('id','') for s in evt.get('sources',[]))}",
|
||||||
|
"lat": coords[1],
|
||||||
|
"lon": coords[0],
|
||||||
|
"location": evt.get("title", "")[:50],
|
||||||
|
"category": "primary",
|
||||||
|
})
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"EONET fetch: {e}")
|
||||||
|
|
||||||
|
# USGS Erdbeben (nur M4.5+ fuer Monitor — kleinere sind zu viele)
|
||||||
|
try:
|
||||||
|
async with httpx.AsyncClient(timeout=10) as client:
|
||||||
|
r = await client.get("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_day.geojson")
|
||||||
|
if r.status_code == 200:
|
||||||
|
for f in r.json().get("features", []):
|
||||||
|
c = f["geometry"]["coordinates"]
|
||||||
|
p = f["properties"]
|
||||||
|
mag = p.get("mag", 0)
|
||||||
|
events.append({
|
||||||
|
"title": f"[Erdbeben M{mag:.1f}] {p.get('place', '?')}",
|
||||||
|
"source": "USGS Earthquake",
|
||||||
|
"url": p.get("url", ""),
|
||||||
|
"description": f"Erdbeben der Staerke {mag:.1f} bei {p.get('place', '?')}. "
|
||||||
|
f"Tiefe: {c[2]:.0f} km. "
|
||||||
|
f"Zeit: {p.get('time', '')}",
|
||||||
|
"lat": c[1],
|
||||||
|
"lon": c[0],
|
||||||
|
"location": p.get("place", "")[:50],
|
||||||
|
"category": "primary" if mag >= 6 else "secondary",
|
||||||
|
})
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"USGS fetch: {e}")
|
||||||
|
|
||||||
|
if events:
|
||||||
|
await _push_to_monitor(events)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Push loop error: {e}")
|
||||||
|
|
||||||
|
await asyncio.sleep(600) # Alle 10 Minuten
|
||||||
|
|
||||||
|
|
||||||
|
def start_push_service():
|
||||||
|
"""Startet den Auto-Push Background-Task."""
|
||||||
|
global _task
|
||||||
|
if not _DISASTER_INCIDENT_ID:
|
||||||
|
logger.info("Push: DISASTER_INCIDENT_ID nicht gesetzt, Push deaktiviert")
|
||||||
|
return
|
||||||
|
if _task is None or _task.done():
|
||||||
|
_task = asyncio.create_task(_push_loop())
|
||||||
|
logger.info(f"Push-Service gestartet (Lage-ID: {_DISASTER_INCIDENT_ID})")
|
||||||
@@ -34,6 +34,7 @@ from data_gdelt import router as gdelt_router
|
|||||||
from data_satellites import router as satellites_router
|
from data_satellites import router as satellites_router
|
||||||
from data_disasters import router as disasters_router
|
from data_disasters import router as disasters_router
|
||||||
from data_monitor import router as monitor_router
|
from data_monitor import router as monitor_router
|
||||||
|
from data_push import start_push_service
|
||||||
|
|
||||||
# Alle Daten-APIs hinter Auth
|
# Alle Daten-APIs hinter Auth
|
||||||
app.include_router(flights_router, prefix="/api", dependencies=[Depends(get_current_user)])
|
app.include_router(flights_router, prefix="/api", dependencies=[Depends(get_current_user)])
|
||||||
@@ -65,3 +66,4 @@ async def startup():
|
|||||||
logger.info("AegisSight Globe gestartet")
|
logger.info("AegisSight Globe gestartet")
|
||||||
start_ais_collector()
|
start_ais_collector()
|
||||||
start_flight_collector()
|
start_flight_collector()
|
||||||
|
start_push_service()
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
/**
|
/**
|
||||||
* Katastrophen-Layer: NASA EONET + USGS Erdbeben kombiniert.
|
* Katastrophen-Layer: NASA EONET + USGS Erdbeben.
|
||||||
|
* Bei Klick: zeigt Details + Monitor-Zusammenfassung falls verfuegbar.
|
||||||
*/
|
*/
|
||||||
const DisastersLayer = {
|
const DisastersLayer = {
|
||||||
_viewer: null,
|
_viewer: null,
|
||||||
_dataSource: null,
|
_dataSource: null,
|
||||||
_interval: null,
|
_interval: null,
|
||||||
_count: 0,
|
_count: 0,
|
||||||
|
_monitorData: null,
|
||||||
|
|
||||||
start(viewer) {
|
start(viewer) {
|
||||||
if (this._dataSource) return;
|
if (this._dataSource) return;
|
||||||
@@ -13,6 +15,7 @@ const DisastersLayer = {
|
|||||||
this._dataSource = new Cesium.CustomDataSource('disasters');
|
this._dataSource = new Cesium.CustomDataSource('disasters');
|
||||||
viewer.dataSources.add(this._dataSource);
|
viewer.dataSources.add(this._dataSource);
|
||||||
this._fetch();
|
this._fetch();
|
||||||
|
this._fetchMonitorContext();
|
||||||
var self = this;
|
var self = this;
|
||||||
this._interval = setInterval(function() { self._fetch(); }, 600000);
|
this._interval = setInterval(function() { self._fetch(); }, 600000);
|
||||||
},
|
},
|
||||||
@@ -23,6 +26,47 @@ const DisastersLayer = {
|
|||||||
this._count = 0;
|
this._count = 0;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_fetchMonitorContext() {
|
||||||
|
var self = this;
|
||||||
|
fetch('/api/monitor-feed')
|
||||||
|
.then(function(r) { return r.json(); })
|
||||||
|
.then(function(data) { self._monitorData = data; })
|
||||||
|
.catch(function() {});
|
||||||
|
},
|
||||||
|
|
||||||
|
_findMonitorSummary(lat, lon) {
|
||||||
|
if (!this._monitorData || !this._monitorData.incidents) return null;
|
||||||
|
// Finde naechsten Monitor-Punkt und dessen Lage-Summary
|
||||||
|
var features = this._monitorData.features || [];
|
||||||
|
var best = null, bestDist = 999;
|
||||||
|
for (var i = 0; i < features.length; i++) {
|
||||||
|
var c = features[i].geometry.coordinates;
|
||||||
|
var d = Math.abs(c[1] - lat) + Math.abs(c[0] - lon);
|
||||||
|
if (d < bestDist) { bestDist = d; best = features[i]; }
|
||||||
|
}
|
||||||
|
if (!best || bestDist > 5) return null;
|
||||||
|
var incId = best.properties.incident_id;
|
||||||
|
var incidents = this._monitorData.incidents || [];
|
||||||
|
for (var j = 0; j < incidents.length; j++) {
|
||||||
|
if (incidents[j].id === incId && incidents[j].summary) return incidents[j];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
},
|
||||||
|
|
||||||
|
_buildMonitorHtml(incident) {
|
||||||
|
if (!incident || !incident.summary) return '';
|
||||||
|
var summary = incident.summary
|
||||||
|
.replace(/##?\s*/g, '').replace(/\*\*/g, '').replace(/\[(\d+)\]/g, '')
|
||||||
|
.substring(0, 600);
|
||||||
|
return '<div style="border-top:1px solid #333;padding-top:8px;margin-top:8px">' +
|
||||||
|
'<div style="color:#00ff88;font-size:10px;letter-spacing:1px;margin-bottom:4px">MONITOR: ' +
|
||||||
|
(incident.title || 'LAGE').toUpperCase() + '</div>' +
|
||||||
|
'<div style="color:#ccc;font-size:11px;line-height:1.5">' + summary +
|
||||||
|
(incident.summary.length > 600 ? '...' : '') + '</div>' +
|
||||||
|
'<div style="color:#666;font-size:9px;margin-top:4px">Stand: ' +
|
||||||
|
new Date(incident.updated_at).toLocaleString('de-DE') + '</div></div>';
|
||||||
|
},
|
||||||
|
|
||||||
_fetch() {
|
_fetch() {
|
||||||
var self = this;
|
var self = this;
|
||||||
var loadEl = document.getElementById('loading-disasters');
|
var loadEl = document.getElementById('loading-disasters');
|
||||||
@@ -37,11 +81,9 @@ const DisastersLayer = {
|
|||||||
.then(function(results) {
|
.then(function(results) {
|
||||||
if (!self._dataSource) return;
|
if (!self._dataSource) return;
|
||||||
self._dataSource.entities.removeAll();
|
self._dataSource.entities.removeAll();
|
||||||
var events = results[0].events || [];
|
self._renderEonet(results[0].events || []);
|
||||||
var quakes = results[1].features || [];
|
self._renderQuakes(results[1].features || []);
|
||||||
self._renderEonet(events);
|
self._count = (results[0].events || []).length + (results[1].features || []).length;
|
||||||
self._renderQuakes(quakes);
|
|
||||||
self._count = events.length + quakes.length;
|
|
||||||
if (statusEl) statusEl.textContent = self._count + ' Ereignisse';
|
if (statusEl) statusEl.textContent = self._count + ' Ereignisse';
|
||||||
})
|
})
|
||||||
.catch(function(e) { console.warn('Disasters error:', e); if (statusEl) statusEl.textContent = 'Fehler'; })
|
.catch(function(e) { console.warn('Disasters error:', e); if (statusEl) statusEl.textContent = 'Fehler'; })
|
||||||
@@ -68,6 +110,9 @@ const DisastersLayer = {
|
|||||||
var latest = geom[geom.length - 1];
|
var latest = geom[geom.length - 1];
|
||||||
var coords = latest.coordinates;
|
var coords = latest.coordinates;
|
||||||
if (!coords || coords.length < 2) return;
|
if (!coords || coords.length < 2) return;
|
||||||
|
|
||||||
|
var monitorHtml = self._buildMonitorHtml(self._findMonitorSummary(coords[1], coords[0]));
|
||||||
|
|
||||||
self._dataSource.entities.add({
|
self._dataSource.entities.add({
|
||||||
position: Cesium.Cartesian3.fromDegrees(coords[0], coords[1], 0),
|
position: Cesium.Cartesian3.fromDegrees(coords[0], coords[1], 0),
|
||||||
point: {
|
point: {
|
||||||
@@ -75,7 +120,6 @@ const DisastersLayer = {
|
|||||||
color: Cesium.Color.fromCssColorString(icon.color),
|
color: Cesium.Color.fromCssColorString(icon.color),
|
||||||
outlineColor: Cesium.Color.fromCssColorString(icon.color).withAlpha(0.4),
|
outlineColor: Cesium.Color.fromCssColorString(icon.color).withAlpha(0.4),
|
||||||
outlineWidth: 3,
|
outlineWidth: 3,
|
||||||
heightReference: Cesium.HeightReference.NONE,
|
|
||||||
},
|
},
|
||||||
label: {
|
label: {
|
||||||
text: icon.label,
|
text: icon.label,
|
||||||
@@ -88,10 +132,11 @@ const DisastersLayer = {
|
|||||||
scale: 0.7,
|
scale: 0.7,
|
||||||
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 5000000),
|
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 5000000),
|
||||||
},
|
},
|
||||||
description: '<div style="font-family:monospace;font-size:13px;padding:8px">' +
|
description: '<div style="font-family:monospace;font-size:12px;padding:10px;max-width:400px;line-height:1.6">' +
|
||||||
'<strong style="color:' + icon.color + '">' + icon.label.toUpperCase() + '</strong><br>' +
|
'<strong style="color:' + icon.color + ';font-size:14px">' + icon.label.toUpperCase() + '</strong><br>' +
|
||||||
'<span style="color:#e0e0e0">' + (evt.title || '?') + '</span><br>' +
|
'<span style="color:#e0e0e0">' + (evt.title || '?') + '</span><br>' +
|
||||||
'<span style="color:#888">Quellen: ' + (evt.sources || []).map(function(s) { return s.id; }).join(', ') + '</span></div>',
|
'<span style="color:#888;font-size:10px">Quellen: ' + (evt.sources || []).map(function(s) { return s.id; }).join(', ') + '</span>' +
|
||||||
|
monitorHtml + '</div>',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -105,6 +150,9 @@ const DisastersLayer = {
|
|||||||
var mag = p.mag || 1;
|
var mag = p.mag || 1;
|
||||||
var ageH = (now - p.time) / 3600000;
|
var ageH = (now - p.time) / 3600000;
|
||||||
var color = ageH < 1 ? '#ff0000' : ageH < 6 ? '#ff6600' : ageH < 12 ? '#ffaa00' : '#ffdd00';
|
var color = ageH < 1 ? '#ff0000' : ageH < 6 ? '#ff6600' : ageH < 12 ? '#ffaa00' : '#ffdd00';
|
||||||
|
|
||||||
|
var monitorHtml = self._buildMonitorHtml(self._findMonitorSummary(c[1], c[0]));
|
||||||
|
|
||||||
self._dataSource.entities.add({
|
self._dataSource.entities.add({
|
||||||
position: Cesium.Cartesian3.fromDegrees(c[0], c[1], 0),
|
position: Cesium.Cartesian3.fromDegrees(c[0], c[1], 0),
|
||||||
point: {
|
point: {
|
||||||
@@ -112,7 +160,6 @@ const DisastersLayer = {
|
|||||||
color: Cesium.Color.fromCssColorString(color),
|
color: Cesium.Color.fromCssColorString(color),
|
||||||
outlineColor: Cesium.Color.fromCssColorString(color).withAlpha(0.4),
|
outlineColor: Cesium.Color.fromCssColorString(color).withAlpha(0.4),
|
||||||
outlineWidth: 2,
|
outlineWidth: 2,
|
||||||
heightReference: Cesium.HeightReference.NONE,
|
|
||||||
},
|
},
|
||||||
label: {
|
label: {
|
||||||
text: 'M' + mag.toFixed(1),
|
text: 'M' + mag.toFixed(1),
|
||||||
@@ -125,11 +172,12 @@ const DisastersLayer = {
|
|||||||
scale: 0.7,
|
scale: 0.7,
|
||||||
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 2000000),
|
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(0, 2000000),
|
||||||
},
|
},
|
||||||
description: '<div style="font-family:monospace;font-size:13px;padding:8px">' +
|
description: '<div style="font-family:monospace;font-size:12px;padding:10px;max-width:400px;line-height:1.6">' +
|
||||||
'<strong style="color:' + color + '">ERDBEBEN M' + mag.toFixed(1) + '</strong><br>' +
|
'<strong style="color:' + color + ';font-size:14px">ERDBEBEN M' + mag.toFixed(1) + '</strong><br>' +
|
||||||
'<span style="color:#e0e0e0">' + (p.place || '?') + '</span><br>' +
|
'<span style="color:#e0e0e0">' + (p.place || '?') + '</span><br>' +
|
||||||
'<span style="color:#888">Tiefe: ' + (c[2] || '?') + ' km | ' +
|
'<span style="color:#888;font-size:10px">Tiefe: ' + (c[2] || '?') + ' km | ' +
|
||||||
new Date(p.time).toLocaleString('de-DE') + '</span></div>',
|
new Date(p.time).toLocaleString('de-DE') + '</span>' +
|
||||||
|
monitorHtml + '</div>',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
In neuem Issue referenzieren
Einen Benutzer sperren