fschwartzer commited on
Commit
81d3eef
1 Parent(s): b28d669

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -22
app.py CHANGED
@@ -62,7 +62,6 @@ custom_lat = data['latitude'].mean()
62
  custom_lon = data['longitude'].mean()
63
  radius_in_meters = 1500
64
  filtered_data = data # Initialize with the entire dataset
65
- zoom_level = 12
66
 
67
  # Find the maximum distance between coordinates
68
  max_distance = 0
@@ -71,6 +70,9 @@ for index, row in data.iterrows():
71
  if distance > max_distance:
72
  max_distance = distance
73
 
 
 
 
74
  # Create a sidebar for controls
75
  with st.sidebar:
76
  st.title('avalia.se')
@@ -86,24 +88,7 @@ with st.sidebar:
86
  radius_visible = False # Hide radius slider for random coordinates
87
  max_distance_all = 0 # Initialize max_distance_all here
88
 
89
- # Slider for setting the radius
90
- if radius_visible:
91
- radius_in_meters = st.slider('Selecione raio (em metros)', min_value=100, max_value=5000, value=1000)
92
-
93
- # Calculate a zoom level based on the radius
94
- radius_zoom_mapping = {
95
- 500: 15,
96
- 1000: 14,
97
- 2000: 13,
98
- 4000: 12,
99
- 5000: 11
100
- }
101
-
102
- # Find the closest radius in the mapping
103
- closest_radius = min(radius_zoom_mapping.keys(), key=lambda x: abs(x - radius_in_meters))
104
-
105
- # Set the zoom level based on the mapping
106
- zoom_level = radius_zoom_mapping[closest_radius]
107
 
108
  # Geocode the custom address using the Google Maps API
109
  gmaps = googlemaps.Client(key='AIzaSyDoJ6C7NE2CHqFcaHTnhreOfgJeTk4uSH0') # Replace with your API key
@@ -115,9 +100,8 @@ if radius_visible:
115
  st.error("Erro: Não foi possível geocodificar o endereço fornecido. Por favor, verifique e tente novamente.")
116
 
117
  # Slider for setting the zoom level
118
- if selected_coords == 'Custom' and not radius_visible:
119
- # Use the zoom level slider based on the entire dataset
120
- zoom_level = st.slider('Nível de zoom', min_value=1, max_value=15, value=zoom_level_all)
121
  else:
122
  for index, row in data.iterrows():
123
  distance_all = calculate_distance(row['latitude'], row['longitude'], data['latitude'].mean(), data['longitude'].mean())
 
62
  custom_lon = data['longitude'].mean()
63
  radius_in_meters = 1500
64
  filtered_data = data # Initialize with the entire dataset
 
65
 
66
  # Find the maximum distance between coordinates
67
  max_distance = 0
 
70
  if distance > max_distance:
71
  max_distance = distance
72
 
73
+ # Calculate a zoom level based on the maximum distance
74
+ zoom_level = round(15 - np.log10(max_distance))
75
+
76
  # Create a sidebar for controls
77
  with st.sidebar:
78
  st.title('avalia.se')
 
88
  radius_visible = False # Hide radius slider for random coordinates
89
  max_distance_all = 0 # Initialize max_distance_all here
90
 
91
+ max_distance_all = 0 # Initialize max_distance_all here
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
 
93
  # Geocode the custom address using the Google Maps API
94
  gmaps = googlemaps.Client(key='AIzaSyDoJ6C7NE2CHqFcaHTnhreOfgJeTk4uSH0') # Replace with your API key
 
100
  st.error("Erro: Não foi possível geocodificar o endereço fornecido. Por favor, verifique e tente novamente.")
101
 
102
  # Slider for setting the zoom level
103
+ if selected_coords == 'Custom':
104
+ zoom_level = st.slider('Nível de zoom', min_value=1, max_value=15, value=zoom_level)
 
105
  else:
106
  for index, row in data.iterrows():
107
  distance_all = calculate_distance(row['latitude'], row['longitude'], data['latitude'].mean(), data['longitude'].mean())