fschwartzer commited on
Commit
7f3d9d9
·
1 Parent(s): 6262455

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -21
app.py CHANGED
@@ -70,22 +70,6 @@ for index, row in data.iterrows():
70
  if distance > max_distance:
71
  max_distance = distance
72
 
73
- # Calculate a zoom level based on the radius
74
- if radius_visible:
75
- radius_zoom_mapping = {
76
- 500: 15,
77
- 1000: 14,
78
- 2000: 13,
79
- 4000: 12,
80
- 5000: 11
81
- }
82
-
83
- # Find the closest radius in the mapping
84
- closest_radius = min(radius_zoom_mapping.keys(), key=lambda x: abs(x - radius_in_meters))
85
-
86
- # Set the zoom level based on the mapping
87
- zoom_level = radius_zoom_mapping[closest_radius]
88
-
89
  # Create a sidebar for controls
90
  with st.sidebar:
91
  st.title('avalia.se')
@@ -101,7 +85,24 @@ with st.sidebar:
101
  radius_visible = False # Hide radius slider for random coordinates
102
  max_distance_all = 0 # Initialize max_distance_all here
103
 
104
- max_distance_all = 0 # Initialize max_distance_all here
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
  # Geocode the custom address using the Google Maps API
107
  gmaps = googlemaps.Client(key='AIzaSyDoJ6C7NE2CHqFcaHTnhreOfgJeTk4uSH0') # Replace with your API key
@@ -113,9 +114,9 @@ with st.sidebar:
113
  st.error("Erro: Não foi possível geocodificar o endereço fornecido. Por favor, verifique e tente novamente.")
114
 
115
  # Slider for setting the zoom level
116
- if selected_coords == 'Custom':
117
- # The zoom level slider is no longer needed if radius is used for zoom adjustment
118
- st.markdown("O nível de zoom é ajustado automaticamente com base no raio.")
119
  else:
120
  for index, row in data.iterrows():
121
  distance_all = calculate_distance(row['latitude'], row['longitude'], data['latitude'].mean(), data['longitude'].mean())
@@ -152,7 +153,7 @@ if selected_coords == 'Custom' and radius_visible:
152
  # Add predicted Vunit values to filtered_data
153
  filtered_data['Predicted_Vunit'] = predicted_vunit
154
 
155
- # Display the map and filtered_data
156
  with st.container():
157
  if selected_coords == 'Custom':
158
  st.map(filtered_data, zoom=zoom_level, use_container_width=True)
 
70
  if distance > max_distance:
71
  max_distance = distance
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
  # Create a sidebar for controls
74
  with st.sidebar:
75
  st.title('avalia.se')
 
85
  radius_visible = False # Hide radius slider for random coordinates
86
  max_distance_all = 0 # Initialize max_distance_all here
87
 
88
+ # Slider for setting the radius
89
+ if radius_visible:
90
+ radius_in_meters = st.slider('Selecione raio (em metros)', min_value=100, max_value=5000, value=1000)
91
+
92
+ # Calculate a zoom level based on the radius
93
+ radius_zoom_mapping = {
94
+ 500: 15,
95
+ 1000: 14,
96
+ 2000: 13,
97
+ 4000: 12,
98
+ 5000: 11
99
+ }
100
+
101
+ # Find the closest radius in the mapping
102
+ closest_radius = min(radius_zoom_mapping.keys(), key=lambda x: abs(x - radius_in_meters))
103
+
104
+ # Set the zoom level based on the mapping
105
+ zoom_level = radius_zoom_mapping[closest_radius]
106
 
107
  # Geocode the custom address using the Google Maps API
108
  gmaps = googlemaps.Client(key='AIzaSyDoJ6C7NE2CHqFcaHTnhreOfgJeTk4uSH0') # Replace with your API key
 
114
  st.error("Erro: Não foi possível geocodificar o endereço fornecido. Por favor, verifique e tente novamente.")
115
 
116
  # Slider for setting the zoom level
117
+ if selected_coords == 'Custom' and not radius_visible:
118
+ # Use the zoom level slider based on the entire dataset
119
+ zoom_level = st.slider('Nível de zoom', min_value=1, max_value=15, value=zoom_level_all)
120
  else:
121
  for index, row in data.iterrows():
122
  distance_all = calculate_distance(row['latitude'], row['longitude'], data['latitude'].mean(), data['longitude'].mean())
 
153
  # Add predicted Vunit values to filtered_data
154
  filtered_data['Predicted_Vunit'] = predicted_vunit
155
 
156
+ Display the map and filtered_data
157
  with st.container():
158
  if selected_coords == 'Custom':
159
  st.map(filtered_data, zoom=zoom_level, use_container_width=True)