Repository navigation
Expand file tree
/
Copy pathstreamlit_app.py
More file actions
257 lines (217 loc) · 8.91 KB
/
Copy pathstreamlit_app.py
File metadata and controls
257 lines (217 loc) · 8.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
"""
ARGO Float Data Visualization Dashboard
Government-grade Streamlit application for oceanographic data exploration
"""
import streamlit as st
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
from datetime import datetime, timedelta
import requests
from typing import Dict, List, Optional, Tuple
import logging
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
# Page configuration
st.set_page_config(
page_title="ARGO Float Data Dashboard",
page_icon="🌊",
layout="wide",
initial_sidebar_state="expanded",
menu_items={
'Get Help': None,
'Report a bug': None,
'About': "ARGO Float Data Visualization Dashboard - Government Edition"
}
)
# Import custom components
try:
from components.api_client import APIClient, APIException
from components.data_transformer import DataTransformer
from utils.dashboard_utils import init_session_state, validate_data_quality
from dashboard_config import dashboard_config
# Components to be created in later tasks
from components.layout_manager import DashboardLayout
from components.chat_interface import ChatInterface
from components.map_visualization import InteractiveMap
from components.profile_visualizer import ProfileVisualizer
from components.data_manager import DataManager
from components.statistics_manager import StatisticsManager
except ImportError as e:
# Some components not yet available - will be created in later tasks
logger.warning(f"Some components not yet available: {e}")
APIClient = None
DataTransformer = None
init_session_state = None
validate_data_quality = None
dashboard_config = None
def main():
"""Main application entry point"""
# Initialize session state
if init_session_state:
init_session_state()
else:
# Fallback initialization
if 'initialized' not in st.session_state:
st.session_state.initialized = True
st.session_state.api_client = None
st.session_state.chat_history = []
st.session_state.selected_floats = []
st.session_state.filter_state = {}
# Initialize API client if not already done
if st.session_state.api_client is None:
try:
if APIClient and dashboard_config:
st.session_state.api_client = APIClient(base_url=dashboard_config.API_BASE_URL)
else:
# Fallback to direct URL
st.session_state.api_client = APIClient(base_url="http://localhost:8000")
except Exception as e:
logger.error(f"Failed to initialize API client: {e}")
st.session_state.api_client = None
# Initialize layout manager
try:
from components.layout_manager import DashboardLayout
layout = DashboardLayout()
# Apply custom styling
layout.apply_custom_styling()
# Render header
layout.render_header()
# Render sidebar and get navigation state
sidebar_state = layout.render_sidebar()
# Render main content
layout.render_main_content(
active_tab=sidebar_state["selected_tab"],
filters=sidebar_state["filters"]
)
# Render footer
layout.render_footer()
except ImportError:
# Fallback to simple layout if layout manager not available
render_fallback_layout()
def render_overview_tab():
"""Render the overview dashboard tab"""
st.header("📊 System Overview")
# Create placeholder metrics
col1, col2, col3, col4 = st.columns(4)
with col1:
st.metric("Active Floats", "50", "2")
with col2:
st.metric("Total Profiles", "1,234", "45")
with col3:
st.metric("Measurements", "45,678", "1,203")
with col4:
st.metric("Data Quality", "98.5%", "0.2%")
st.markdown("---")
# Placeholder for overview visualizations
st.subheader("Recent Activity")
st.info("📈 Overview charts and recent data summaries will be displayed here")
# Sample data for demonstration
sample_data = pd.DataFrame({
'Date': pd.date_range('2024-01-01', periods=30, freq='D'),
'Measurements': [100 + i*5 + (i%7)*10 for i in range(30)]
})
fig = px.line(sample_data, x='Date', y='Measurements',
title="Daily Measurement Count (Sample Data)")
st.plotly_chart(fig, use_container_width=True)
def render_map_tab():
"""Render the interactive map tab"""
st.header("🗺️ Interactive Float Map")
st.info("🚧 Interactive map with ARGO float locations will be implemented in Task 4")
# Placeholder map
st.markdown("**Features to be implemented:**")
st.markdown("- Float location markers with clustering")
st.markdown("- Trajectory visualization with temporal coloring")
st.markdown("- Geographic region selection")
st.markdown("- Real-time filtering integration")
def render_profile_tab():
"""Render the profile analysis tab"""
st.header("📈 Profile Analysis")
st.info("🚧 Temperature-salinity-depth profiles will be implemented in Task 5")
# Placeholder content
st.markdown("**Features to be implemented:**")
st.markdown("- Temperature-salinity-depth profile plots")
st.markdown("- Multi-profile comparison overlays")
st.markdown("- BGC parameter visualization")
st.markdown("- Statistical analysis integration")
def render_chat_tab():
"""Render the chat interface tab"""
try:
from components.chat_interface import ChatInterface
# Initialize chat interface with API client
chat_interface = ChatInterface(api_client=st.session_state.get('api_client'))
# Render the chat container
chat_interface.render_chat_container()
except ImportError:
st.header("💬 Natural Language Query Interface")
st.error("❌ Chat interface component not available")
# Fallback interface
st.markdown("**Example queries you can ask:**")
st.markdown("- 'Show me salinity profiles near the equator in March 2023'")
st.markdown("- 'Compare BGC parameters in the Arabian Sea for the last 6 months'")
st.markdown("- 'What are the nearest ARGO floats to this location?'")
user_input = st.text_input("Enter your query:")
if user_input:
st.info("🚧 Chat interface will be available once all components are properly installed.")
except Exception as e:
st.error(f"Error loading chat interface: {e}")
logger.error(f"Chat interface error: {e}")
def render_fallback_layout():
"""Fallback layout when layout manager is not available"""
st.markdown("""
<style>
h1 {
color: #FFFFFF !important;
}
</style>
""", unsafe_allow_html=True)
st.title("🌊 ARGO Float Data Dashboard")
st.markdown("**Government Oceanographic Data Visualization System**")
# Simple sidebar
with st.sidebar:
st.header("Navigation")
tab_selection = st.selectbox(
"Select Dashboard Section",
["Overview", "Interactive Map", "Profile Analysis", "Chat Interface", "Data Export"]
)
st.header("System Status")
# Check API client
if st.session_state.get('api_client'):
try:
health_data = st.session_state.api_client.health_check()
if health_data.get("status") == "healthy":
st.success("✅ Backend Connected")
else:
st.error("❌ Backend Disconnected")
except Exception as e:
st.error(f"❌ Connection Failed: {str(e)}")
else:
st.warning("⚠️ API Client Not Available - Initializing...")
try:
st.session_state.api_client = APIClient(base_url="http://localhost:8000")
st.success("✅ API Client Initialized")
except Exception as e:
st.error(f"❌ Failed to initialize API client: {str(e)}")
# Simple content based on tab
if tab_selection == "Overview":
render_overview_tab()
elif tab_selection == "Interactive Map":
render_map_tab()
elif tab_selection == "Profile Analysis":
render_profile_tab()
elif tab_selection == "Chat Interface":
render_chat_tab()
elif tab_selection == "Data Export":
render_export_tab()
def render_export_tab():
"""Render the data export tab"""
st.header("📥 Data Export")
st.info("🚧 Export functionality will be implemented in Task 8")
# Placeholder export options
st.markdown("**Export formats to be supported:**")
st.markdown("- Visualizations: PNG, PDF, SVG")
st.markdown("- Data: ASCII, NetCDF, CSV")
st.markdown("- Reports: PDF with metadata")
if __name__ == "__main__":
main()