Spaces:
Sleeping
Sleeping
fschwartzer
commited on
Commit
•
ff1b036
1
Parent(s):
81d3eef
Update app.py
Browse files
app.py
CHANGED
@@ -55,11 +55,11 @@ st.markdown(
|
|
55 |
data = pd.read_excel('ven_ter_fim_PEDÓ.xlsx')
|
56 |
|
57 |
# Initialize variables to avoid NameError
|
58 |
-
selected_coords = '
|
59 |
radius_visible = True
|
60 |
custom_address_initial = 'Av. Senador Alberto Pasqualini, 177 - Centro, Lajeado - RS, 95900-034' # Initial custom address
|
61 |
-
custom_lat = data['latitude'].
|
62 |
-
custom_lon = data['longitude'].
|
63 |
radius_in_meters = 1500
|
64 |
filtered_data = data # Initialize with the entire dataset
|
65 |
|
@@ -71,15 +71,15 @@ for index, row in data.iterrows():
|
|
71 |
max_distance = distance
|
72 |
|
73 |
# Calculate a zoom level based on the maximum distance
|
74 |
-
zoom_level = round(
|
75 |
|
76 |
# Create a sidebar for controls
|
77 |
with st.sidebar:
|
78 |
st.title('avalia.se')
|
79 |
|
80 |
-
selected_coords = st.selectbox('Selecione
|
81 |
|
82 |
-
if selected_coords == '
|
83 |
custom_address = st.text_input('Informe o endereço', custom_address_initial)
|
84 |
radius_visible = True # Show radius slider for custom coordinates
|
85 |
# No need to initialize max_distance_all here
|
@@ -100,7 +100,7 @@ with st.sidebar:
|
|
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 == '
|
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():
|
@@ -119,7 +119,7 @@ with st.sidebar:
|
|
119 |
radius_in_meters = st.slider('Selecione raio (em metros)', min_value=100, max_value=5000, value=1000)
|
120 |
|
121 |
# Filter data based on the radius
|
122 |
-
if selected_coords == '
|
123 |
filtered_data = data[data.apply(lambda x: calculate_distance(x['latitude'], x['longitude'], custom_lat, custom_lon), axis=1) <= radius_in_meters]
|
124 |
filtered_data = filtered_data.dropna() # Drop rows with NaN values
|
125 |
|
@@ -132,7 +132,7 @@ st.markdown(f"""<style>
|
|
132 |
</style>""", unsafe_allow_html=True)
|
133 |
|
134 |
# Check if KNN should be applied
|
135 |
-
if selected_coords == '
|
136 |
# Apply KNN and get predicted Vunit values
|
137 |
predicted_vunit = knn_predict(filtered_data, 'Vunit', ['latitude', 'longitude', 'Area']) # Update with your features
|
138 |
# Add predicted Vunit values to filtered_data
|
@@ -140,9 +140,9 @@ if selected_coords == 'Custom' and radius_visible:
|
|
140 |
|
141 |
# Display the map and filtered_data
|
142 |
with st.container():
|
143 |
-
if selected_coords == '
|
144 |
st.map(filtered_data, zoom=zoom_level, use_container_width=True)
|
145 |
-
elif selected_coords == '
|
146 |
st.map(data, zoom=zoom_level, use_container_width=True)
|
147 |
|
148 |
# Display the predicted Vunit values if applicable
|
|
|
55 |
data = pd.read_excel('ven_ter_fim_PEDÓ.xlsx')
|
56 |
|
57 |
# Initialize variables to avoid NameError
|
58 |
+
selected_coords = 'Direcionada'
|
59 |
radius_visible = True
|
60 |
custom_address_initial = 'Av. Senador Alberto Pasqualini, 177 - Centro, Lajeado - RS, 95900-034' # Initial custom address
|
61 |
+
custom_lat = data['latitude'].median()
|
62 |
+
custom_lon = data['longitude'].median()
|
63 |
radius_in_meters = 1500
|
64 |
filtered_data = data # Initialize with the entire dataset
|
65 |
|
|
|
71 |
max_distance = distance
|
72 |
|
73 |
# Calculate a zoom level based on the maximum distance
|
74 |
+
zoom_level = round(16 - np.log10(max_distance))
|
75 |
|
76 |
# Create a sidebar for controls
|
77 |
with st.sidebar:
|
78 |
st.title('avalia.se')
|
79 |
|
80 |
+
selected_coords = st.selectbox('Selecione o tipo de pesquisa', ['Ampla', 'Direcionada'])
|
81 |
|
82 |
+
if selected_coords == 'Direcionada':
|
83 |
custom_address = st.text_input('Informe o endereço', custom_address_initial)
|
84 |
radius_visible = True # Show radius slider for custom coordinates
|
85 |
# No need to initialize max_distance_all here
|
|
|
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 == 'Direcionada':
|
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():
|
|
|
119 |
radius_in_meters = st.slider('Selecione raio (em metros)', min_value=100, max_value=5000, value=1000)
|
120 |
|
121 |
# Filter data based on the radius
|
122 |
+
if selected_coords == 'Direcionada':
|
123 |
filtered_data = data[data.apply(lambda x: calculate_distance(x['latitude'], x['longitude'], custom_lat, custom_lon), axis=1) <= radius_in_meters]
|
124 |
filtered_data = filtered_data.dropna() # Drop rows with NaN values
|
125 |
|
|
|
132 |
</style>""", unsafe_allow_html=True)
|
133 |
|
134 |
# Check if KNN should be applied
|
135 |
+
if selected_coords == 'Direcionada' and radius_visible:
|
136 |
# Apply KNN and get predicted Vunit values
|
137 |
predicted_vunit = knn_predict(filtered_data, 'Vunit', ['latitude', 'longitude', 'Area']) # Update with your features
|
138 |
# Add predicted Vunit values to filtered_data
|
|
|
140 |
|
141 |
# Display the map and filtered_data
|
142 |
with st.container():
|
143 |
+
if selected_coords == 'Direcionada':
|
144 |
st.map(filtered_data, zoom=zoom_level, use_container_width=True)
|
145 |
+
elif selected_coords == 'Ampla':
|
146 |
st.map(data, zoom=zoom_level, use_container_width=True)
|
147 |
|
148 |
# Display the predicted Vunit values if applicable
|