From 7bebd53d32f16e4cfa12043db1e01ced32de0471 Mon Sep 17 00:00:00 2001 From: Eli Lucherini Date: Sun, 22 Dec 2024 20:18:32 -0800 Subject: [PATCH 1/8] Add .vscode to .gitignore for now --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 749b65de..19ca899a 100644 --- a/.gitignore +++ b/.gitignore @@ -23,4 +23,7 @@ node_modules # Sensitive config .env.development.local .env -.env.local \ No newline at end of file +.env.local + +# IDEs +.vscode/ \ No newline at end of file From dbcfb1efdc435fac12f482ae3de953332eb21d6a Mon Sep 17 00:00:00 2001 From: Eli Lucherini Date: Sun, 22 Dec 2024 20:26:51 -0800 Subject: [PATCH 2/8] Soft story --- backend/api/routers/soft_story_api.py | 20 ++++++++++++++++++++ backend/api/tests/test_soft_story.py | 13 ++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/backend/api/routers/soft_story_api.py b/backend/api/routers/soft_story_api.py index deeafa90..cbced4d3 100644 --- a/backend/api/routers/soft_story_api.py +++ b/backend/api/routers/soft_story_api.py @@ -4,6 +4,7 @@ from ..tags import Tags from sqlalchemy.orm import Session from backend.database.session import get_db +from geoalchemy2 import functions as geo_func from backend.api.schemas.soft_story_schemas import ( SoftStoryFeature, SoftStoryFeatureCollection, @@ -39,3 +40,22 @@ async def get_soft_stories(db: Session = Depends(get_db)): features = [SoftStoryFeature.from_sqlalchemy_model(story) for story in soft_stories] return SoftStoryFeatureCollection(type="FeatureCollection", features=features) + + +@router.get("/is-soft-story", response_model=bool) +async def is_soft_story(lat: float, lon: float, db: Session = Depends(get_db)): + """ + Check if a point is a soft story property. + + Args: + lat (float): Latitude of the point. + lon (float): Longitude of the point. + db (Session): The database session dependency. + + Returns: + bool: True if the point is a soft story property, False otherwise. + """ + query = db.query(SoftStoryProperty).filter( + SoftStoryProperty.point == geo_func.ST_GeomFromText(f"POINT({lon} {lat})",4326) + ) + return db.query(query.exists()).scalar() \ No newline at end of file diff --git a/backend/api/tests/test_soft_story.py b/backend/api/tests/test_soft_story.py index 2f9591d6..87cb59c2 100644 --- a/backend/api/tests/test_soft_story.py +++ b/backend/api/tests/test_soft_story.py @@ -7,7 +7,6 @@ # Will the .. be stable? from ..main import app -from ..schemas.geo import Polygon @pytest.fixture @@ -41,3 +40,15 @@ def test_get_soft_story(client): assert response.status_code == 200 # Temporary guaranteed failure until test is written assert False + +def test_is_soft_story(client): + lat, lon = [-122.446575165, 37.766034349] + response = client.get(f"/api/soft-story/is-soft-story?lat={lat}&lon={lon}") + assert response.status_code == 200 + assert response.json() # True + + # These should not be soft stories + wrong_lat, wrong_lon = [0.0, 0.0] + response = client.get(f"/api/soft-story/is-soft-story?lat={wrong_lat}&lon={wrong_lon}") + assert response.status_code == 200 + assert not response.json() # False \ No newline at end of file From e811d510cecde7b8c9c13bfbc10b3da1bfaa530b Mon Sep 17 00:00:00 2001 From: Eli Lucherini Date: Sun, 22 Dec 2024 21:04:35 -0800 Subject: [PATCH 3/8] Liq and tsunami --- backend/api/routers/liquefaction_api.py | 21 +++++++++++++++++++++ backend/api/routers/tsunami_api.py | 21 +++++++++++++++++++++ backend/api/tests/test_liquefaction.py | 0 backend/api/tests/test_tsunami.py | 14 ++++++++++---- 4 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 backend/api/tests/test_liquefaction.py diff --git a/backend/api/routers/liquefaction_api.py b/backend/api/routers/liquefaction_api.py index 6d30c710..5d3b208e 100644 --- a/backend/api/routers/liquefaction_api.py +++ b/backend/api/routers/liquefaction_api.py @@ -3,6 +3,7 @@ from fastapi import Depends, HTTPException, APIRouter from ..tags import Tags from sqlalchemy.orm import Session +from geoalchemy2 import functions as geo_func from backend.database.session import get_db from ..schemas.liquefaction_schemas import ( LiquefactionFeature, @@ -41,3 +42,23 @@ async def get_liquefaction_zones(db: Session = Depends(get_db)): LiquefactionFeature.from_sqlalchemy_model(zone) for zone in liquefaction_zones ] return LiquefactionFeatureCollection(type="FeatureCollection", features=features) + + +@router.get("/is-in-liquefaction-zone", response_model=bool) +async def is_in_liquefaction_zone(lat: float, lon: float, db: Session = Depends(get_db)): + """ + Check if a point is in a liquefaction zone. + + Args: + lat (float): Latitude of the point. + lon (float): Longitude of the point. + db (Session): The database session dependency. + + Returns: + bool: True if the point is in a liquefaction zone, False otherwise. + """ + query = db.query(LiquefactionZone).filter( + LiquefactionZone.geometry.ST_Contains( + geo_func.ST_SetSRID(geo_func.ST_GeomFromText(f"POINT({lon} {lat})"), 4326)) + ) + return db.query(query.exists()).scalar() \ No newline at end of file diff --git a/backend/api/routers/tsunami_api.py b/backend/api/routers/tsunami_api.py index 25c06907..394e9d03 100644 --- a/backend/api/routers/tsunami_api.py +++ b/backend/api/routers/tsunami_api.py @@ -3,6 +3,7 @@ from fastapi import Depends, HTTPException, APIRouter from ..tags import Tags from sqlalchemy.orm import Session +from geoalchemy2 import functions as geo_func from backend.database.session import get_db from backend.api.schemas.tsunami_schemas import TsunamiFeature, TsunamiFeatureCollection from backend.api.models.tsunami import TsunamiZone @@ -38,3 +39,23 @@ async def get_tsunami_zones(db: Session = Depends(get_db)): raise HTTPException(status_code=404, detail="No tsunami zones found") features = [TsunamiFeature.from_sqlalchemy_model(zone) for zone in tsunami_zones] return TsunamiFeatureCollection(type="FeatureCollection", features=features) + + +@router.get("/is-in-tsunami-zone", response_model=bool) +async def is_in_tsunami_zone(lat: float, lon: float, db: Session = Depends(get_db)): + """ + Check if a point is in a tsunami zone. + + Args: + lat (float): Latitude of the point. + lon (float): Longitude of the point. + db (Session): The database session dependency. + + Returns: + bool: True if the point is in a tsunami zone, False otherwise. + """ + query = db.query(TsunamiZone).filter( + TsunamiZone.geometry.ST_Contains( + geo_func.ST_SetSRID(geo_func.ST_GeomFromText(f"POINT({lon} {lat})"), 4326)) + ) + return db.query(query.exists()).scalar() \ No newline at end of file diff --git a/backend/api/tests/test_liquefaction.py b/backend/api/tests/test_liquefaction.py new file mode 100644 index 00000000..e69de29b diff --git a/backend/api/tests/test_tsunami.py b/backend/api/tests/test_tsunami.py index 14290c5a..e59a04c5 100644 --- a/backend/api/tests/test_tsunami.py +++ b/backend/api/tests/test_tsunami.py @@ -47,8 +47,14 @@ def test_get_tsunami_polygon(client): assert False -def test_get_tsunami_risk(client): - response = client.get("/api/tsunami-risk/addresss") +def test_is_in_tsunami_zone(client): + lat, lon = [37.759039, -122.509515] + response = client.get(f"/api/tsunami/is-in-tsunami-zone?lat={lat}&lon={lon}") assert response.status_code == 200 - # Temporary guaranteed failure until test is written - assert False + assert response.json() # True + + # These should not be in our tsunami zone + wrong_lat, wrong_lon = [0.0, 0.0] + response = client.get(f"/api/tsunami/is-in-tsunami-zone?lat={wrong_lat}&lon={wrong_lon}") + assert response.status_code == 200 + assert not response.json() # False From cf41809b4426c447b3791e2d9388d0d3607ce41f Mon Sep 17 00:00:00 2001 From: Eli Lucherini Date: Sun, 22 Dec 2024 21:08:36 -0800 Subject: [PATCH 4/8] Linting --- backend/api/routers/liquefaction_api.py | 9 ++++++--- backend/api/routers/soft_story_api.py | 8 ++++---- backend/api/routers/tsunami_api.py | 5 +++-- backend/api/tests/test_soft_story.py | 7 +++++-- backend/api/tests/test_tsunami.py | 4 +++- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/backend/api/routers/liquefaction_api.py b/backend/api/routers/liquefaction_api.py index 5d3b208e..2c26e7f7 100644 --- a/backend/api/routers/liquefaction_api.py +++ b/backend/api/routers/liquefaction_api.py @@ -45,7 +45,9 @@ async def get_liquefaction_zones(db: Session = Depends(get_db)): @router.get("/is-in-liquefaction-zone", response_model=bool) -async def is_in_liquefaction_zone(lat: float, lon: float, db: Session = Depends(get_db)): +async def is_in_liquefaction_zone( + lat: float, lon: float, db: Session = Depends(get_db) +): """ Check if a point is in a liquefaction zone. @@ -59,6 +61,7 @@ async def is_in_liquefaction_zone(lat: float, lon: float, db: Session = Depends( """ query = db.query(LiquefactionZone).filter( LiquefactionZone.geometry.ST_Contains( - geo_func.ST_SetSRID(geo_func.ST_GeomFromText(f"POINT({lon} {lat})"), 4326)) + geo_func.ST_SetSRID(geo_func.ST_GeomFromText(f"POINT({lon} {lat})"), 4326) + ) ) - return db.query(query.exists()).scalar() \ No newline at end of file + return db.query(query.exists()).scalar() diff --git a/backend/api/routers/soft_story_api.py b/backend/api/routers/soft_story_api.py index cbced4d3..be004b87 100644 --- a/backend/api/routers/soft_story_api.py +++ b/backend/api/routers/soft_story_api.py @@ -46,16 +46,16 @@ async def get_soft_stories(db: Session = Depends(get_db)): async def is_soft_story(lat: float, lon: float, db: Session = Depends(get_db)): """ Check if a point is a soft story property. - + Args: lat (float): Latitude of the point. lon (float): Longitude of the point. db (Session): The database session dependency. - + Returns: bool: True if the point is a soft story property, False otherwise. """ query = db.query(SoftStoryProperty).filter( - SoftStoryProperty.point == geo_func.ST_GeomFromText(f"POINT({lon} {lat})",4326) + SoftStoryProperty.point == geo_func.ST_GeomFromText(f"POINT({lon} {lat})", 4326) ) - return db.query(query.exists()).scalar() \ No newline at end of file + return db.query(query.exists()).scalar() diff --git a/backend/api/routers/tsunami_api.py b/backend/api/routers/tsunami_api.py index 394e9d03..48dfaea7 100644 --- a/backend/api/routers/tsunami_api.py +++ b/backend/api/routers/tsunami_api.py @@ -56,6 +56,7 @@ async def is_in_tsunami_zone(lat: float, lon: float, db: Session = Depends(get_d """ query = db.query(TsunamiZone).filter( TsunamiZone.geometry.ST_Contains( - geo_func.ST_SetSRID(geo_func.ST_GeomFromText(f"POINT({lon} {lat})"), 4326)) + geo_func.ST_SetSRID(geo_func.ST_GeomFromText(f"POINT({lon} {lat})"), 4326) + ) ) - return db.query(query.exists()).scalar() \ No newline at end of file + return db.query(query.exists()).scalar() diff --git a/backend/api/tests/test_soft_story.py b/backend/api/tests/test_soft_story.py index 87cb59c2..b6d2d906 100644 --- a/backend/api/tests/test_soft_story.py +++ b/backend/api/tests/test_soft_story.py @@ -41,6 +41,7 @@ def test_get_soft_story(client): # Temporary guaranteed failure until test is written assert False + def test_is_soft_story(client): lat, lon = [-122.446575165, 37.766034349] response = client.get(f"/api/soft-story/is-soft-story?lat={lat}&lon={lon}") @@ -49,6 +50,8 @@ def test_is_soft_story(client): # These should not be soft stories wrong_lat, wrong_lon = [0.0, 0.0] - response = client.get(f"/api/soft-story/is-soft-story?lat={wrong_lat}&lon={wrong_lon}") + response = client.get( + f"/api/soft-story/is-soft-story?lat={wrong_lat}&lon={wrong_lon}" + ) assert response.status_code == 200 - assert not response.json() # False \ No newline at end of file + assert not response.json() # False diff --git a/backend/api/tests/test_tsunami.py b/backend/api/tests/test_tsunami.py index e59a04c5..afc73561 100644 --- a/backend/api/tests/test_tsunami.py +++ b/backend/api/tests/test_tsunami.py @@ -55,6 +55,8 @@ def test_is_in_tsunami_zone(client): # These should not be in our tsunami zone wrong_lat, wrong_lon = [0.0, 0.0] - response = client.get(f"/api/tsunami/is-in-tsunami-zone?lat={wrong_lat}&lon={wrong_lon}") + response = client.get( + f"/api/tsunami/is-in-tsunami-zone?lat={wrong_lat}&lon={wrong_lon}" + ) assert response.status_code == 200 assert not response.json() # False From 8346376c60377b61485bfb6c6a98fc0b05b83f65 Mon Sep 17 00:00:00 2001 From: Eli Lucherini Date: Sun, 22 Dec 2024 21:11:03 -0800 Subject: [PATCH 5/8] Added pre_commit to dev requirements --- requirements-dev.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements-dev.txt b/requirements-dev.txt index 53bb077b..4cbcd4dc 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -34,6 +34,7 @@ pandas==2.2.3 pathspec==0.12.1 platformdirs==4.3.6 pluggy==1.5.0 +pre_commit==4.0.1 psycopg2-binary==2.9.9 pydantic==2.9.0 pydantic-settings==2.5.2 From 6bf35353f8b9b0af546e998974e4c2d0a3015ff0 Mon Sep 17 00:00:00 2001 From: Eli Lucherini Date: Sun, 22 Dec 2024 22:05:11 -0800 Subject: [PATCH 6/8] Seismic + fixes --- backend/api/routers/seismic_api.py | 22 ++++++++++++++++++ backend/api/tests/test_liquefaction.py | 31 ++++++++++++++++++++++++++ backend/api/tests/test_seismic.py | 15 +++++++++++++ 3 files changed, 68 insertions(+) diff --git a/backend/api/routers/seismic_api.py b/backend/api/routers/seismic_api.py index 1d47397f..ddbbf8c2 100644 --- a/backend/api/routers/seismic_api.py +++ b/backend/api/routers/seismic_api.py @@ -3,6 +3,7 @@ from fastapi import Depends, HTTPException, APIRouter from ..tags import Tags from sqlalchemy.orm import Session +from geoalchemy2 import functions as geo_func from backend.database.session import get_db from ..schemas.seismic_schemas import ( SeismicFeature, @@ -39,3 +40,24 @@ async def get_seismic_hazard_zones(db: Session = Depends(get_db)): features = [SeismicFeature.from_sqlalchemy_model(zone) for zone in seismic_zones] return SeismicFeatureCollection(type="FeatureCollection", features=features) + + +@router.get("/is-in-seismic-zone", response_model=bool) +async def is_in_seismic_zone(lat: float, lon: float, db: Session = Depends(get_db)): + """ + Check if a point is in a liquefaction zone. + + Args: + lat (float): Latitude of the point. + lon (float): Longitude of the point. + db (Session): The database session dependency. + + Returns: + bool: True if the point is in a liquefaction zone, False otherwise. + """ + query = db.query(SeismicHazardZone).filter( + SeismicHazardZone.geometry.ST_Contains( + geo_func.ST_SetSRID(geo_func.ST_GeomFromText(f"POINT({lon} {lat})"), 4326) + ) + ) + return db.query(query.exists()).scalar() diff --git a/backend/api/tests/test_liquefaction.py b/backend/api/tests/test_liquefaction.py index e69de29b..c99b2577 100644 --- a/backend/api/tests/test_liquefaction.py +++ b/backend/api/tests/test_liquefaction.py @@ -0,0 +1,31 @@ +""" +Test the API of liquefaction_api.py. +""" + +import pytest +from fastapi.testclient import TestClient + +# Will the .. be stable? +from ..main import app + + +@pytest.fixture +def client(): + return TestClient(app) + + +def test_is_in_liquefaction_zone(client): + lat, lon = [37.779759, -122.407436] + response = client.get( + f"/api/liquefaction-zones/is-in-liquefaction-zone?lat={lat}&lon={lon}" + ) + assert response.status_code == 200 + assert response.json() # True + + # These should not be in liquefaction zones + wrong_lat, wrong_lon = [0.0, 0.0] + response = client.get( + f"/api/liquefaction-zones/is-in-liquefaction-zone?lat={wrong_lat}&lon={wrong_lon}" + ) + assert response.status_code == 200 + assert not response.json() # False diff --git a/backend/api/tests/test_seismic.py b/backend/api/tests/test_seismic.py index 67d51840..e35250b6 100644 --- a/backend/api/tests/test_seismic.py +++ b/backend/api/tests/test_seismic.py @@ -8,3 +8,18 @@ def test_get_seismic_hazard_zones(client): print(response_dict) assert response.status_code == 200 assert len(response_dict) == 2 + + +def test_is_in_seismic_zone(client): + lat, lon = [37.779759, -122.407436] + response = client.get(f"/api/seismic-zones/is-in-seismic-zone?lat={lat}&lon={lon}") + assert response.status_code == 200 + assert response.json() # True + + # These should not be in a seismic hazard zone + wrong_lat, wrong_lon = [0.0, 0.0] + response = client.get( + f"/api/seismic-zones/is-in-seismic-zone?lat={wrong_lat}&lon={wrong_lon}" + ) + assert response.status_code == 200 + assert not response.json() # False From 0e35fa26139fd0730cd87f6a09c8d91554320f43 Mon Sep 17 00:00:00 2001 From: Eli Lucherini Date: Mon, 23 Dec 2024 18:40:16 -0800 Subject: [PATCH 7/8] Fix oops --- backend/api/tests/test_addresses.py | 2 +- backend/api/tests/test_landslide.py | 2 +- backend/api/tests/test_liquefaction.py | 2 +- backend/api/tests/test_soft_story.py | 2 +- backend/api/tests/test_tsunami.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/api/tests/test_addresses.py b/backend/api/tests/test_addresses.py index d798798a..55156320 100644 --- a/backend/api/tests/test_addresses.py +++ b/backend/api/tests/test_addresses.py @@ -1,4 +1,4 @@ -from backend.api.tests.test_session_config import client +from backend.api.tests.test_session_config import test_engine, test_session, client def test_get_address_by_id(client): diff --git a/backend/api/tests/test_landslide.py b/backend/api/tests/test_landslide.py index 7befee54..6556ead6 100644 --- a/backend/api/tests/test_landslide.py +++ b/backend/api/tests/test_landslide.py @@ -1,4 +1,4 @@ -from backend.api.tests.test_session_config import client +from backend.api.tests.test_session_config import test_engine, test_session, client def test_get_landslide_zones(client): diff --git a/backend/api/tests/test_liquefaction.py b/backend/api/tests/test_liquefaction.py index 1040ae8a..17b1cc20 100644 --- a/backend/api/tests/test_liquefaction.py +++ b/backend/api/tests/test_liquefaction.py @@ -1,4 +1,4 @@ -from backend.api.tests.test_session_config import client +from backend.api.tests.test_session_config import test_engine, test_session, client def test_get_liquefaction_zones(client): diff --git a/backend/api/tests/test_soft_story.py b/backend/api/tests/test_soft_story.py index ba83f826..54808454 100644 --- a/backend/api/tests/test_soft_story.py +++ b/backend/api/tests/test_soft_story.py @@ -1,4 +1,4 @@ -from backend.api.tests.test_session_config import client +from backend.api.tests.test_session_config import test_engine, test_session, client def test_get_soft_stories(client): diff --git a/backend/api/tests/test_tsunami.py b/backend/api/tests/test_tsunami.py index af83579d..ca3a328d 100644 --- a/backend/api/tests/test_tsunami.py +++ b/backend/api/tests/test_tsunami.py @@ -1,4 +1,4 @@ -from backend.api.tests.test_session_config import client +from backend.api.tests.test_session_config import test_session, test_engine, client def test_get_tsunami_zones(client): From 666c8e4d7345ee61a7723e2dc25a838992b89871 Mon Sep 17 00:00:00 2001 From: Eli Lucherini Date: Mon, 23 Dec 2024 20:09:08 -0800 Subject: [PATCH 8/8] Swap coordinates to get (lon, lat) --- backend/api/models/tsunami.py | 1 - backend/api/routers/liquefaction_api.py | 4 ++-- backend/api/routers/seismic_api.py | 4 ++-- backend/api/routers/soft_story_api.py | 4 ++-- backend/api/routers/tsunami_api.py | 4 ++-- backend/api/tests/test_liquefaction.py | 8 ++++---- backend/api/tests/test_seismic.py | 10 +++++----- backend/api/tests/test_soft_story.py | 8 ++++---- backend/api/tests/test_tsunami.py | 8 ++++---- 9 files changed, 25 insertions(+), 26 deletions(-) diff --git a/backend/api/models/tsunami.py b/backend/api/models/tsunami.py index 092e78f3..b09a2a59 100644 --- a/backend/api/models/tsunami.py +++ b/backend/api/models/tsunami.py @@ -1,7 +1,6 @@ """Tsunami Risk Zone data""" from sqlalchemy import String, Integer, Float, DateTime, func -from sqlalchemy.orm import DeclarativeBase from sqlalchemy.orm import Mapped from sqlalchemy.orm import mapped_column from geoalchemy2 import Geometry diff --git a/backend/api/routers/liquefaction_api.py b/backend/api/routers/liquefaction_api.py index 2c26e7f7..cc03dadb 100644 --- a/backend/api/routers/liquefaction_api.py +++ b/backend/api/routers/liquefaction_api.py @@ -46,14 +46,14 @@ async def get_liquefaction_zones(db: Session = Depends(get_db)): @router.get("/is-in-liquefaction-zone", response_model=bool) async def is_in_liquefaction_zone( - lat: float, lon: float, db: Session = Depends(get_db) + lon: float, lat: float, db: Session = Depends(get_db) ): """ Check if a point is in a liquefaction zone. Args: - lat (float): Latitude of the point. lon (float): Longitude of the point. + lat (float): Latitude of the point. db (Session): The database session dependency. Returns: diff --git a/backend/api/routers/seismic_api.py b/backend/api/routers/seismic_api.py index ddbbf8c2..00d54916 100644 --- a/backend/api/routers/seismic_api.py +++ b/backend/api/routers/seismic_api.py @@ -43,13 +43,13 @@ async def get_seismic_hazard_zones(db: Session = Depends(get_db)): @router.get("/is-in-seismic-zone", response_model=bool) -async def is_in_seismic_zone(lat: float, lon: float, db: Session = Depends(get_db)): +async def is_in_seismic_zone(lon: float, lat: float, db: Session = Depends(get_db)): """ Check if a point is in a liquefaction zone. Args: - lat (float): Latitude of the point. lon (float): Longitude of the point. + lat (float): Latitude of the point. db (Session): The database session dependency. Returns: diff --git a/backend/api/routers/soft_story_api.py b/backend/api/routers/soft_story_api.py index be004b87..00616094 100644 --- a/backend/api/routers/soft_story_api.py +++ b/backend/api/routers/soft_story_api.py @@ -43,13 +43,13 @@ async def get_soft_stories(db: Session = Depends(get_db)): @router.get("/is-soft-story", response_model=bool) -async def is_soft_story(lat: float, lon: float, db: Session = Depends(get_db)): +async def is_soft_story(lon: float, lat: float, db: Session = Depends(get_db)): """ Check if a point is a soft story property. Args: - lat (float): Latitude of the point. lon (float): Longitude of the point. + lat (float): Latitude of the point. db (Session): The database session dependency. Returns: diff --git a/backend/api/routers/tsunami_api.py b/backend/api/routers/tsunami_api.py index 7f31ed06..40bc2768 100644 --- a/backend/api/routers/tsunami_api.py +++ b/backend/api/routers/tsunami_api.py @@ -42,13 +42,13 @@ async def get_tsunami_zones(db: Session = Depends(get_db)): @router.get("/is-in-tsunami-zone", response_model=bool) -async def is_in_tsunami_zone(lat: float, lon: float, db: Session = Depends(get_db)): +async def is_in_tsunami_zone(lon: float, lat: float, db: Session = Depends(get_db)): """ Check if a point is in a tsunami zone. Args: - lat (float): Latitude of the point. lon (float): Longitude of the point. + lat (float): Latitude of the point. db (Session): The database session dependency. Returns: diff --git a/backend/api/tests/test_liquefaction.py b/backend/api/tests/test_liquefaction.py index 17b1cc20..f1415c64 100644 --- a/backend/api/tests/test_liquefaction.py +++ b/backend/api/tests/test_liquefaction.py @@ -9,17 +9,17 @@ def test_get_liquefaction_zones(client): def test_is_in_liquefaction_zone(client): - lat, lon = [37.779759, -122.407436] + lon, lat = [-122.35, 37.83] response = client.get( - f"/api/liquefaction-zones/is-in-liquefaction-zone?lat={lat}&lon={lon}" + f"/liquefaction-zones/is-in-liquefaction-zone?lon={lon}&lat={lat}" ) assert response.status_code == 200 assert response.json() # True # These should not be in liquefaction zones - wrong_lat, wrong_lon = [0.0, 0.0] + wrong_lon, wrong_lat = [0.0, 0.0] response = client.get( - f"/api/liquefaction-zones/is-in-liquefaction-zone?lat={wrong_lat}&lon={wrong_lon}" + f"/liquefaction-zones/is-in-liquefaction-zone?lon={wrong_lon}&lat={wrong_lat}" ) assert response.status_code == 200 assert not response.json() # False diff --git a/backend/api/tests/test_seismic.py b/backend/api/tests/test_seismic.py index 76623415..10e87a3e 100644 --- a/backend/api/tests/test_seismic.py +++ b/backend/api/tests/test_seismic.py @@ -1,4 +1,4 @@ -from backend.api.tests.test_session_config import client +from backend.api.tests.test_session_config import test_engine, test_session, client def test_get_seismic_hazard_zones(client): @@ -9,15 +9,15 @@ def test_get_seismic_hazard_zones(client): def test_is_in_seismic_zone(client): - lat, lon = [37.779759, -122.407436] - response = client.get(f"/api/seismic-zones/is-in-seismic-zone?lat={lat}&lon={lon}") + lon, lat = [-122.407436, 37.779759] + response = client.get(f"/seismic-zones/is-in-seismic-zone?lon={lon}&lat={lat}") assert response.status_code == 200 assert response.json() # True # These should not be in a seismic hazard zone - wrong_lat, wrong_lon = [0.0, 0.0] + wrong_lon, wrong_lat = [0.0, 0.0] response = client.get( - f"/api/seismic-zones/is-in-seismic-zone?lat={wrong_lat}&lon={wrong_lon}" + f"/seismic-zones/is-in-seismic-zone?lon={wrong_lon}&lat={wrong_lat}" ) assert response.status_code == 200 assert not response.json() # False diff --git a/backend/api/tests/test_soft_story.py b/backend/api/tests/test_soft_story.py index 54808454..452d8c38 100644 --- a/backend/api/tests/test_soft_story.py +++ b/backend/api/tests/test_soft_story.py @@ -9,15 +9,15 @@ def test_get_soft_stories(client): def test_is_soft_story(client): - lat, lon = [-122.446575165, 37.766034349] - response = client.get(f"/api/soft-story/is-soft-story?lat={lat}&lon={lon}") + lon, lat = [-122.424966202, 37.762929444] + response = client.get(f"/soft-stories/is-soft-story?lon={lon}&lat={lat}") assert response.status_code == 200 assert response.json() # True # These should not be soft stories - wrong_lat, wrong_lon = [0.0, 0.0] + wrong_lon, wrong_lat = [0.0, 0.0] response = client.get( - f"/api/soft-story/is-soft-story?lat={wrong_lat}&lon={wrong_lon}" + f"/soft-stories/is-soft-story?lon={wrong_lon}&lat={wrong_lat}" ) assert response.status_code == 200 assert not response.json() # False diff --git a/backend/api/tests/test_tsunami.py b/backend/api/tests/test_tsunami.py index ca3a328d..77fa6a73 100644 --- a/backend/api/tests/test_tsunami.py +++ b/backend/api/tests/test_tsunami.py @@ -9,15 +9,15 @@ def test_get_tsunami_zones(client): def test_is_in_tsunami_zone(client): - lat, lon = [37.759039, -122.509515] - response = client.get(f"/api/tsunami/is-in-tsunami-zone?lat={lat}&lon={lon}") + lon, lat = [-122.4, 37.75] + response = client.get(f"/tsunami-zones/is-in-tsunami-zone?lon={lon}&lat={lat}") assert response.status_code == 200 assert response.json() # True # These should not be in our tsunami zone - wrong_lat, wrong_lon = [0.0, 0.0] + wrong_lon, wrong_lat = [0.0, 0.0] response = client.get( - f"/api/tsunami/is-in-tsunami-zone?lat={wrong_lat}&lon={wrong_lon}" + f"/tsunami-zones/is-in-tsunami-zone?lon={wrong_lon}&lat={wrong_lat}" ) assert response.status_code == 200 assert not response.json() # False