tsunami / src /tsuwave /dashboard /alert_panel.py
Gitdeeper4's picture
رفع جميع ملفات TSU-WAVE مع YAML
12834b7
"""Alert panel component"""
import streamlit as st
import pandas as pd
from datetime import datetime, timedelta
from typing import List, Dict, Optional
def display_alerts(alerts: List[Dict]):
"""Display alerts panel"""
if not alerts:
st.info("No active alerts")
return
for alert in alerts:
level = alert.get('level', 'UNKNOWN')
if level == 'CRITICAL' or level == 'SEVERE':
with st.container():
st.markdown(f"""
<div style="background-color: #ff4b4b; padding: 1rem; border-radius: 0.5rem; margin-bottom: 1rem;">
<h3 style="color: white; margin: 0;">🚨 {level} TSUNAMI THREAT</h3>
<p style="color: white;"><strong>Zone:</strong> {alert.get('zone', 'Unknown')}</p>
<p style="color: white;"><strong>CHI:</strong> {alert.get('chi', 0):.2f}</p>
<p style="color: white;"><strong>Time:</strong> {alert.get('time', datetime.now())}</p>
<p style="color: white;"><strong>Message:</strong> {alert.get('message', '')}</p>
</div>
""", unsafe_allow_html=True)
elif level == 'HIGH':
with st.container():
st.markdown(f"""
<div style="background-color: #ffa500; padding: 1rem; border-radius: 0.5rem; margin-bottom: 1rem;">
<h3 style="color: white; margin: 0;">⚠️ HIGH - Tsunami Warning</h3>
<p style="color: white;"><strong>Zone:</strong> {alert.get('zone', 'Unknown')}</p>
<p style="color: white;"><strong>CHI:</strong> {alert.get('chi', 0):.2f}</p>
<p style="color: white;"><strong>Time:</strong> {alert.get('time', datetime.now())}</p>
<p style="color: white;"><strong>Message:</strong> {alert.get('message', '')}</p>
</div>
""", unsafe_allow_html=True)
elif level == 'MODERATE':
with st.container():
st.markdown(f"""
<div style="background-color: #ffff00; padding: 1rem; border-radius: 0.5rem; margin-bottom: 1rem;">
<h3 style="color: black; margin: 0;">ℹ️ MODERATE - Tsunami Advisory</h3>
<p style="color: black;"><strong>Zone:</strong> {alert.get('zone', 'Unknown')}</p>
<p style="color: black;"><strong>CHI:</strong> {alert.get('chi', 0):.2f}</p>
<p style="color: black;"><strong>Time:</strong> {alert.get('time', datetime.now())}</p>
<p style="color: black;"><strong>Message:</strong> {alert.get('message', '')}</p>
</div>
""", unsafe_allow_html=True)
else:
with st.container():
st.info(f"{level}: {alert.get('message', '')}")
def create_sample_alerts() -> List[Dict]:
"""Create sample alerts for testing"""
now = datetime.now()
return [
{
"level": "SEVERE",
"zone": "Miyako, Japan",
"chi": 0.91,
"time": now.strftime("%Y-%m-%d %H:%M UTC"),
"message": "EVACUATE IMMEDIATELY - Tsunami approaching",
"acknowledged": False
},
{
"level": "HIGH",
"zone": "Hilo Bay, Hawaii",
"chi": 0.72,
"time": (now - timedelta(minutes=5)).strftime("%Y-%m-%d %H:%M UTC"),
"message": "Tsunami warning - prepare evacuation",
"acknowledged": False
},
{
"level": "MODERATE",
"zone": "Crescent City, CA",
"chi": 0.48,
"time": (now - timedelta(minutes=15)).strftime("%Y-%m-%d %H:%M UTC"),
"message": "Tsunami advisory - monitor conditions",
"acknowledged": True
}
]
def alert_statistics(alerts: List[Dict]) -> Dict:
"""Calculate alert statistics"""
total = len(alerts)
by_level = {}
acknowledged = 0
for alert in alerts:
level = alert.get('level', 'UNKNOWN')
by_level[level] = by_level.get(level, 0) + 1
if alert.get('acknowledged', False):
acknowledged += 1
return {
"total": total,
"by_level": by_level,
"acknowledged": acknowledged,
"unacknowledged": total - acknowledged
}
def display_alert_controls():
"""Display alert control panel"""
col1, col2, col3 = st.columns(3)
with col1:
if st.button("Acknowledge All", use_container_width=True):
st.success("All alerts acknowledged")
with col2:
if st.button("Request Update", use_container_width=True):
st.info("Update requested")
with col3:
if st.button("Contact Emergency", use_container_width=True):
st.warning("Emergency services notified")
def display_alert_history(alerts: List[Dict]):
"""Display alert history table"""
if not alerts:
st.info("No alert history")
return
df = pd.DataFrame(alerts)
st.dataframe(df, use_container_width=True)
def get_alert_color(level: str) -> str:
"""Get color for alert level"""
colors = {
'LOW': 'green',
'MODERATE': 'yellow',
'HIGH': 'orange',
'SEVERE': 'red',
'CRITICAL': 'darkred',
'CATASTROPHIC': 'darkred'
}
return colors.get(level, 'gray')
def get_alert_icon(level: str) -> str:
"""Get icon for alert level"""
icons = {
'LOW': 'ℹ️',
'MODERATE': '⚠️',
'HIGH': '⚠️',
'SEVERE': '🚨',
'CRITICAL': '🚨',
'CATASTROPHIC': '💀'
}
return icons.get(level, '📢')