-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
1114 lines (977 loc) · 52.2 KB
/
Copy pathmain.py
File metadata and controls
1114 lines (977 loc) · 52.2 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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import streamlit as st
import requests
import json
from datetime import datetime, timedelta
import plotly.graph_objects as go
import plotly.express as px
from PIL import Image
import base64
from io import BytesIO
import time
import pandas as pd
import numpy as np
import math
import os
from weather_api import PremiumWeatherAPI
from location_detector import PremiumLocationDetector
from ui_components import UIComponents
from data_processor import AdvancedDataProcessor
# Premium page configuration
st.set_page_config(
page_title="Climatrack • Premium Weather Intelligence",
page_icon="🌤️",
layout="wide",
initial_sidebar_state="expanded",
menu_items={
'Get Help': 'https://github.com/theeccentriccoder01/climatrack',
'Report a bug': "https://github.com/theeccentriccoder01/climatrack/issues",
'About': "# Climatrack\nPremium weather intelligence platform with AI-powered insights"
}
)
def get_img_as_base64(file):
script_dir = os.path.dirname(os.path.abspath(__file__))
abs_file_path = os.path.join(script_dir, file)
try:
with open(abs_file_path, "rb") as f:
data = f.read()
return base64.b64encode(data).decode()
except FileNotFoundError:
st.error(f"Image file not found at: {abs_file_path}. Please check your file path and project structure.")
return None
class PremiumWeatherApp:
"""World-class premium weather intelligence platform"""
def __init__(self):
self.weather_api = PremiumWeatherAPI()
self.location_detector = PremiumLocationDetector()
self.ui = UIComponents()
self.data_processor = AdvancedDataProcessor()
# Premium app state
self.views = {
'dashboard': '🏠 Dashboard',
'forecast': '📅 Extended Forecast',
'radar': '🗺️ Weather Radar',
'maps': '🌍 Interactive Maps',
'analytics': '📊 Weather Analytics',
'compare': '⚖️ Location Compare',
'alerts': '🚨 Weather Alerts',
'historical': '📈 Historical Data'
}
def initialize_session_state(self):
"""Initialize premium session state with advanced features"""
defaults = {
# Core data
'location_data': None,
'weather_data': None,
'forecast_data': None,
'hourly_data': None,
'air_quality_data': None,
'radar_data': None,
'alerts_data': None,
'historical_data': None,
# UI state
'current_view': 'dashboard',
'sidebar_expanded': True,
'background_mode': 'dynamic',
'animation_enabled': True,
'sound_enabled': False,
# User preferences
'units': 'metric',
'language': 'en',
'favorite_locations': [],
'comparison_locations': [],
'custom_alerts': [],
# CORRECTED: Default widgets now match available widget keys
'dashboard_widgets': ['current_weather', 'hourly_forecast', 'weekly_forecast', 'air_quality'],
# Advanced features
'notifications_enabled': True,
'auto_refresh': True,
'refresh_interval': 300,
'data_quality_alerts': True,
'performance_mode': 'balanced',
# Analytics
'weather_history': [],
'location_history': [],
'app_usage_stats': {
'sessions': 0,
'locations_searched': 0,
'forecasts_viewed': 0
},
# Premium features
'premium_maps_enabled': True,
'advanced_analytics': True,
'historical_access': True,
'unlimited_locations': True,
# Cache and performance
'last_update': None,
'cache_enabled': True,
'preload_data': True
}
for key, value in defaults.items():
if key not in st.session_state:
st.session_state[key] = value
# Update usage statistics
if 'app_initialized' not in st.session_state:
st.session_state.app_usage_stats['sessions'] += 1
st.session_state.app_initialized = True
# In main.py
def load_premium_styling(self):
"""Load world-class premium styling system with a global override for the background."""
img = get_img_as_base64("assets/Background.jpg")
# This is a single, consolidated block of CSS.
# It includes the styles from ui_components.py and adds a brute-force background fix at the end.
st.markdown(f"""
<style>
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@100..900&family=JetBrains+Mono:wght@100..800&family=Playfair+Display:wght@400..900&family=Space+Grotesk:wght@300..700&display=swap');
/* Root Variables */
:root {{
--secondary: #00d4ff; --primary: #7c3aed; --accent: #06ffa5;
--warm: #ff6b35; --cold: #4facfe; --success: #10b981;
--warning: #f59e0b; --error: #ef4444; --info: #3b82f6;
}}
body, #root, [data-testid="stAppViewContainer"], [data-testid="stAppViewContainer"] > .main {{
background-image: url("data:image/png;base64,{img}") !important;
background-size: cover !important;
background-position: center center !important;
background-repeat: no-repeat !important;
background-attachment: fixed !important;
background-color: #0F1116 !important; /* Fallback color */
}}
.stAppViewBlockContainer {{
background-color: transparent !important;
background: transparent !important;
}}
/* Styling for the sidebar */
.stSidebar {{
background: rgba(255, 255, 255, 0.02) !important;
border-right: 1px solid rgba(255, 255, 255, 0.1) !important;
backdrop-filter: blur(20px) !important;
}}
/* Hide Default Streamlit Elements */
.stDeployButton, #MainMenu, footer, header, .stDecoration {{
display: none !important;
}}
/* Custom Scrollbar */
::-webkit-scrollbar {{ width: 8px; height: 8px; }}
::-webkit-scrollbar-track {{ background: rgba(0, 0, 0, 0.2); }}
::-webkit-scrollbar-thumb {{ background: linear-gradient(180deg, var(--primary), var(--secondary)); border-radius: 9999px; }}
</style>
""", unsafe_allow_html=True)
def render_premium_sidebar(self):
"""Render sophisticated sidebar navigation"""
with st.sidebar:
# App branding
st.markdown("""
<div style="text-align: center; padding: 20px 0; margin-bottom: 30px;">
<h1 style="
font-family: 'Playfair Display', serif;
font-size: 28px;
font-weight: 800;
background: linear-gradient(135deg, var(--secondary), var(--accent));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
margin: 0;
">Climatrack</h1>
<p style="
color: rgba(255, 255, 255, 0.6);
font-size: 12px;
margin: 5px 0 0 0;
text-transform: uppercase;
letter-spacing: 2px;
">Premium Intelligence</p>
</div>
""", unsafe_allow_html=True)
# Navigation menu
st.markdown("### 🧭 Navigation")
for view_key, view_name in self.views.items():
is_active = st.session_state.current_view == view_key
if st.button(
view_name,
key=f"nav_{view_key}",
use_container_width=True,
type="primary" if is_active else "secondary"
):
st.session_state.current_view = view_key
st.rerun()
st.markdown("---")
# Quick actions
st.markdown("### ⚡ Quick Actions")
col1, col2, col3 = st.columns(3)
with col1:
if st.button("🔄", help="Refresh Data"):
self.refresh_weather_data()
st.rerun()
with col2:
if st.button("⭐", help="Add to Favorites"):
self.add_current_to_favorites()
with col3:
# ADDED: Share functionality
if st.button("📤", help="Share Weather"):
if st.session_state.location_data:
location = st.session_state.location_data
st.success("Link copied to clipboard!")
st.code(f"https://climatrack.app/dashboard?lat={location['lat']}&lon={location['lon']}")
else:
st.warning("Search for a location to share.")
# Location shortcuts
st.markdown("### 📍 Quick Locations")
quick_locations = [
("🏠 Current", "auto"),
("🗽 New York", "New York, US"),
("🏛️ London", "London, UK"),
("🗼 Tokyo", "Tokyo, JP"),
("🦘 Sydney", "Sydney, AU")
]
for name, location in quick_locations:
if st.button(name, key=f"quick_{location}", use_container_width=True):
self.handle_quick_location(location)
st.rerun()
st.markdown("---")
# Settings section
st.markdown("### ⚙️ Settings")
# Units selector
new_units = st.selectbox(
"Units",
["metric", "imperial", "kelvin"],
format_func=lambda x: {"metric": "Metric (°C)", "imperial": "Imperial (°F)", "kelvin": "Scientific (K)"}[x]
)
if new_units != st.session_state.units:
st.session_state.units = new_units
self.refresh_weather_data()
st.rerun()
# Premium features toggles
st.session_state.animation_enabled = st.checkbox("🎭 Animations", value=st.session_state.animation_enabled)
st.session_state.auto_refresh = st.checkbox("🔄 Auto Refresh", value=st.session_state.auto_refresh)
st.session_state.notifications_enabled = st.checkbox("🔔 Notifications", value=st.session_state.notifications_enabled)
# Status indicators
st.markdown("---")
st.markdown("### 📊 System Status")
# API status
api_validation = self.weather_api.validate_api_key_comprehensive()
status_color = "🟢" if api_validation.get('is_valid') else "🔴"
status_message = api_validation.get('status', 'unknown').replace('_', ' ').title()
st.markdown(f"{status_color} **API Status:** {status_message}")
# Data freshness
if st.session_state.last_update:
time_diff = datetime.now() - st.session_state.last_update
freshness = "🟢 Fresh" if time_diff.seconds < 300 else "🟡 Aging" if time_diff.seconds < 900 else "🔴 Stale"
st.markdown(f"{freshness} **Data:** {time_diff.seconds//60}m ago")
# Usage stats
stats = st.session_state.app_usage_stats
st.markdown(f"📈 **Sessions:** {stats['sessions']}")
st.markdown(f"🌍 **Locations:** {stats['locations_searched']}")
def render_content_area(self):
"""Render main content area based on current view"""
# Premium header
self.render_premium_header()
# Content routing
if st.session_state.current_view == 'dashboard':
self.render_dashboard_view()
elif st.session_state.current_view == 'forecast':
self.render_forecast_view()
elif st.session_state.current_view == 'radar':
self.render_radar_view()
elif st.session_state.current_view == 'maps':
self.render_maps_view()
elif st.session_state.current_view == 'analytics':
self.render_analytics_view()
elif st.session_state.current_view == 'compare':
self.render_compare_view()
elif st.session_state.current_view == 'alerts':
self.render_alerts_view()
elif st.session_state.current_view == 'historical':
self.render_historical_view()
def render_premium_header(self):
"""Render premium application header"""
col1, col2, col3 = st.columns([2, 3, 2])
with col1:
if st.session_state.location_data:
location = st.session_state.location_data
st.markdown(f"""
<div style="
background: rgba(255, 255, 255, 0.05);
padding: 12px 20px;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
">
<div style="color: white; font-weight: 600; font-size: 16px;">
📍 {location['city']}, {location['country']}
</div>
<div style="color: rgba(255, 255, 255, 0.6); font-size: 12px;">
{location['lat']:.4f}, {location['lon']:.4f}
</div>
</div>
""", unsafe_allow_html=True)
with col2:
# Premium search bar
self.render_premium_search(suffix="_header")
with col3:
# Current time and weather summary
now = datetime.now()
if st.session_state.weather_data:
temp = st.session_state.weather_data['main']['temp']
condition = st.session_state.weather_data['weather'][0]['description'].title()
temp_unit = "°C" if st.session_state.units == "metric" else "°F"
st.markdown(f"""
<div style="text-align: right;">
<div style="color: white; font-weight: 600; font-size: 16px;">
{temp:.0f}{temp_unit} • {condition}
</div>
<div style="color: rgba(255, 255, 255, 0.6); font-size: 12px;">
{now.strftime('%H:%M, %A %d %B')}
</div>
</div>
""", unsafe_allow_html=True)
def render_premium_search(self, suffix=""):
"""Render premium search interface"""
st.markdown('<div class="premium-search-container">', unsafe_allow_html=True)
search_query = st.text_input(
"",
placeholder="🔍 Search locations, coordinates, or points of interest...",
key=f"premium_search{suffix}",
label_visibility="collapsed"
)
if search_query:
suggestions = self.location_detector.search_location_advanced(search_query)
if suggestions:
selected = st.selectbox(
"Suggestions",
suggestions,
format_func=lambda x: x['display_name'],
key="search_suggestions",
label_visibility="collapsed"
)
if st.button("🎯 Go to Location", use_container_width=True):
self.handle_location_selection(selected)
st.rerun()
st.markdown('</div>', unsafe_allow_html=True)
def _get_tile_coords(self, lat: float, lon: float, zoom: int) -> tuple[int, int]:
"""Convert lat/lon to slippy map tile coordinates."""
lat_rad = math.radians(lat)
n = 2.0 ** zoom
xtile = int((lon + 180.0) / 360.0 * n)
ytile = int((1.0 - math.asinh(math.tan(lat_rad)) / math.pi) / 2.0 * n)
return xtile, ytile
def render_dashboard_view(self):
"""Render premium dashboard with customizable widgets"""
if not st.session_state.weather_data:
self.render_welcome_screen()
return
# Hero weather section
self.render_hero_weather_section()
# Customizable widget grid
st.markdown("### 📊 Weather Intelligence Dashboard")
# Widget configuration
available_widgets = {
'current_weather': 'Current Conditions',
'hourly_forecast': '24-Hour Forecast',
'weekly_forecast': '7-Day Forecast',
'air_quality': 'Air Quality Index',
'uv_index': 'UV Index & Solar',
'pressure_trends': 'Atmospheric Pressure',
'wind_analysis': 'Wind Conditions',
'precipitation': 'Precipitation Radar',
'satellite': 'Satellite Imagery',
'alerts': 'Weather Alerts'
}
# Widget selector
col1, col2 = st.columns([3, 1])
with col2:
valid_default_widgets = [widget for widget in st.session_state.dashboard_widgets if widget in available_widgets]
selected_widgets = st.multiselect(
"Customize Dashboard",
list(available_widgets.keys()),
default=valid_default_widgets,
format_func=lambda x: available_widgets[x]
)
st.session_state.dashboard_widgets = selected_widgets
# Render selected widgets
if selected_widgets:
# Create responsive grid
cols_per_row = 2
for i in range(0, len(selected_widgets), cols_per_row):
cols = st.columns(cols_per_row)
for j, widget in enumerate(selected_widgets[i:i+cols_per_row]):
with cols[j]:
self.render_widget(widget)
def render_widget(self, widget_type):
"""Render individual dashboard widgets"""
with st.container():
if widget_type == 'current_weather':
self.render_current_weather_widget()
elif widget_type == 'hourly_forecast':
self.render_hourly_forecast_widget()
elif widget_type == 'weekly_forecast':
self.render_weekly_forecast_widget()
elif widget_type == 'air_quality':
self.render_air_quality_widget()
elif widget_type == 'uv_index':
self.render_uv_index_widget()
elif widget_type == 'pressure_trends':
self.render_pressure_trends_widget()
elif widget_type == 'wind_analysis':
self.render_wind_analysis_widget()
elif widget_type == 'precipitation':
self.render_precipitation_widget()
elif widget_type == 'satellite':
self.render_satellite_widget()
elif widget_type == 'alerts':
self.render_alerts_widget()
def render_hero_weather_section(self):
"""Render the main hero weather display"""
weather = st.session_state.weather_data
# Create hero section with premium styling
st.markdown("""
<div style="
background: linear-gradient(135deg, rgba(0, 212, 255, 0.1), rgba(124, 58, 237, 0.1));
border-radius: 24px;
padding: 40px;
margin: 20px 0;
border: 1px solid rgba(255, 255, 255, 0.1);
backdrop-filter: blur(5px);
position: relative;
overflow: hidden;
">
""", unsafe_allow_html=True)
col1, col2, col3 = st.columns([1, 2, 1])
with col1:
icon_code = weather['weather'][0]['icon']
condition = weather['weather'][0]['main'].lower()
st.markdown(
self.ui.create_animated_weather_icon(icon_code, condition, size="120px"),
unsafe_allow_html=True
)
with col2:
temp_unit = "°C" if st.session_state.units == "metric" else "°F"
temp = weather['main']['temp']
condition = weather['weather'][0]['description'].title()
feels_like = weather['main']['feels_like']
st.markdown(f"""
<div style="text-align: center;">
<div style="
font-size: 4rem;
font-weight: 800;
background: linear-gradient(135deg, #ffffff, #e2e8f0);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
line-height: 0.9;
margin-bottom: 10px;
">{temp:.0f}{temp_unit}</div>
<div style="
font-size: 1.5rem;
color: rgba(255, 255, 255, 0.9);
margin-bottom: 10px;
font-weight: 500;
">{condition}</div>
<div style="
font-size: 1rem;
color: rgba(255, 255, 255, 0.6);
">Feels like {feels_like:.0f}{temp_unit}</div>
</div>
""", unsafe_allow_html=True)
with col3:
humidity = weather['main']['humidity']
wind_speed = weather['wind']['speed']
pressure = weather['main']['pressure']
st.markdown(f"""
<div style="text-align: center;">
<div style="margin-bottom: 15px;">
<div style="color: rgba(255, 255, 255, 0.6); font-size: 0.8rem;">HUMIDITY</div>
<div style="color: white; font-size: 1.2rem; font-weight: 600;">{humidity}%</div>
</div>
<div style="margin-bottom: 15px;">
<div style="color: rgba(255, 255, 255, 0.6); font-size: 0.8rem;">WIND</div>
<div style="color: white; font-size: 1.2rem; font-weight: 600;">{wind_speed:.1f} m/s</div>
</div>
<div>
<div style="color: rgba(255, 255, 255, 0.6); font-size: 0.8rem;">PRESSURE</div>
<div style="color: white; font-size: 1.2rem; font-weight: 600;">{pressure} hPa</div>
</div>
</div>
""", unsafe_allow_html=True)
st.markdown("</div>", unsafe_allow_html=True)
# Quick metrics bar
self.render_quick_metrics_bar()
def render_quick_metrics_bar(self):
"""Render quick metrics below hero section"""
weather = st.session_state.weather_data
metrics = [
("🌡️", "Feels Like", f"{weather['main']['feels_like']:.0f}°", "Apparent temperature"),
("👁️", "Visibility", f"{weather.get('visibility', 10000)/1000:.1f} km", "Horizontal visibility"),
("☁️", "Clouds", f"{weather['clouds']['all']}%", "Cloud coverage"),
("🌅", "Sunrise", datetime.fromtimestamp(weather['sys']['sunrise']).strftime('%H:%M'), "Local sunrise"),
("🌇", "Sunset", datetime.fromtimestamp(weather['sys']['sunset']).strftime('%H:%M'), "Local sunset"),
("🧭", "Direction", self.data_processor.format_wind_direction(weather['wind'].get('deg', 0)), "Wind direction")
]
cols = st.columns(len(metrics))
for i, (icon, label, value, description) in enumerate(metrics):
with cols[i]:
st.markdown(f"""
<div class="metric-card" style="text-align: center; padding: 16px;">
<div class="metric-icon">{icon}</div>
<div class="metric-value" style="font-size: 18px;">{value}</div>
<div class="metric-label" style="font-size: 11px;">{label}</div>
</div>
""", unsafe_allow_html=True)
def render_welcome_screen(self):
"""Render premium welcome screen"""
c_logo_base64 = get_img_as_base64("assets/C.png")
if c_logo_base64 is None:
logo_html = "C"
else:
logo_html = f"""
<img src="data:image/png;base64,{c_logo_base64}"
alt="C Logo"
style="
height: 1.2em;
vertical-align: middle;
margin-right: 0.05em;
margin-left: 0.3em;
filter: drop-shadow(0 0 5px rgba(0, 212, 255, 0.5));
">
"""
st.markdown(f"""
<div style="
text-align: center;
padding: 60px 40px;
background: linear-gradient(135deg, rgba(0, 212, 255, 0.1), rgba(124, 58, 237, 0.1));
border-radius: 24px;
border: 1px solid rgba(255, 255, 255, 0.1);
backdrop-filter: blur(5px);
margin: 40px 0;
">
<h1 style="
font-size: 3rem;
font-weight: 800;
background: linear-gradient(135deg, var(--primary), var(--warning));
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
margin-bottom: 20px;
display: flex;
align-items: center;
justify-content: center;
">
🌤️ Welcome to {logo_html}limatrack Premium
</h1>
<p style="
font-size: 1.2rem;
color: rgba(255, 255, 255, 0.8);
margin-bottom: 30px;
max-width: 600px;
margin-left: auto;
margin-right: auto;
line-height: 1.6;
">
Experience the world's most advanced weather intelligence platform with AI-powered insights,
premium visualisations, and real-time global weather data.
</p>
</div>
""", unsafe_allow_html=True)
# Feature highlights
col1, col2, col3 = st.columns(3)
features = [
("🎯", "Precision Forecasting", "AI-powered weather predictions with unprecedented accuracy"),
("🌍", "Global Coverage", "Real-time weather data from thousands of stations worldwide"),
("📊", "Advanced Analytics", "Comprehensive weather trends and historical analysis"),
]
for i, (icon, title, description) in enumerate(features):
with [col1, col2, col3][i]:
st.markdown(f"""
<div style="
text-align: center;
padding: 30px 20px;
background: rgba(255, 255, 255, 0.03);
border-radius: 16px;
border: 1px solid rgba(255, 255, 255, 0.1);
backdrop-filter: blur(5px);
margin: 10px 0;
transition: transform 0.3s ease;
">
<div style="font-size: 2.5rem; margin-bottom: 15px;">{icon}</div>
<h3 style="color: white; margin-bottom: 10px; font-size: 1.1rem;">{title}</h3>
<p style="color: rgba(255, 255, 255, 0.7); font-size: 0.9rem; line-height: 1.4;">{description}</p>
</div>
""", unsafe_allow_html=True)
# Call to action
st.markdown("### 🌍 Get Started")
def render_forecast_view(self):
"""Render the 7-day extended forecast view with advanced analytics."""
st.markdown("## 📅 Extended Forecast")
if not st.session_state.get('processed_forecast_data'):
st.info("Search for a location to see the extended forecast.")
return
forecast_data = st.session_state.processed_forecast_data
with st.container():
st.markdown("#### Forecast Overview")
fig = go.Figure()
dates = [day['date'] for day in forecast_data]
temp_max = [day['temp_max'] for day in forecast_data]
temp_min = [day['temp_min'] for day in forecast_data]
precip_chance = [day['precipitation_chance'] for day in forecast_data]
fig.add_trace(go.Scatter(x=dates, y=temp_max, name='Max Temp', mode='lines+markers',
line=dict(color='var(--warm)', width=3), marker=dict(size=8)))
fig.add_trace(go.Scatter(x=dates, y=temp_min, name='Min Temp', mode='lines+markers',
line=dict(color='var(--cold)', width=3), marker=dict(size=8)))
primary_rgb = "0, 212, 255"
fig.add_trace(go.Bar(x=dates, y=precip_chance, name='Precipitation',
marker=dict(color=f'rgba({primary_rgb}, 0.5)'), yaxis='y2'))
fig.update_layout(
template="plotly_dark",
plot_bgcolor='rgba(0,0,0,0)', paper_bgcolor='rgba(0,0,0,0)',
legend=dict(orientation="h", yanchor="bottom", y=1.02, xanchor="right", x=1),
yaxis=dict(title='Temperature (°C)'),
yaxis2=dict(title='Precipitation (%)', overlaying='y', side='right', range=[0, 100]),
margin=dict(l=20, r=20, t=20, b=20)
)
st.plotly_chart(fig, use_container_width=True)
st.markdown("---")
for day in forecast_data:
with st.expander(f"{day['day_full']}, {day['date'].strftime('%b %d')} - {day['condition']}", expanded=day['date'].date() == datetime.now().date()):
cols = st.columns([1, 2])
with cols[0]:
st.image(f"http://openweathermap.org/img/wn/{day['icon']}@4x.png", width=128)
st.markdown(f"<p style='text-align:center; color: var(--accent);'>{day['comfort_level']} Comfort ({day['comfort_score']:.0f}%)</p>", unsafe_allow_html=True)
with cols[1]:
metric_cols = st.columns(3)
with metric_cols[0]:
st.metric("Temperature", f"{day['temp_avg']:.0f}°C", f"{day['temp_max']:.0f}° / {day['temp_min']:.0f}°")
st.metric("Precipitation", f"{day['precipitation_chance']:.0f}%", f"{day['precipitation_avg']:.1f} mm")
with metric_cols[1]:
st.metric("Wind", f"{day['wind_speed']:.1f} m/s", self.data_processor.format_wind_direction(day['wind_direction_avg']))
st.metric("Humidity", f"{day['humidity']:.0f}%", f"{day['humidity_range']:.0f}% range")
with metric_cols[2]:
st.metric("Pressure", f"{day['pressure_avg']:.0f} hPa", day['pressure_trend'].title())
st.metric("UV Index", f"{day['uv_index_max']:.1f}", "Max Daily")
def render_radar_view(self):
"""Render the weather radar view using an embedded map."""
st.markdown("## 🗺️ Weather Radar")
if not st.session_state.get('location_data'):
st.info("Search for a location to view the weather radar.")
return
lat = st.session_state.location_data['lat']
lon = st.session_state.location_data['lon']
embed_url = f"https://embed.windy.com/embed2.html?lat={lat}&lon={lon}&zoom=8&level=surface&overlay=radar&menu=&message=&marker=&calendar=now&pressure=&type=map&location=coordinates&detail=&metricWind=m%2Fs&metricTemp=%C2%B0C&radarRange=-1"
st.components.v1.html(f'<iframe width="100%" height="600" src="{embed_url}" frameborder="0"></iframe>', height=610)
def render_maps_view(self):
"""Render various interactive weather map layers."""
st.markdown("## 🌍 Interactive Weather Maps")
if not st.session_state.get('location_data'):
st.info("Search for a location to explore weather maps.")
return
map_layers = {
'Temperature': 'temp_new',
'Precipitation': 'precipitation_new',
'Wind Speed': 'wind_new',
'Pressure': 'pressure_new',
'Clouds': 'clouds_new'
}
selected_layer_name = st.selectbox("Select Map Layer", list(map_layers.keys()))
selected_layer_code = map_layers[selected_layer_name]
lat = st.session_state.location_data['lat']
lon = st.session_state.location_data['lon']
zoom = 6
# CORRECTED: Convert lat/lon to the correct tile coordinates
xtile, ytile = self._get_tile_coords(lat, lon, zoom)
# Build the URL with the correct x and y tile values
tile_url = f"https://tile.openweathermap.org/map/{selected_layer_code}/{zoom}/{xtile}/{ytile}.png?appid={self.weather_api.api_key}"
st.markdown(f"#### {selected_layer_name} Map")
st.image(tile_url, caption=f"Weather map layer showing {selected_layer_name.lower()}.", use_column_width=True)
st.info("Note: For a fully interactive map experience, integration with a mapping library like Folium or Leaflet is recommended. This view displays the relevant map tile for the selected location.")
def render_analytics_view(self):
"""Render the weather analytics view with trend analysis."""
st.markdown("## 📊 Weather Analytics")
if not st.session_state.get('processed_forecast_data'):
st.info("Search for a location to generate weather analytics.")
return
forecast_data = st.session_state.processed_forecast_data
trends = self.data_processor.calculate_weather_trends_advanced(forecast_data)
st.markdown("#### Key Trends for the Next 7 Days")
cols = st.columns(4)
with cols[0]:
temp_trend = trends['temperature']['avg_trend']
# CORRECTED: Using st.components.v1.html for robust rendering
st.components.v1.html(self.ui.create_premium_metric_card("🌡️", "Temperature Trend", temp_trend['direction'].title(), f"{temp_trend['slope']:.1f}°/day"))
with cols[1]:
pressure_trend = trends['pressure']['trend']
# CORRECTED: Using st.components.v1.html for robust rendering
st.components.v1.html(self.ui.create_premium_metric_card("💨", "Pressure Trend", pressure_trend['direction'].title(), f"{pressure_trend['slope']:.1f} hPa/day"))
with cols[2]:
comfort_trend = trends['comfort']['trend']
# CORRECTED: Using st.components.v1.html for robust rendering
st.components.v1.html(self.ui.create_premium_metric_card("😊", "Comfort Trend", comfort_trend['direction'].title(), f"{comfort_trend['slope']:.1f}%/day"))
with cols[3]:
change_prob = trends['pressure']['weather_change_likelihood']['probability']
# CORRECTED: Using st.components.v1.html for robust rendering
st.components.v1.html(self.ui.create_premium_metric_card("🔄", "Change Likelihood", f"{change_prob:.0%}", "Chance of pattern shift"))
# --- Detailed Analytics Sections --- (This part remains unchanged)
with st.expander("🌡️ Temperature Deep Dive", expanded=True):
temp_analytics = trends['temperature']
st.markdown(f"**Volatility:** {temp_analytics['volatility']:.2f}°C (day-to-day fluctuation)")
st.markdown(f"**Heat Wave Risk:** {temp_analytics['heat_wave_risk']:.0%}")
st.markdown(f"**Cold Snap Risk:** {temp_analytics['cold_snap_risk']:.0%}")
diurnal_trend = temp_analytics['diurnal_range_trend']
st.markdown(f"**Daily Temp Range Trend:** {diurnal_trend['direction'].title()} ({diurnal_trend['slope']:.2f}°C/day)")
with st.expander("😊 Comfort & Activity Forecast", expanded=True):
comfort_analytics = trends['comfort']
st.markdown(f"**Average Comfort Score:** {comfort_analytics['avg']:.0f}%")
st.markdown(f"**Forecast Quality:** {comfort_analytics['forecast_quality']['quality'].title()}")
st.markdown("**Optimal Days:**")
for day in comfort_analytics['optimal_days']:
st.markdown(f"- **{day['day']}**: Score {day['overall_score']:.0f}/100 ({', '.join(day['reasons'])})")
def render_compare_view(self):
"""Render the location comparison view."""
st.markdown("## ⚖️ Location Comparison")
if 'comparison_locations_data' not in st.session_state:
st.session_state.comparison_locations_data = {}
new_location_query = st.text_input("Add a location to compare (e.g., 'Paris, FR')")
if new_location_query:
suggestions = self.location_detector.search_location_advanced(new_location_query, limit=1)
if suggestions:
location_info = suggestions[0]
location_key = location_info['display_name']
if location_key not in st.session_state.comparison_locations_data:
with st.spinner(f"Fetching weather for {location_key}..."):
weather_data = self.weather_api.get_current_weather_enhanced(location_info['lat'], location_info['lon'])
if weather_data:
st.session_state.comparison_locations_data[location_key] = weather_data
st.rerun()
if not st.session_state.comparison_locations_data:
st.info("Add one or more locations to start comparing their current weather conditions.")
return
locations = list(st.session_state.comparison_locations_data.keys())
cols = st.columns(len(locations))
for i, loc_name in enumerate(locations):
with cols[i]:
weather = st.session_state.comparison_locations_data[loc_name]
st.markdown(f"#### {loc_name}")
st.image(f"http://openweathermap.org/img/wn/{weather['weather'][0]['icon']}@2x.png", width=80)
st.metric("Temperature", f"{weather['main']['temp']:.1f}°C", f"Feels like {weather['main']['feels_like']:.1f}°C")
st.metric("Condition", weather['weather'][0]['description'].title())
st.metric("Wind", f"{weather['wind']['speed']:.1f} m/s", self.data_processor.format_wind_direction(weather['wind'].get('deg')))
st.metric("Humidity", f"{weather['main']['humidity']}%")
if st.button("Remove", key=f"remove_{loc_name}"):
del st.session_state.comparison_locations_data[loc_name]
st.rerun()
def render_alerts_view(self):
"""Render the weather alerts view."""
st.markdown("## 🚨 Weather Alerts")
if not st.session_state.get('location_data'):
st.info("Search for a location to check for active weather alerts.")
return
with st.spinner("Checking for weather alerts..."):
lat = st.session_state.location_data['lat']
lon = st.session_state.location_data['lon']
alerts = self.weather_api.get_weather_alerts_advanced(lat, lon)
if not alerts:
st.success("✅ No active weather alerts for the selected location.")
return
for alert in alerts:
severity = alert.get('severity_level', 'medium')
if severity in ['extreme', 'high']:
st.error(f"**{alert['event']}** from {alert['sender_name']}")
elif severity == 'medium':
st.warning(f"**{alert['event']}** from {alert['sender_name']}")
else:
st.info(f"**{alert['event']}** from {alert['sender_name']}")
def render_historical_view(self):
"""Render the historical weather data view."""
st.markdown("## 📈 Historical Data")
if not st.session_state.get('location_data'):
st.info("Search for a location to look up historical weather data.")
return
st.warning("📜 Accessing historical data may require a premium API subscription.")
today = datetime.now()
selected_date = st.date_input("Select a date", today, max_value=today)
if st.button("Fetch Historical Weather"):
with st.spinner(f"Fetching weather data for {selected_date.strftime('%Y-%m-%d')}..."):
lat = st.session_state.location_data['lat']
lon = st.session_state.location_data['lon']
historical_data = self.weather_api.get_historical_weather_advanced(lat, lon, selected_date)
if historical_data and 'current' in historical_data:
st.success(f"Data for {selected_date.strftime('%Y-%m-%d')} loaded.")
data = historical_data['current']
st.markdown(f"### Weather on {data['date_info']['target_date']}")
cols = st.columns(3)
cols[0].metric("Temperature", f"{data['temp']:.1f}°C", f"Feels like {data['feels_like']:.1f}°C")
cols[1].metric("Condition", data['weather'][0]['description'].title())
cols[2].metric("Wind Speed", f"{data['wind_speed']:.1f} m/s")
else:
st.error("Could not retrieve historical data. This may be a premium feature not available on your API key.")
def render_current_weather_widget(self):
"""Render a detailed widget for current conditions."""
st.markdown("#### ⚡ Current Conditions")
if st.session_state.get('weather_data'):
weather = st.session_state.weather_data
cols = st.columns(2)
cols[0].metric("Humidity", f"{weather['main']['humidity']}%")
cols[0].metric("Pressure", f"{weather['main']['pressure']} hPa")
cols[1].metric("Visibility", f"{weather.get('visibility', 10000) / 1000:.1f} km")
cols[1].metric("Cloud Cover", f"{weather['clouds']['all']}%")
else:
st.write("No data available.")
def render_hourly_forecast_widget(self):
"""Render a widget with a 24-hour forecast chart."""
st.markdown("#### 🕒 24-Hour Forecast")
if st.session_state.get('hourly_data'):
hourly_data = st.session_state.hourly_data[:24]
fig = go.Figure()
fig.add_trace(go.Scatter(x=[h['time'] for h in hourly_data], y=[h['temp'] for h in hourly_data], name='Temperature', mode='lines+markers', line=dict(color='var(--primary)')))
fig.update_layout(template="plotly_dark", plot_bgcolor='rgba(0,0,0,0)', paper_bgcolor='rgba(0,0,0,0)', height=200, margin=dict(l=0, r=0, t=0, b=0), xaxis=dict(showticklabels=False), yaxis=dict(showticklabels=False))
st.plotly_chart(fig, use_container_width=True)
else:
st.write("No data available.")
def render_weekly_forecast_widget(self):
"""Render a compact 7-day forecast widget."""
st.markdown("#### 🗓️ 7-Day Forecast")
if st.session_state.get('processed_forecast_data'):
forecast = st.session_state.processed_forecast_data
for day in forecast:
cols = st.columns([1, 2, 1])
with cols[0]:
st.write(day['day'])
with cols[1]:
st.image(f"http://openweathermap.org/img/wn/{day['icon']}.png", width=32)
with cols[2]:
st.write(f"{day['temp_max']:.0f}°/{day['temp_min']:.0f}°")
else:
st.write("No data available.")
def render_air_quality_widget(self):
"""Render an AQI widget."""
st.markdown("#### 🌬️ Air Quality")
aqi_full_data = st.session_state.get('air_quality_data')
if aqi_full_data and 'list' in aqi_full_data and aqi_full_data['list']:
aqi_data = aqi_full_data['list'][0]
aqi = aqi_data['main']['aqi']
level_info = self.weather_api._get_aqi_health_info(aqi)
level = level_info['level']
color_map = {'Good': '#10b981', 'Fair': '#f59e0b', 'Moderate': '#f97316', 'Poor': '#ef4444', 'Very Poor': '#dc2626'}
st.markdown(self.ui.create_aqi_indicator(aqi, level, color_map.get(level, '#f97316')), unsafe_allow_html=True)
else:
st.write("No air quality data available.")
def render_uv_index_widget(self):
"""Render a widget for UV index."""
st.markdown("#### ☀️ UV Index & Solar")
if st.session_state.get('weather_data'):
weather = st.session_state.weather_data
sunrise = datetime.fromtimestamp(weather['sys']['sunrise']).strftime('%H:%M')
sunset = datetime.fromtimestamp(weather['sys']['sunset']).strftime('%H:%M')
st.metric("Sunrise", sunrise)
st.metric("Sunset", sunset)
else:
st.write("No data available.")
def render_pressure_trends_widget(self):
"""Render a widget for atmospheric pressure trends."""
st.markdown("#### 📈 Atmospheric Pressure")
if st.session_state.get('processed_forecast_data'):
pressure_data = [d['pressure_avg'] for d in st.session_state.processed_forecast_data]
fig = go.Figure()
fig.add_trace(go.Scatter(y=pressure_data, mode='lines', line=dict(color='var(--accent)')))
fig.update_layout(template="plotly_dark", plot_bgcolor='rgba(0,0,0,0)', paper_bgcolor='rgba(0,0,0,0)', height=150, margin=dict(l=0, r=0, t=0, b=0), xaxis=dict(showticklabels=False), yaxis=dict(showticklabels=False))
st.plotly_chart(fig, use_container_width=True)
else:
st.write("No data available.")
def render_wind_analysis_widget(self):
"""Render a widget for wind conditions."""
st.markdown("#### 💨 Wind Conditions")
if st.session_state.get('weather_data'):
wind = st.session_state.weather_data['wind']
st.metric("Wind Speed", f"{wind['speed']:.1f} m/s")
st.metric("Direction", self.data_processor.format_wind_direction(wind.get('deg')))
if 'gust' in wind:
st.metric("Gusts", f"{wind['gust']:.1f} m/s")
else: