-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added fastapi and connected danger zones to frontend
- Loading branch information
1 parent
a36ae3a
commit 0cfeabc
Showing
10 changed files
with
214 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
from fastapi import FastAPI, status, Request | ||
from fastapi.middleware.cors import CORSMiddleware | ||
from pydantic import BaseModel | ||
from redis_lib import create_redis_client, add_geospatial_point, find_geospatial_points_within_radius | ||
|
||
|
||
# Create the Redis client | ||
r = create_redis_client( | ||
host_url = env.host_url, | ||
host_password = env.host_password | ||
) | ||
|
||
# Get number of nearest neighbours functionality | ||
def get_number_risk_points(latitude, longitude): | ||
latitude = float(latitude) | ||
longitude = float(longitude) | ||
|
||
points = find_geospatial_points_within_radius(r, latitude, longitude, radius = 1000, collection_name="geoparky") | ||
return len(points) | ||
|
||
|
||
app = FastAPI() | ||
|
||
origins = ["*"] | ||
|
||
app.add_middleware( | ||
CORSMiddleware, | ||
allow_origins=origins, | ||
allow_credentials=True, | ||
allow_methods=["*"], | ||
allow_headers=["*"], | ||
) | ||
|
||
|
||
@app.get("/") | ||
async def root(): | ||
return {"message": "Hello World"} | ||
|
||
|
||
|
||
# Nearest points' route | ||
@app.post('/nearby') | ||
async def nearby_points(request: Request): | ||
global r | ||
|
||
input_json = await request.json() | ||
latitude = str(input_json["latitude"]) | ||
longitude = str(input_json["longitude"]) | ||
|
||
num_points = get_number_risk_points(latitude, longitude) | ||
response = { | ||
"latitude" : latitude, | ||
"longitude" : longitude, | ||
"points" : num_points | ||
} | ||
return response |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
home = C:\Python310 | ||
implementation = CPython | ||
version_info = 3.10.0.final.0 | ||
virtualenv = 20.24.5 | ||
include-system-site-packages = false | ||
base-prefix = C:\Python310 | ||
base-exec-prefix = C:\Python310 | ||
base-executable = C:\Python310\python.exe |
Oops, something went wrong.