JulsdL commited on
Commit
67d590e
·
1 Parent(s): 0587a5f

Refactor layout to improve mobile-friendliness and simplify code structure

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