Refactor layout to improve mobile-friendliness and simplify code structure
Browse files
app.py
CHANGED
@@ -36,70 +36,66 @@ def main():
|
|
36 |
# Detect user's local time zone
|
37 |
local_timezone = datetime.now().astimezone().tzinfo
|
38 |
|
39 |
-
# Coordinates and time input
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
if map_data and 'last_clicked' in map_data and map_data['last_clicked']:
|
64 |
-
latitude = map_data['last_clicked']['lat']
|
65 |
-
longitude = map_data['last_clicked']['lng']
|
66 |
|
67 |
-
|
68 |
-
|
69 |
-
longitude = st.text_input("Longitude:", value=str(longitude) if 'longitude' in locals() else "")
|
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 |
# Align the table with the button
|
105 |
if compute_button:
|
|
|
36 |
# Detect user's local time zone
|
37 |
local_timezone = datetime.now().astimezone().tzinfo
|
38 |
|
39 |
+
# Coordinates and time input - Default to mobile-friendly single-column layout
|
40 |
+
use_address = st.checkbox("Use Address to Set Location", value=False)
|
41 |
+
if use_address:
|
42 |
+
address = st.text_input("Enter Your Address:")
|
43 |
+
if address:
|
44 |
+
geolocator = Nominatim(user_agent="satellite-observation-app")
|
45 |
+
try:
|
46 |
+
location = geolocator.geocode(address, timeout=10)
|
47 |
+
if location:
|
48 |
+
latitude = location.latitude
|
49 |
+
longitude = location.longitude
|
50 |
+
else:
|
51 |
+
st.write("Could not find the location. Please enter a valid address.")
|
52 |
+
except Exception as e:
|
53 |
+
st.error(f"Error fetching location data: {str(e)}")
|
54 |
+
else:
|
55 |
+
st.write("Select your location on the map:")
|
56 |
+
default_location = [37.7749, -122.4194]
|
57 |
+
map_display = folium.Map(location=default_location, zoom_start=2)
|
58 |
+
folium.Marker(default_location, tooltip="Default Location").add_to(map_display)
|
59 |
+
map_data = st_folium(map_display, width=350, height=300)
|
60 |
+
if map_data and 'last_clicked' in map_data and map_data['last_clicked']:
|
61 |
+
latitude = map_data['last_clicked']['lat']
|
62 |
+
longitude = map_data['last_clicked']['lng']
|
|
|
|
|
|
|
63 |
|
64 |
+
latitude = st.text_input("Latitude:", value=str(latitude) if 'latitude' in locals() else "")
|
65 |
+
longitude = st.text_input("Longitude:", value=str(longitude) if 'longitude' in locals() else "")
|
|
|
66 |
|
67 |
+
# Determine time zone from GPS coordinates
|
68 |
+
if latitude and longitude:
|
69 |
+
try:
|
70 |
+
tf = TimezoneFinder()
|
71 |
+
timezone_str = tf.timezone_at(lng=float(longitude), lat=float(latitude))
|
72 |
+
timezone = pytz.timezone(timezone_str)
|
73 |
+
current_time = datetime.now()
|
74 |
+
timezone_abbr = get_abbreviated_timezone(timezone_str, current_time)
|
75 |
+
st.write(f"Detected Time Zone: {timezone_str} ({timezone_abbr})")
|
76 |
+
except Exception as e:
|
77 |
+
st.error(f"Error determining timezone: {str(e)}")
|
78 |
+
timezone = local_timezone
|
79 |
+
else:
|
80 |
+
timezone = local_timezone
|
81 |
+
timezone_str = str(timezone)
|
82 |
+
timezone_abbr = timezone.tzname(datetime.now())
|
83 |
+
st.write(f"Using local time zone: {timezone} ({timezone_abbr})")
|
84 |
|
85 |
+
start_date_local = st.date_input("Start Date (Local Time):")
|
86 |
+
start_time_local = st.time_input("Start Time (Local Time):")
|
87 |
+
end_time_local = st.time_input("End Time (Local Time):")
|
88 |
|
89 |
+
# Convert local time to UTC
|
90 |
+
start_datetime_local = datetime.combine(start_date_local, start_time_local)
|
91 |
+
end_datetime_local = datetime.combine(start_date_local, end_time_local)
|
92 |
+
start_datetime_utc = start_datetime_local.astimezone(pytz.utc)
|
93 |
+
end_datetime_utc = end_datetime_local.astimezone(pytz.utc)
|
94 |
|
95 |
+
st.write(f"Start Time in UTC: {start_datetime_utc.strftime('%Y-%m-%d %H:%M:%S')}")
|
96 |
+
st.write(f"End Time in UTC: {end_datetime_utc.strftime('%Y-%m-%d %H:%M:%S')}")
|
97 |
|
98 |
+
compute_button = st.button("Compute Satellite Positions")
|
99 |
|
100 |
# Align the table with the button
|
101 |
if compute_button:
|