From e0b71d88772e844ef063d793a6bb0672a042ef55 Mon Sep 17 00:00:00 2001 From: Niraj Adhikari Date: Thu, 2 Nov 2023 17:54:12 +0545 Subject: [PATCH] feat: api to get data extracts for the given aoi and category --- src/backend/app/projects/project_routes.py | 39 ++++++++++++++++++++-- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/src/backend/app/projects/project_routes.py b/src/backend/app/projects/project_routes.py index fd951d440e..5f710d9b49 100644 --- a/src/backend/app/projects/project_routes.py +++ b/src/backend/app/projects/project_routes.py @@ -616,8 +616,10 @@ async def generate_files( try: extracts_contents = await data_extracts.read() json.loads(extracts_contents) - except json.JSONDecodeError: - raise HTTPException(status_code=400, detail="Provide a valid geojson file") + except json.JSONDecodeError as e: + raise HTTPException( + status_code=400, detail="Provide a valid geojson file" + ) from e # generate a unique task ID using uuid background_task_id = uuid.uuid4() @@ -647,6 +649,39 @@ async def generate_files( return {"Message": f"{project_id}", "task_id": f"{background_task_id}"} +from osm_fieldwork.data_models import data_models_path +from osm_fieldwork.filter_data import FilterData +from osm_rawdata.postgres import PostgresClient + + +@router.post("/view_data_extracts/") +async def get_data_extracts( + aoi: UploadFile, + category: Optional[str] = Form(...), +): + # read entire file + await aoi.seek(0) + aoi_content = await aoi.read() + boundary = json.loads(aoi_content) + + # Validatiing Coordinate Reference System + check_crs(boundary) + xlsform = f"{xlsforms_path}/{category}.xls" + + config_path = f"{data_models_path}/{category}.yaml" + + # # OSM Extracts using raw data api + pg = PostgresClient("underpass", config_path) + data_extract = pg.execQuery(boundary) + filter = FilterData(xlsform) + + updated_data_extract = {"type": "FeatureCollection", "features": []} + filtered_data_extract = ( + filter.cleanData(data_extract) if data_extract else updated_data_extract + ) + return filtered_data_extract + + @router.post("/update-form/{project_id}") async def update_project_form( project_id: int,