Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +258 -0
- templates/index.html +654 -0
app.py
ADDED
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, request
|
2 |
+
import pandas as pd
|
3 |
+
import folium
|
4 |
+
from folium.plugins import HeatMap, MarkerCluster, Fullscreen, MiniMap
|
5 |
+
from folium.raster_layers import TileLayer
|
6 |
+
from datetime import datetime, timedelta, timezone
|
7 |
+
import re
|
8 |
+
import google.generativeai as genai
|
9 |
+
import os
|
10 |
+
import requests # <--- CORRECTED: Added requests import
|
11 |
+
import toml # For potentially reading secrets.toml
|
12 |
+
from datetime import datetime, timezone # Make sure timezone is imported
|
13 |
+
|
14 |
+
# --- Configuration ---
|
15 |
+
DEFAULT_MIN_LAT_INDIA = 6.0
|
16 |
+
DEFAULT_MAX_LAT_INDIA = 38.0
|
17 |
+
DEFAULT_MIN_LON_INDIA = 68.0
|
18 |
+
DEFAULT_MAX_LON_INDIA = 98.0
|
19 |
+
DEFAULT_REGION_NAME_INDIA = "India & Surrounding"
|
20 |
+
TSUNAMI_MAG_THRESHOLD = 6.8
|
21 |
+
TSUNAMI_DEPTH_THRESHOLD = 70
|
22 |
+
OFFSHORE_KEYWORDS = ["sea", "ocean", "off the coast", "ridge", "trench", "gulf", "bay", "islands region", "strait"]
|
23 |
+
TECTONIC_PLATES_URL = "https://raw.githubusercontent.com/fraxen/tectonicplates/master/GeoJSON/PB2002_boundaries.json"
|
24 |
+
USGS_API_URL = "https://earthquake.usgs.gov/fdsnws/event/1/query"
|
25 |
+
|
26 |
+
# --- Load API Key ---
|
27 |
+
GEMINI_API_KEY = os.getenv("GEMINI_API_KEY")
|
28 |
+
if not GEMINI_API_KEY:
|
29 |
+
try:
|
30 |
+
secrets_path = os.path.join(os.path.dirname(__file__), '.streamlit', 'secrets.toml')
|
31 |
+
if os.path.exists(secrets_path):
|
32 |
+
secrets = toml.load(secrets_path)
|
33 |
+
GEMINI_API_KEY = secrets.get("GEMINI_API_KEY")
|
34 |
+
except Exception as e:
|
35 |
+
print(f"Could not load secrets.toml: {e}")
|
36 |
+
GEMINI_API_KEY = None
|
37 |
+
|
38 |
+
if not GEMINI_API_KEY:
|
39 |
+
print("WARNING: GEMINI_API_KEY not found. AI features will be disabled.")
|
40 |
+
|
41 |
+
# --- API Functions ---
|
42 |
+
def fetch_earthquake_data(starttime, endtime, min_mag, min_lat, max_lat, min_lon, max_lon, source="USGS"):
|
43 |
+
print(f"Fetching data from {source} from {starttime.strftime('%Y-%m-%d %H:%M')} to {endtime.strftime('%Y-%m-%d %H:%M')} for Mag >= {min_mag}...")
|
44 |
+
params = {
|
45 |
+
'format': 'geojson',
|
46 |
+
'starttime': starttime.strftime('%Y-%m-%dT%H:%M:%S'),
|
47 |
+
'endtime': endtime.strftime('%Y-%m-%dT%H:%M:%S'),
|
48 |
+
'minlatitude': min_lat,
|
49 |
+
'maxlatitude': max_lat,
|
50 |
+
'minlongitude': min_lon,
|
51 |
+
'maxlongitude': max_lon,
|
52 |
+
'minmagnitude': min_mag,
|
53 |
+
'orderby': 'time'
|
54 |
+
}
|
55 |
+
try:
|
56 |
+
response = requests.get(USGS_API_URL, params=params, timeout=30)
|
57 |
+
response.raise_for_status()
|
58 |
+
data = response.json()
|
59 |
+
features = data.get('features', [])
|
60 |
+
earthquakes = []
|
61 |
+
for feature in features:
|
62 |
+
properties = feature.get('properties', {})
|
63 |
+
geometry = feature.get('geometry', {})
|
64 |
+
coordinates = geometry.get('coordinates', [None, None, None])
|
65 |
+
earthquakes.append({
|
66 |
+
'id': feature.get('id'),
|
67 |
+
'magnitude': properties.get('mag'),
|
68 |
+
'place': properties.get('place'),
|
69 |
+
'time': pd.to_datetime(properties.get('time'), unit='ms', utc=True),
|
70 |
+
'url': properties.get('url'),
|
71 |
+
'longitude': coordinates[0],
|
72 |
+
'latitude': coordinates[1],
|
73 |
+
'depth': coordinates[2]
|
74 |
+
})
|
75 |
+
df = pd.DataFrame(earthquakes)
|
76 |
+
if not df.empty:
|
77 |
+
df = df.sort_values(by='time', ascending=False)
|
78 |
+
print(f"Fetched {len(df)} earthquakes from {source}.")
|
79 |
+
return df
|
80 |
+
except requests.exceptions.RequestException as e:
|
81 |
+
print(f"Error fetching data from {source}: {e}")
|
82 |
+
return pd.DataFrame()
|
83 |
+
except Exception as e:
|
84 |
+
print(f"An unexpected error occurred during data fetching: {e}")
|
85 |
+
return pd.DataFrame()
|
86 |
+
|
87 |
+
def fetch_tectonic_plates_data(url):
|
88 |
+
print("Fetching tectonic plate boundaries data...")
|
89 |
+
try:
|
90 |
+
response = requests.get(url, timeout=30)
|
91 |
+
response.raise_for_status()
|
92 |
+
print("Tectonic plate data fetched.")
|
93 |
+
return response.json()
|
94 |
+
except requests.exceptions.RequestException as e:
|
95 |
+
print(f"Error fetching tectonic plate data: {e}")
|
96 |
+
return None
|
97 |
+
|
98 |
+
# --- Helper Functions ---
|
99 |
+
def is_offshore(place_description, depth_km):
|
100 |
+
if place_description is None or depth_km is None: return False
|
101 |
+
place_lower = str(place_description).lower()
|
102 |
+
for keyword in OFFSHORE_KEYWORDS:
|
103 |
+
if keyword in place_lower: return True
|
104 |
+
return False
|
105 |
+
|
106 |
+
def get_marker_color_by_magnitude(magnitude):
|
107 |
+
if magnitude is None: return 'gray'
|
108 |
+
if magnitude < 4.0: return 'green'
|
109 |
+
elif magnitude < 5.0: return 'blue'
|
110 |
+
elif magnitude < 6.0: return 'orange'
|
111 |
+
elif magnitude < 7.0: return 'red'
|
112 |
+
else: return 'darkred'
|
113 |
+
|
114 |
+
# --- Gemini LLM Function ---
|
115 |
+
def get_gemini_interpretation(api_key, data_summary_prompt):
|
116 |
+
if not api_key:
|
117 |
+
return "API Key not configured for Gemini."
|
118 |
+
try:
|
119 |
+
genai.configure(api_key=api_key)
|
120 |
+
model = genai.GenerativeModel('gemini-1.5-flash-latest')
|
121 |
+
response = model.generate_content(data_summary_prompt)
|
122 |
+
return response.text
|
123 |
+
except Exception as e:
|
124 |
+
print(f"Error communicating with Gemini API: {e}")
|
125 |
+
return "Could not retrieve interpretation from AI model."
|
126 |
+
|
127 |
+
app = Flask(__name__)
|
128 |
+
|
129 |
+
predefined_regions_dict = {
|
130 |
+
"India & Surrounding": (DEFAULT_MIN_LAT_INDIA, DEFAULT_MAX_LAT_INDIA, DEFAULT_MIN_LON_INDIA, DEFAULT_MAX_LON_INDIA),
|
131 |
+
"Indian Ocean Region (Tsunami Focus)": (-20, 35, 40, 120),
|
132 |
+
"Northern India (Himalayan Belt)": (25, 38, 70, 98),
|
133 |
+
"Andaman & Nicobar Region": (5, 15, 90, 95),
|
134 |
+
"Global (Significant Quakes)": (-60, 60, -180, 180)
|
135 |
+
}
|
136 |
+
|
137 |
+
def get_default_configs_for_region(region_name):
|
138 |
+
if region_name == "Global (Significant Quakes)":
|
139 |
+
return {"days_historical": 730, "min_magnitude_historical": 4.5, "days_recent": 7, "min_magnitude_recent": 4.0, "alert_threshold_magnitude": 5.0, "show_tectonic_plates": True, "enable_ai_interpretation": bool(GEMINI_API_KEY)}
|
140 |
+
elif region_name == "Indian Ocean Region (Tsunami Focus)":
|
141 |
+
return {"days_historical": 730, "min_magnitude_historical": 4.0, "days_recent": 7, "min_magnitude_recent": 3.5, "alert_threshold_magnitude": 4.5, "show_tectonic_plates": True, "enable_ai_interpretation": bool(GEMINI_API_KEY)}
|
142 |
+
else:
|
143 |
+
return {"days_historical": 730, "min_magnitude_historical": 3.0, "days_recent": 7, "min_magnitude_recent": 2.5, "alert_threshold_magnitude": 3.5, "show_tectonic_plates": True, "enable_ai_interpretation": bool(GEMINI_API_KEY)}
|
144 |
+
|
145 |
+
@app.route('/', methods=['GET', 'POST'])
|
146 |
+
def index():
|
147 |
+
map_html = None
|
148 |
+
historical_df = pd.DataFrame()
|
149 |
+
recent_df = pd.DataFrame()
|
150 |
+
significant_quakes = []
|
151 |
+
tsunami_potential_events = []
|
152 |
+
ai_interpretation = None
|
153 |
+
initial_load = True
|
154 |
+
|
155 |
+
current_config = {}
|
156 |
+
if request.method == 'POST':
|
157 |
+
initial_load = False
|
158 |
+
current_config['selected_region_name'] = request.form.get('selected_region_name', DEFAULT_REGION_NAME_INDIA)
|
159 |
+
# Load defaults for selected region first, then override with form values
|
160 |
+
defaults = get_default_configs_for_region(current_config['selected_region_name'])
|
161 |
+
current_config.update(defaults)
|
162 |
+
|
163 |
+
current_config['days_historical'] = int(request.form.get('days_historical', defaults['days_historical']))
|
164 |
+
current_config['min_magnitude_historical'] = float(request.form.get('min_magnitude_historical', defaults['min_magnitude_historical']))
|
165 |
+
current_config['days_recent'] = int(request.form.get('days_recent', defaults['days_recent']))
|
166 |
+
current_config['min_magnitude_recent'] = float(request.form.get('min_magnitude_recent', defaults['min_magnitude_recent']))
|
167 |
+
current_config['alert_threshold_magnitude'] = float(request.form.get('alert_threshold_magnitude', defaults['alert_threshold_magnitude']))
|
168 |
+
current_config['show_tectonic_plates'] = request.form.get('show_tectonic_plates') == 'True'
|
169 |
+
current_config['enable_ai_interpretation'] = request.form.get('enable_ai_interpretation') == 'True'
|
170 |
+
else: # GET
|
171 |
+
initial_load = True
|
172 |
+
current_config['selected_region_name'] = DEFAULT_REGION_NAME_INDIA
|
173 |
+
defaults = get_default_configs_for_region(DEFAULT_REGION_NAME_INDIA)
|
174 |
+
current_config.update(defaults)
|
175 |
+
|
176 |
+
if request.method == 'POST': # Process data only on POST
|
177 |
+
min_lat, max_lat, min_lon, max_lon = predefined_regions_dict[current_config['selected_region_name']]
|
178 |
+
end_time_global = datetime.now(timezone.utc)
|
179 |
+
start_time_historical = end_time_global - timedelta(days=current_config['days_historical'])
|
180 |
+
start_time_recent = end_time_global - timedelta(days=current_config['days_recent'])
|
181 |
+
|
182 |
+
historical_df = fetch_earthquake_data(start_time_historical, end_time_global, current_config['min_magnitude_historical'], min_lat, max_lat, min_lon, max_lon)
|
183 |
+
recent_df = fetch_earthquake_data(start_time_recent, end_time_global, current_config['min_magnitude_recent'], min_lat, max_lat, min_lon, max_lon)
|
184 |
+
|
185 |
+
map_center_lat = (min_lat + max_lat) / 2; map_center_lon = (min_lon + max_lon) / 2
|
186 |
+
if current_config['selected_region_name'] == "Global (Significant Quakes)": initial_zoom = 2
|
187 |
+
elif abs(max_lat - min_lat) > 30 or abs(max_lon - min_lon) > 30: initial_zoom = 3
|
188 |
+
else: initial_zoom = 4 if abs(max_lat - min_lat) > 15 or abs(max_lon - min_lon) > 15 else 5
|
189 |
+
|
190 |
+
m = folium.Map(location=[map_center_lat, map_center_lon], zoom_start=initial_zoom, tiles=None)
|
191 |
+
TileLayer(tiles='https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', attr='OpenTopoMap', name='OpenTopoMap (Terrain)', show=True).add_to(m)
|
192 |
+
TileLayer("OpenStreetMap", name="OpenStreetMap", show=False).add_to(m)
|
193 |
+
|
194 |
+
if current_config['show_tectonic_plates']:
|
195 |
+
plate_data = fetch_tectonic_plates_data(TECTONIC_PLATES_URL)
|
196 |
+
if plate_data:
|
197 |
+
folium.GeoJson(plate_data, name="Tectonic Plates", style_function=lambda x: {'color': '#E04A00', 'weight': 3, 'opacity': 0.9}, tooltip=folium.GeoJsonTooltip(fields=['Name'], aliases=['Plate Name:'], localize=True)).add_to(m)
|
198 |
+
|
199 |
+
if not historical_df.empty:
|
200 |
+
heat_data_list = [[row_h['latitude'], row_h['longitude'], row_h['magnitude']] if pd.notnull(row_h['magnitude']) else [row_h['latitude'], row_h['longitude']] for _, row_h in historical_df.iterrows() if pd.notnull(row_h['latitude']) and pd.notnull(row_h['longitude'])]
|
201 |
+
if heat_data_list: HeatMap(heat_data_list, name="Historical Heatmap").add_to(m)
|
202 |
+
|
203 |
+
if not recent_df.empty:
|
204 |
+
mc = MarkerCluster(name="Recent Earthquakes").add_to(m)
|
205 |
+
for _, row_r in recent_df.iterrows():
|
206 |
+
if pd.notnull(row_r['latitude']) and pd.notnull(row_r['longitude']) and pd.notnull(row_r['magnitude']):
|
207 |
+
mag = f"{row_r['magnitude']:.1f}"; depth = f"{row_r['depth']:.1f} km" if pd.notnull(row_r['depth']) else "N/A"; color = get_marker_color_by_magnitude(row_r['magnitude'])
|
208 |
+
popup = f"<b>RECENT</b><br>M{mag} at {row_r['place']}<br>{row_r['time'].strftime('%Y-%m-%d %H:%M')}<br>Depth: {depth}<br><a href='{row_r['url']}' target='_blank'>USGS</a>"
|
209 |
+
folium.CircleMarker(location=[row_r['latitude'], row_r['longitude']], radius=max(3, (row_r['magnitude'] * 1.8)), popup=folium.Popup(popup, max_width=300), color=color, fill=True, fill_color=color, fill_opacity=0.7, tooltip=f"M{mag}").add_to(mc)
|
210 |
+
folium.LayerControl().add_to(m)
|
211 |
+
Fullscreen().add_to(m)
|
212 |
+
map_html = m._repr_html_()
|
213 |
+
|
214 |
+
if not recent_df.empty:
|
215 |
+
recent_alerts = recent_df.copy()
|
216 |
+
recent_alerts['magnitude'] = pd.to_numeric(recent_alerts['magnitude'], errors='coerce').dropna()
|
217 |
+
temp_sig_q = recent_alerts[recent_alerts['magnitude'] >= current_config['alert_threshold_magnitude']]
|
218 |
+
for _, sq_row in temp_sig_q.iterrows():
|
219 |
+
q_info = sq_row.to_dict(); q_info['tsunami_risk_info'] = ""
|
220 |
+
if pd.notnull(sq_row.get('magnitude')) and pd.notnull(sq_row.get('depth')) and pd.notnull(sq_row.get('place')):
|
221 |
+
if sq_row['magnitude'] >= TSUNAMI_MAG_THRESHOLD and sq_row['depth'] <= TSUNAMI_DEPTH_THRESHOLD and is_offshore(sq_row['place'], sq_row['depth']):
|
222 |
+
q_info['tsunami_risk_info'] = "🌊 POTENTIAL TSUNAMI RISK"; tsunami_potential_events.append(q_info)
|
223 |
+
significant_quakes.append(q_info)
|
224 |
+
|
225 |
+
if current_config['enable_ai_interpretation'] and GEMINI_API_KEY:
|
226 |
+
summary_ai = f"Region: {current_config['selected_region_name']}\nHist: {current_config['days_historical']}d, M>={current_config['min_magnitude_historical']}, Tot:{len(historical_df)}\n"
|
227 |
+
if not historical_df.empty and 'magnitude' in historical_df and not historical_df['magnitude'].dropna().empty: summary_ai += f"Lgst hist.M: {historical_df['magnitude'].dropna().max():.1f}\n"
|
228 |
+
summary_ai += f"Recent: {current_config['days_recent']}d, M>={current_config['min_magnitude_recent']}, Tot:{len(recent_df)}\n"
|
229 |
+
if not recent_df.empty and 'magnitude' in recent_df and not recent_df['magnitude'].dropna().empty: summary_ai += f"Lgst rec.M: {recent_df['magnitude'].dropna().max():.1f}, Avg rec.M: {recent_df['magnitude'].dropna().mean():.1f}\n"
|
230 |
+
summary_ai += f"Alerts (M>={current_config['alert_threshold_magnitude']}): {len(significant_quakes)}\n"
|
231 |
+
if significant_quakes:
|
232 |
+
summary_ai += "Top sig. quakes:\n"
|
233 |
+
for r_s in significant_quakes[:2]: summary_ai += f" - M {r_s.get('magnitude',0.0):.1f} at {r_s.get('place','N/A')} on {r_s.get('time').strftime('%Y-%m-%d')}\n"
|
234 |
+
summary_ai += f"Tsunami risk events: {len(tsunami_potential_events)}\n"
|
235 |
+
full_prompt_ai = f"""You are a seismic data analyst. Based on this summary for '{current_config['selected_region_name']}', give a concise interpretation (max 3-4 paragraphs):
|
236 |
+
1. Overall seismic activity (recent vs. hist.).
|
237 |
+
2. Notable patterns/clusters in recent data.
|
238 |
+
3. Areas more active recently.
|
239 |
+
4. General outlook (NO PREDICTIONS).
|
240 |
+
IMPORTANT: Start with a disclaimer.
|
241 |
+
Data: {summary_ai}Interpretation:"""
|
242 |
+
ai_interpretation = get_gemini_interpretation(GEMINI_API_KEY, full_prompt_ai)
|
243 |
+
current_time_for_render = datetime.now(timezone.utc)
|
244 |
+
|
245 |
+
return render_template('index.html',
|
246 |
+
map_html=map_html,
|
247 |
+
historical_df=historical_df, # For potential future use in template
|
248 |
+
recent_df=recent_df, # For Top 5 table
|
249 |
+
significant_quakes=significant_quakes,
|
250 |
+
tsunami_potential_events=tsunami_potential_events,
|
251 |
+
ai_interpretation=ai_interpretation,
|
252 |
+
predefined_regions_list=predefined_regions_dict.keys(),
|
253 |
+
now= current_time_for_render,
|
254 |
+
current_config=current_config,
|
255 |
+
initial_load=initial_load)
|
256 |
+
|
257 |
+
if __name__ == '__main__':
|
258 |
+
app.run(debug=True)
|
templates/index.html
ADDED
@@ -0,0 +1,654 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html lang="en">
|
3 |
+
<head>
|
4 |
+
<meta charset="UTF-8">
|
5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
6 |
+
<title>Seismic Monitor Pro - India</title>
|
7 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
|
8 |
+
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
|
9 |
+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css">
|
10 |
+
<style>
|
11 |
+
:root {
|
12 |
+
--primary-color: #2b6cb0;
|
13 |
+
--secondary-color: #3182ce;
|
14 |
+
--warning-color: #dd6b20;
|
15 |
+
--danger-color: #e53e3e;
|
16 |
+
--light-bg: #f7fafc;
|
17 |
+
--dark-bg: #1a202c;
|
18 |
+
--card-shadow: 0 4px 6px rgba(0, 0, 0, 0.1), 0 1px 3px rgba(0, 0, 0, 0.08);
|
19 |
+
}
|
20 |
+
|
21 |
+
body {
|
22 |
+
font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
|
23 |
+
background-color: var(--light-bg);
|
24 |
+
color: #2d3748;
|
25 |
+
padding-top: 0;
|
26 |
+
}
|
27 |
+
|
28 |
+
.navbar-custom {
|
29 |
+
background-color: var(--primary-color);
|
30 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
|
31 |
+
}
|
32 |
+
|
33 |
+
.logo-text {
|
34 |
+
font-weight: 700;
|
35 |
+
letter-spacing: -0.5px;
|
36 |
+
font-size: 1.5rem;
|
37 |
+
color: white;
|
38 |
+
}
|
39 |
+
|
40 |
+
.container-fluid {
|
41 |
+
padding: 0;
|
42 |
+
}
|
43 |
+
|
44 |
+
.main-container {
|
45 |
+
padding: 0 20px 20px 20px;
|
46 |
+
}
|
47 |
+
|
48 |
+
.card {
|
49 |
+
border: none;
|
50 |
+
border-radius: 8px;
|
51 |
+
box-shadow: var(--card-shadow);
|
52 |
+
margin-bottom: 20px;
|
53 |
+
transition: transform 0.2s, box-shadow 0.2s;
|
54 |
+
}
|
55 |
+
|
56 |
+
.card:hover {
|
57 |
+
transform: translateY(-2px);
|
58 |
+
box-shadow: 0 10px 15px rgba(0, 0, 0, 0.1);
|
59 |
+
}
|
60 |
+
|
61 |
+
.card-header {
|
62 |
+
background-color: white;
|
63 |
+
border-bottom: 1px solid rgba(0,0,0,0.05);
|
64 |
+
font-weight: 600;
|
65 |
+
padding: 15px 20px;
|
66 |
+
font-size: 1.1rem;
|
67 |
+
border-radius: 8px 8px 0 0 !important;
|
68 |
+
}
|
69 |
+
|
70 |
+
.card-header i {
|
71 |
+
margin-right: 8px;
|
72 |
+
color: var(--primary-color);
|
73 |
+
}
|
74 |
+
|
75 |
+
.card-body {
|
76 |
+
padding: 20px;
|
77 |
+
}
|
78 |
+
|
79 |
+
.map-container {
|
80 |
+
width: 100%;
|
81 |
+
height: 550px;
|
82 |
+
border-radius: 8px;
|
83 |
+
overflow: hidden;
|
84 |
+
}
|
85 |
+
|
86 |
+
.config-form {
|
87 |
+
max-height: 550px;
|
88 |
+
overflow-y: auto;
|
89 |
+
}
|
90 |
+
|
91 |
+
.kpi-card {
|
92 |
+
border-radius: 8px;
|
93 |
+
padding: 15px;
|
94 |
+
height: 100%;
|
95 |
+
text-align: center;
|
96 |
+
position: relative;
|
97 |
+
}
|
98 |
+
|
99 |
+
.kpi-card .kpi-icon {
|
100 |
+
position: absolute;
|
101 |
+
right: 15px;
|
102 |
+
top: 15px;
|
103 |
+
opacity: 0.2;
|
104 |
+
font-size: 2rem;
|
105 |
+
}
|
106 |
+
|
107 |
+
.kpi-value {
|
108 |
+
font-size: 2rem;
|
109 |
+
font-weight: 700;
|
110 |
+
margin-bottom: 5px;
|
111 |
+
line-height: 1;
|
112 |
+
}
|
113 |
+
|
114 |
+
.kpi-label {
|
115 |
+
font-size: 0.9rem;
|
116 |
+
text-transform: uppercase;
|
117 |
+
letter-spacing: 0.5px;
|
118 |
+
opacity: 0.8;
|
119 |
+
}
|
120 |
+
|
121 |
+
.kpi-small {
|
122 |
+
font-size: 0.75rem;
|
123 |
+
opacity: 0.7;
|
124 |
+
}
|
125 |
+
|
126 |
+
.btn-primary {
|
127 |
+
background-color: var(--primary-color);
|
128 |
+
border-color: var(--primary-color);
|
129 |
+
box-shadow: 0 1px 3px rgba(0,0,0,0.12);
|
130 |
+
}
|
131 |
+
|
132 |
+
.btn-primary:hover {
|
133 |
+
background-color: var(--secondary-color);
|
134 |
+
border-color: var(--secondary-color);
|
135 |
+
}
|
136 |
+
|
137 |
+
.form-control, .form-select {
|
138 |
+
border-radius: 6px;
|
139 |
+
padding: 10px 12px;
|
140 |
+
border: 1px solid #e2e8f0;
|
141 |
+
}
|
142 |
+
|
143 |
+
.form-label {
|
144 |
+
font-weight: 500;
|
145 |
+
font-size: 0.9rem;
|
146 |
+
margin-bottom: 5px;
|
147 |
+
}
|
148 |
+
|
149 |
+
.alert-custom {
|
150 |
+
border-radius: 6px;
|
151 |
+
padding: 15px;
|
152 |
+
margin-bottom: 15px;
|
153 |
+
position: relative;
|
154 |
+
}
|
155 |
+
|
156 |
+
.alert-warning-custom {
|
157 |
+
background-color: #fffaf0;
|
158 |
+
border-left: 4px solid var(--warning-color);
|
159 |
+
color: #7b341e;
|
160 |
+
}
|
161 |
+
|
162 |
+
.alert-info-custom {
|
163 |
+
background-color: #ebf8ff;
|
164 |
+
border-left: 4px solid var(--primary-color);
|
165 |
+
color: #2c5282;
|
166 |
+
}
|
167 |
+
|
168 |
+
.alert-danger-custom {
|
169 |
+
background-color: #fff5f5;
|
170 |
+
border-left: 4px solid var(--danger-color);
|
171 |
+
color: #c53030;
|
172 |
+
}
|
173 |
+
|
174 |
+
.recent-quake {
|
175 |
+
border-radius: 6px;
|
176 |
+
border-left: 4px solid var(--primary-color);
|
177 |
+
background-color: white;
|
178 |
+
padding: 12px;
|
179 |
+
margin-bottom: 12px;
|
180 |
+
box-shadow: 0 1px 3px rgba(0,0,0,0.12);
|
181 |
+
}
|
182 |
+
|
183 |
+
.tsunami-risk {
|
184 |
+
border-left-color: var(--danger-color);
|
185 |
+
}
|
186 |
+
|
187 |
+
.tsunami-badge {
|
188 |
+
background-color: var(--danger-color);
|
189 |
+
color: white;
|
190 |
+
padding: 3px 8px;
|
191 |
+
border-radius: 12px;
|
192 |
+
font-size: 0.7rem;
|
193 |
+
text-transform: uppercase;
|
194 |
+
letter-spacing: 0.5px;
|
195 |
+
font-weight: 700;
|
196 |
+
}
|
197 |
+
|
198 |
+
.magnitude-badge {
|
199 |
+
display: inline-block;
|
200 |
+
width: 40px;
|
201 |
+
height: 40px;
|
202 |
+
line-height: 40px;
|
203 |
+
border-radius: 50%;
|
204 |
+
background-color: #3182ce;
|
205 |
+
color: white;
|
206 |
+
font-weight: 700;
|
207 |
+
text-align: center;
|
208 |
+
margin-right: 10px;
|
209 |
+
font-size: 1rem;
|
210 |
+
}
|
211 |
+
|
212 |
+
.magnitude-high {
|
213 |
+
background-color: var(--danger-color);
|
214 |
+
}
|
215 |
+
|
216 |
+
.magnitude-med {
|
217 |
+
background-color: var(--warning-color);
|
218 |
+
}
|
219 |
+
|
220 |
+
.ai-interpretation {
|
221 |
+
background-color: #f0f4f8;
|
222 |
+
border-radius: 8px;
|
223 |
+
padding: 20px;
|
224 |
+
position: relative;
|
225 |
+
}
|
226 |
+
|
227 |
+
.ai-interpretation:before {
|
228 |
+
content: '\201C'; /* Corrected: Unicode for left double quotation mark */
|
229 |
+
position: absolute;
|
230 |
+
top: 5px;
|
231 |
+
left: 10px;
|
232 |
+
font-size: 3rem;
|
233 |
+
color: rgba(0,0,0,0.1);
|
234 |
+
line-height: 1;
|
235 |
+
}
|
236 |
+
|
237 |
+
.table-recent {
|
238 |
+
border-collapse: separate;
|
239 |
+
border-spacing: 0;
|
240 |
+
width: 100%;
|
241 |
+
border-radius: 8px;
|
242 |
+
overflow: hidden;
|
243 |
+
}
|
244 |
+
|
245 |
+
.table-recent th {
|
246 |
+
background-color: #f7fafc;
|
247 |
+
font-weight: 600;
|
248 |
+
text-transform: uppercase;
|
249 |
+
font-size: 0.75rem;
|
250 |
+
letter-spacing: 0.5px;
|
251 |
+
color: #4a5568;
|
252 |
+
}
|
253 |
+
|
254 |
+
.table-recent td, .table-recent th {
|
255 |
+
padding: 12px;
|
256 |
+
border-bottom: 1px solid #edf2f7;
|
257 |
+
}
|
258 |
+
|
259 |
+
.table-recent tr:last-child td {
|
260 |
+
border-bottom: none;
|
261 |
+
}
|
262 |
+
|
263 |
+
@media (max-width: 768px) {
|
264 |
+
.map-container {
|
265 |
+
height: 400px;
|
266 |
+
}
|
267 |
+
|
268 |
+
.kpi-value {
|
269 |
+
font-size: 1.5rem;
|
270 |
+
}
|
271 |
+
}
|
272 |
+
</style>
|
273 |
+
</head>
|
274 |
+
<body>
|
275 |
+
<!-- Navigation Bar -->
|
276 |
+
<nav class="navbar navbar-expand-lg navbar-dark navbar-custom mb-4">
|
277 |
+
<div class="container-fluid px-4">
|
278 |
+
<span class="logo-text"><i class="fas fa-map-marked-alt me-2"></i>Seismic Monitor Pro - India</span>
|
279 |
+
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
280 |
+
<span class="navbar-toggler-icon"></span>
|
281 |
+
</button>
|
282 |
+
<div class="collapse navbar-collapse" id="navbarNav">
|
283 |
+
<ul class="navbar-nav ms-auto">
|
284 |
+
<li class="nav-item">
|
285 |
+
<a class="nav-link" href="#" data-bs-toggle="modal" data-bs-target="#aboutModal">
|
286 |
+
<i class="fas fa-info-circle me-1"></i> About
|
287 |
+
</a>
|
288 |
+
</li>
|
289 |
+
<li class="nav-item">
|
290 |
+
<a class="nav-link" href="https://www.incois.gov.in/portal/TsunamiEarlyWarning.jsp" target="_blank">
|
291 |
+
<i class="fas fa-external-link-alt me-1"></i> INCOIS
|
292 |
+
</a>
|
293 |
+
</li>
|
294 |
+
<li class="nav-item">
|
295 |
+
<a class="nav-link" href="https://ndma.gov.in/" target="_blank">
|
296 |
+
<i class="fas fa-external-link-alt me-1"></i> NDMA
|
297 |
+
</a>
|
298 |
+
</li>
|
299 |
+
</ul>
|
300 |
+
</div>
|
301 |
+
</div>
|
302 |
+
</nav>
|
303 |
+
|
304 |
+
<div class="container-fluid main-container">
|
305 |
+
<!-- Disclaimer Alert -->
|
306 |
+
<div class="alert alert-warning-custom mb-4" role="alert">
|
307 |
+
<div class="d-flex align-items-center">
|
308 |
+
<i class="fas fa-exclamation-triangle fa-2x me-3 text-warning"></i>
|
309 |
+
<div>
|
310 |
+
<strong>Important Disclaimer:</strong> True earthquake prediction is NOT currently possible.
|
311 |
+
This dashboard provides historical data visualization and analysis only. Always refer to official sources for warnings and advisories.
|
312 |
+
</div>
|
313 |
+
</div>
|
314 |
+
</div>
|
315 |
+
|
316 |
+
<div class="row">
|
317 |
+
<!-- Configuration Sidebar -->
|
318 |
+
<div class="col-lg-3 col-md-12 mb-4">
|
319 |
+
<div class="card">
|
320 |
+
<div class="card-header">
|
321 |
+
<i class="fas fa-sliders-h"></i> Analysis Configuration
|
322 |
+
</div>
|
323 |
+
<div class="card-body config-form">
|
324 |
+
<form method="POST" id="analysisForm"> {# Added id="analysisForm" #}
|
325 |
+
<div class="mb-3">
|
326 |
+
<label for="selected_region_name" class="form-label">Region</label>
|
327 |
+
<select class="form-select" id="selected_region_name" name="selected_region_name">
|
328 |
+
{% for region in predefined_regions_list %}
|
329 |
+
<option value="{{ region }}" {% if region == current_config.selected_region_name %}selected{% endif %}>{{ region }}</option>
|
330 |
+
{% endfor %}
|
331 |
+
</select>
|
332 |
+
</div>
|
333 |
+
|
334 |
+
<div class="row mb-3">
|
335 |
+
<div class="col-6">
|
336 |
+
<label for="days_recent" class="form-label">Recent Days</label>
|
337 |
+
<input type="number" class="form-control" id="days_recent" name="days_recent" value="{{ request.form.get('days_recent', current_config.days_recent) }}" min="1" max="30">
|
338 |
+
</div>
|
339 |
+
<div class="col-6">
|
340 |
+
<label for="min_magnitude_recent" class="form-label">Min Magnitude</label>
|
341 |
+
<input type="number" step="0.1" class="form-control" id="min_magnitude_recent" name="min_magnitude_recent" value="{{ request.form.get('min_magnitude_recent', current_config.min_magnitude_recent) }}" min="1.0" max="7.0">
|
342 |
+
</div>
|
343 |
+
</div>
|
344 |
+
|
345 |
+
<div class="row mb-3">
|
346 |
+
<div class="col-6">
|
347 |
+
<label for="days_historical" class="form-label">Historical Days</label>
|
348 |
+
<input type="number" class="form-control" id="days_historical" name="days_historical" value="{{ request.form.get('days_historical', current_config.days_historical) }}" min="7" max="1825">
|
349 |
+
</div>
|
350 |
+
<div class="col-6">
|
351 |
+
<label for="min_magnitude_historical" class="form-label">Min Magnitude</label>
|
352 |
+
<input type="number" step="0.1" class="form-control" id="min_magnitude_historical" name="min_magnitude_historical" value="{{ request.form.get('min_magnitude_historical', current_config.min_magnitude_historical) }}" min="1.0" max="7.0">
|
353 |
+
</div>
|
354 |
+
</div>
|
355 |
+
|
356 |
+
<div class="mb-3">
|
357 |
+
<label for="alert_threshold_magnitude" class="form-label">Alert Threshold (M ≥)</label>
|
358 |
+
<input type="number" step="0.1" class="form-control" id="alert_threshold_magnitude" name="alert_threshold_magnitude" value="{{ request.form.get('alert_threshold_magnitude', current_config.alert_threshold_magnitude) }}" min="2.0" max="7.0">
|
359 |
+
</div>
|
360 |
+
|
361 |
+
<div class="form-check form-switch mb-3">
|
362 |
+
<input class="form-check-input" type="checkbox" id="show_tectonic_plates" name="show_tectonic_plates" value="True" {% if current_config.show_tectonic_plates %}checked{% endif %}>
|
363 |
+
<label class="form-check-label" for="show_tectonic_plates">Show Tectonic Plates</label>
|
364 |
+
</div>
|
365 |
+
|
366 |
+
<div class="form-check form-switch mb-4">
|
367 |
+
<input class="form-check-input" type="checkbox" id="enable_ai_interpretation" name="enable_ai_interpretation" value="True" {% if current_config.enable_ai_interpretation %}checked{% endif %}>
|
368 |
+
<label class="form-check-label" for="enable_ai_interpretation">Enable AI Interpretation</label>
|
369 |
+
</div>
|
370 |
+
|
371 |
+
<button type="submit" class="btn btn-primary w-100 py-2" id="runAnalysisBtn"> {# Added id="runAnalysisBtn" #}
|
372 |
+
<i class="fas fa-sync-alt me-2"></i> Run Analysis
|
373 |
+
</button>
|
374 |
+
</form>
|
375 |
+
</div>
|
376 |
+
</div>
|
377 |
+
|
378 |
+
<!-- Recent Activity Card - Adjusted Structure -->
|
379 |
+
<div class="card">
|
380 |
+
<div class="card-header">
|
381 |
+
<i class="fas fa-chart-line"></i> Recent Activity (Last {{ current_config.days_recent }} days)
|
382 |
+
</div>
|
383 |
+
<div class="card-body {% if recent_df is defined and not recent_df.empty %}p-0{% else %}py-3{% endif %}">
|
384 |
+
{% if recent_df is defined and not recent_df.empty %}
|
385 |
+
<table class="table table-recent mb-0">
|
386 |
+
<thead>
|
387 |
+
<tr>
|
388 |
+
<th>Time</th>
|
389 |
+
<th>Mag</th>
|
390 |
+
<th>Location</th>
|
391 |
+
</tr>
|
392 |
+
</thead>
|
393 |
+
<tbody>
|
394 |
+
{% for index, row in recent_df.head(5).iterrows() %}
|
395 |
+
<tr>
|
396 |
+
<td class="small">{{ row.time.strftime('%m/%d %H:%M') }}</td>
|
397 |
+
<td class="fw-bold {% if row.magnitude >= 5.0 %}text-danger{% elif row.magnitude >= 4.0 %}text-warning{% endif %}">{{ "%.1f"|format(row.magnitude) }}</td>
|
398 |
+
<td class="small text-truncate" style="max-width: 120px;">{{ row.place }}</td>
|
399 |
+
</tr>
|
400 |
+
{% endfor %}
|
401 |
+
</tbody>
|
402 |
+
</table>
|
403 |
+
{% elif not initial_load %}
|
404 |
+
<p class="text-center text-muted mb-0">
|
405 |
+
<small>No recent quakes (M ≥ {{ "%.1f"|format(current_config.min_magnitude_recent) }}) found in the selected region and period.</small>
|
406 |
+
</p>
|
407 |
+
{% else %}
|
408 |
+
<p class="text-center text-muted mb-0">
|
409 |
+
<small>Run analysis to see recent activity.</small>
|
410 |
+
</p>
|
411 |
+
{% endif %}
|
412 |
+
</div>
|
413 |
+
</div>
|
414 |
+
</div>
|
415 |
+
|
416 |
+
<!-- Main Content -->
|
417 |
+
<div class="col-lg-9 col-md-12">
|
418 |
+
{% if map_html %}
|
419 |
+
<!-- Map Card -->
|
420 |
+
<div class="card">
|
421 |
+
<div class="card-header d-flex justify-content-between align-items-center">
|
422 |
+
<div><i class="fas fa-map-marked-alt"></i> {{ current_config.selected_region_name }}</div>
|
423 |
+
{# Ensure 'now' is passed from Flask to the template #}
|
424 |
+
<div class="text-muted small">Updated: {{ now.strftime('%Y-%m-%d %H:%M %Z') if now else 'N/A' }}</div>
|
425 |
+
</div>
|
426 |
+
<div class="card-body p-0">
|
427 |
+
<div class="map-container">
|
428 |
+
{{ map_html|safe }}
|
429 |
+
</div>
|
430 |
+
</div>
|
431 |
+
</div>
|
432 |
+
{% endif %}
|
433 |
+
|
434 |
+
{% if recent_df is defined and not recent_df.empty %}
|
435 |
+
<!-- KPI Cards -->
|
436 |
+
<div class="row">
|
437 |
+
<div class="col-lg-3 col-md-6 col-sm-6 mb-4">
|
438 |
+
<div class="card kpi-card bg-primary bg-opacity-10 text-primary">
|
439 |
+
<i class="fas fa-chart-bar kpi-icon"></i>
|
440 |
+
<span class="kpi-value">{{ recent_df|length }}</span>
|
441 |
+
<div class="kpi-label">Recent Quakes</div>
|
442 |
+
<div class="kpi-small">Past {{ current_config.days_recent }} days</div>
|
443 |
+
</div>
|
444 |
+
</div>
|
445 |
+
|
446 |
+
<div class="col-lg-3 col-md-6 col-sm-6 mb-4">
|
447 |
+
<div class="card kpi-card {% if recent_df['magnitude'].max() >= 6.0 %}bg-danger bg-opacity-10 text-danger{% elif recent_df['magnitude'].max() >= 5.0 %}bg-warning bg-opacity-10 text-warning{% else %}bg-success bg-opacity-10 text-success{% endif %}">
|
448 |
+
<i class="fas fa-ruler kpi-icon"></i>
|
449 |
+
<span class="kpi-value">{{ "%.1f"|format(recent_df['magnitude'].max()) if recent_df['magnitude'].max() else 'N/A' }}</span>
|
450 |
+
<div class="kpi-label">Largest Magnitude</div>
|
451 |
+
<div class="kpi-small">Recent period</div>
|
452 |
+
</div>
|
453 |
+
</div>
|
454 |
+
|
455 |
+
<div class="col-lg-3 col-md-6 col-sm-6 mb-4">
|
456 |
+
<div class="card kpi-card {% if significant_quakes|length > 0 %}bg-warning bg-opacity-10 text-warning{% else %}bg-success bg-opacity-10 text-success{% endif %}">
|
457 |
+
<i class="fas fa-exclamation-triangle kpi-icon"></i>
|
458 |
+
<span class="kpi-value">{{ significant_quakes|length }}</span>
|
459 |
+
<div class="kpi-label">Significant Alerts</div>
|
460 |
+
<div class="kpi-small">M ≥ {{ current_config.alert_threshold_magnitude }}</div>
|
461 |
+
</div>
|
462 |
+
</div>
|
463 |
+
|
464 |
+
<div class="col-lg-3 col-md-6 col-sm-6 mb-4">
|
465 |
+
<div class="card kpi-card {% if tsunami_potential_events|length > 0 %}bg-danger bg-opacity-10 text-danger{% else %}bg-success bg-opacity-10 text-success{% endif %}">
|
466 |
+
<i class="fas fa-water kpi-icon"></i>
|
467 |
+
<span class="kpi-value">{{ tsunami_potential_events|length }}</span>
|
468 |
+
<div class="kpi-label">Tsunami Potential</div>
|
469 |
+
<div class="kpi-small">Recent period</div>
|
470 |
+
</div>
|
471 |
+
</div>
|
472 |
+
</div>
|
473 |
+
|
474 |
+
<div class="row">
|
475 |
+
<!-- Significant Alerts -->
|
476 |
+
<div class="col-lg-7 col-md-12 mb-4">
|
477 |
+
<div class="card">
|
478 |
+
<div class="card-header">
|
479 |
+
<i class="fas fa-exclamation-circle"></i> Significant Alerts
|
480 |
+
</div>
|
481 |
+
<div class="card-body">
|
482 |
+
{% if significant_quakes %}
|
483 |
+
{% for quake in significant_quakes[:5] %}
|
484 |
+
<div class="recent-quake {% if quake.tsunami_risk_info %}tsunami-risk{% endif %}">
|
485 |
+
<div class="d-flex align-items-center mb-2">
|
486 |
+
<span class="magnitude-badge {% if quake.magnitude >= 6.0 %}magnitude-high{% elif quake.magnitude >= 5.0 %}magnitude-med{% endif %}">
|
487 |
+
{{ "%.1f"|format(quake.magnitude) }}
|
488 |
+
</span>
|
489 |
+
<div>
|
490 |
+
<div class="fw-bold">{{ quake.place }}</div>
|
491 |
+
<div class="small text-muted">{{ quake.time.strftime('%Y-%m-%d %H:%M:%S %Z') }}</div>
|
492 |
+
</div>
|
493 |
+
</div>
|
494 |
+
<div class="d-flex justify-content-between align-items-center">
|
495 |
+
<span class="small text-muted">Depth: {{ "%.1f"|format(quake.depth) }} km</span>
|
496 |
+
<div>
|
497 |
+
{% if quake.tsunami_risk_info %}
|
498 |
+
<span class="tsunami-badge me-2">
|
499 |
+
<i class="fas fa-water me-1"></i> Tsunami Risk
|
500 |
+
</span>
|
501 |
+
{% endif %}
|
502 |
+
<a href="{{ quake.url }}" target="_blank" class="btn btn-sm btn-outline-primary">
|
503 |
+
<i class="fas fa-external-link-alt me-1"></i> Details
|
504 |
+
</a>
|
505 |
+
</div>
|
506 |
+
</div>
|
507 |
+
</div>
|
508 |
+
{% endfor %}
|
509 |
+
{% if significant_quakes|length > 5 %}
|
510 |
+
<div class="text-center mt-2">
|
511 |
+
<small class="text-muted">+ {{ significant_quakes|length - 5 }} more alerts</small>
|
512 |
+
</div>
|
513 |
+
{% endif %}
|
514 |
+
{% else %}
|
515 |
+
<div class="text-center py-4">
|
516 |
+
<i class="fas fa-check-circle fa-3x text-muted mb-3"></i>
|
517 |
+
<p>No significant alerts for the current criteria</p>
|
518 |
+
</div>
|
519 |
+
{% endif %}
|
520 |
+
</div>
|
521 |
+
</div>
|
522 |
+
</div>
|
523 |
+
|
524 |
+
<!-- AI Interpretation -->
|
525 |
+
<div class="col-lg-5 col-md-12 mb-4">
|
526 |
+
<div class="card">
|
527 |
+
<div class="card-header">
|
528 |
+
<i class="fas fa-robot"></i> AI Analysis
|
529 |
+
</div>
|
530 |
+
<div class="card-body">
|
531 |
+
{% if ai_interpretation %}
|
532 |
+
<div class="ai-interpretation">
|
533 |
+
{{ ai_interpretation|replace('\n', '<br>')|safe }}
|
534 |
+
</div>
|
535 |
+
<div class="text-center mt-2">
|
536 |
+
<small class="text-muted"><i class="fas fa-info-circle me-1"></i> AI interpretation is based on limited data and is experimental</small>
|
537 |
+
</div>
|
538 |
+
{% elif current_config.enable_ai_interpretation and not initial_load %}
|
539 |
+
<div class="text-center py-4">
|
540 |
+
<i class="fas fa-exclamation-circle fa-3x text-warning mb-3"></i>
|
541 |
+
<p>AI Interpretation was enabled, but could not be generated</p>
|
542 |
+
<small class="text-muted">Check API key configuration or data availability</small>
|
543 |
+
</div>
|
544 |
+
{% else %}
|
545 |
+
<div class="text-center py-4">
|
546 |
+
<i class="fas fa-toggle-off fa-3x text-muted mb-3"></i>
|
547 |
+
<p>AI Interpretation is disabled</p>
|
548 |
+
<small class="text-muted">Enable it in configuration settings</small>
|
549 |
+
</div>
|
550 |
+
{% endif %}
|
551 |
+
</div>
|
552 |
+
</div>
|
553 |
+
</div>
|
554 |
+
</div>
|
555 |
+
{% elif not initial_load %}
|
556 |
+
<!-- No Data Message -->
|
557 |
+
<div class="card mb-4">
|
558 |
+
<div class="card-body text-center py-5">
|
559 |
+
<i class="fas fa-search fa-3x text-muted mb-3"></i>
|
560 |
+
<h3>No Earthquake Data Found</h3>
|
561 |
+
<p class="text-muted">No data matches your current filter criteria. Try adjusting your parameters and run the analysis again.</p>
|
562 |
+
</div>
|
563 |
+
</div>
|
564 |
+
{% else %}
|
565 |
+
<!-- Initial Welcome Screen -->
|
566 |
+
<div class="card">
|
567 |
+
<div class="card-body text-center py-5">
|
568 |
+
<i class="fas fa-globe-asia fa-4x text-primary mb-4"></i>
|
569 |
+
<h2>Welcome to Seismic Monitor Pro</h2>
|
570 |
+
<p class="lead mb-4">Configure your analysis parameters and click "Run Analysis" to begin exploring earthquake data.</p>
|
571 |
+
<div class="text-start mx-auto" style="max-width: 500px;">
|
572 |
+
<h5><i class="fas fa-check-circle text-success me-2"></i> Features</h5>
|
573 |
+
<ul class="text-muted">
|
574 |
+
<li>Interactive earthquake map with historical heatmap</li>
|
575 |
+
<li>Real-time seismic alerts and potential tsunami warnings</li>
|
576 |
+
<li>AI-powered data interpretation and risk assessment</li>
|
577 |
+
<li>Customizable analysis parameters for specific regions</li>
|
578 |
+
</ul>
|
579 |
+
</div>
|
580 |
+
</div>
|
581 |
+
</div>
|
582 |
+
{% endif %}
|
583 |
+
</div>
|
584 |
+
</div>
|
585 |
+
</div>
|
586 |
+
|
587 |
+
<!-- About Modal -->
|
588 |
+
<div class="modal fade" id="aboutModal" tabindex="-1" aria-hidden="true">
|
589 |
+
<div class="modal-dialog">
|
590 |
+
<div class="modal-content">
|
591 |
+
<div class="modal-header">
|
592 |
+
<h5 class="modal-title"><i class="fas fa-info-circle me-2"></i>About This Dashboard</h5>
|
593 |
+
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
594 |
+
</div>
|
595 |
+
<div class="modal-body">
|
596 |
+
<p><strong>Seismic Monitor Pro</strong> is an advanced earthquake monitoring tool focused on the Indian subcontinent and surrounding regions.</p>
|
597 |
+
<p>The data is sourced directly from USGS earthquake feeds and refreshed each time you run an analysis.</p>
|
598 |
+
<h6 class="mt-4 mb-2">Key Features:</h6>
|
599 |
+
<ul>
|
600 |
+
<li>Interactive mapping with tectonic plate visualization</li>
|
601 |
+
<li>Historical and recent earthquake data analysis</li>
|
602 |
+
<li>Automated tsunami potential detection</li>
|
603 |
+
<li>AI-powered seismic activity interpretation</li>
|
604 |
+
</ul>
|
605 |
+
<div class="alert alert-warning-custom mt-3">
|
606 |
+
<strong>Disclaimer:</strong> This tool is for informational purposes only. Always refer to official government sources for emergency information.
|
607 |
+
</div>
|
608 |
+
</div>
|
609 |
+
<div class="modal-footer">
|
610 |
+
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
|
611 |
+
</div>
|
612 |
+
</div>
|
613 |
+
</div>
|
614 |
+
</div>
|
615 |
+
|
616 |
+
<!-- Scripts -->
|
617 |
+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script>
|
618 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
|
619 |
+
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
|
620 |
+
<script>
|
621 |
+
document.addEventListener('DOMContentLoaded', function() {
|
622 |
+
// Make KPI cards responsive on smaller screens
|
623 |
+
const resizeKpiCards = () => {
|
624 |
+
const windowWidth = window.innerWidth;
|
625 |
+
if (windowWidth < 768) {
|
626 |
+
document.querySelectorAll('.kpi-value').forEach(el => {
|
627 |
+
el.style.fontSize = '1.5rem';
|
628 |
+
});
|
629 |
+
} else {
|
630 |
+
document.querySelectorAll('.kpi-value').forEach(el => {
|
631 |
+
el.style.fontSize = '2rem';
|
632 |
+
});
|
633 |
+
}
|
634 |
+
};
|
635 |
+
|
636 |
+
// Run on initial load and when window is resized
|
637 |
+
resizeKpiCards();
|
638 |
+
window.addEventListener('resize', resizeKpiCards);
|
639 |
+
|
640 |
+
// Handle "Run Analysis" button loading state
|
641 |
+
const analysisForm = document.getElementById('analysisForm');
|
642 |
+
if (analysisForm) {
|
643 |
+
analysisForm.addEventListener('submit', function() {
|
644 |
+
const btn = document.getElementById('runAnalysisBtn');
|
645 |
+
if (btn) {
|
646 |
+
btn.disabled = true;
|
647 |
+
btn.innerHTML = '<span class="spinner-border spinner-border-sm" role="status" aria-hidden="true"></span> Analyzing...';
|
648 |
+
}
|
649 |
+
});
|
650 |
+
}
|
651 |
+
});
|
652 |
+
</script>
|
653 |
+
</body>
|
654 |
+
</html>
|