def depthWellAdvanced(user_lat, user_lon, thresh):
def create_well_recommendation_map(
user_latitude, user_longitude, threshold_distance=float(thresh)
):
file_path = "/home/varad2004/mysite/dugwell.csv"
df = pd.read_csv(file_path)
df = df.dropna(subset=["Y", "X", "Depth (m.bgl)", "Well Type"])
X = df[["Y", "X"]]
y_depth = df["Depth (m.bgl)"]
y_well_type = df["Well Type"]
depth_model = KNeighborsRegressor(n_neighbors=3)
depth_model.fit(X, y_depth)
well_type_model = KNeighborsClassifier(n_neighbors=3)
well_type_model.fit(X, y_well_type)
def recommend_well_and_nearest(user_lat, user_lon):
user_location = [[user_lat, user_lon]]
nearest_dugwell_index = depth_model.kneighbors(user_location)[1][0][0]
nearest_dugwell_coordinates = X.iloc[nearest_dugwell_index]
nearest_dugwell_depth = y_depth.iloc[nearest_dugwell_index]
nearest_dugwell_well_type = y_well_type.iloc[nearest_dugwell_index]
distance_to_nearest_dugwell = geodesic(
user_location[0], nearest_dugwell_coordinates
).kilometers
if distance_to_nearest_dugwell > threshold_distance:
return f"No suitable well within {threshold_distance} km.", None, None
return (
nearest_dugwell_depth,
nearest_dugwell_well_type,
nearest_dugwell_coordinates,
)
map_center = [user_latitude, user_longitude]
map_object = folium.Map(location=map_center, zoom_start=12)
recommendation_result = recommend_well_and_nearest(
user_latitude, user_longitude
)
recommended_depth, recommended_well_type, recommended_coordinates = (
recommendation_result
)
if (
isinstance(recommended_well_type, str)
and recommended_well_type != "No suitable well within 3 km."
):
folium.Marker(
location=[user_latitude, user_longitude],
popup=f"Recommended Depth: {recommended_depth} meters, Recommended Well Type: {recommended_well_type}",
icon=folium.Icon(color="red"),
).add_to(map_object)
folium.Marker(
location=[recommended_coordinates["Y"], recommended_coordinates["X"]],
popup=f"Nearest Well - Depth: {recommended_depth} meters, Well Type: {recommended_well_type}",
icon=folium.Icon(color="green"),
).add_to(map_object)
else:
folium.Marker(
location=[user_latitude, user_longitude],
popup="No suitable well within 3 km.",
icon=folium.Icon(color="gray"),
).add_to(map_object)
return map_object, recommended_depth, recommended_well_type
user_latitude = user_lat
user_longitude = user_lon
map_object, recommended_depth, recommended_well_type = (
create_well_recommendation_map(user_latitude, user_longitude)
)
print(f"Recommended Depth: {recommended_depth} meters")
print(f"Recommended Well Type: {recommended_well_type}")
map_object.save("well_recommendation_map.html")
with open("well_recommendation_map.html", "r") as file:
html_content = file.read()
result = {
"depth": f"{recommended_depth}",
"well_type": f"{recommended_well_type}",
"html_content": f"{html_content}",
}
return result
I am trying to get the file dugwell.csv but getting an error File does not exist.
My mysite directory contains these files
Aquifer_data_Cuddalore.xlsx
Modified_Water_Quality_Shuffled.csv
Transmisivitty.xlsx
UpdatedWaterQuality.csv
dugwell.csv
flask_app.py