From 0b67b06d2f4df5fab85677cc1dee506e6d62e4b5 Mon Sep 17 00:00:00 2001 From: Niraj Adhikari Date: Mon, 22 Jul 2024 17:05:38 +0545 Subject: [PATCH 1/2] no fly zone made optional in project creation --- src/backend/app/projects/project_schemas.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/backend/app/projects/project_schemas.py b/src/backend/app/projects/project_schemas.py index 092caeac..31345d89 100644 --- a/src/backend/app/projects/project_schemas.py +++ b/src/backend/app/projects/project_schemas.py @@ -35,7 +35,7 @@ class ProjectIn(BaseModel): dem_url: Optional[str] = None gsd_cm_px: float = None is_terrain_follow: bool = False - outline_no_fly_zones: Union[FeatureCollection, Feature, Polygon] + outline_no_fly_zones: Optional[Union[FeatureCollection, Feature, Polygon]] = None outline_geojson: Union[FeatureCollection, Feature, Polygon] output_orthophoto_url: Optional[str] = None output_pointcloud_url: Optional[str] = None From 1034e9472a7065d9ac20b7106f8292019db735ce Mon Sep 17 00:00:00 2001 From: Niraj Adhikari Date: Mon, 22 Jul 2024 17:43:37 +0545 Subject: [PATCH 2/2] update: task status for all task events in endpoint --- src/backend/app/tasks/task_crud.py | 46 ++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/src/backend/app/tasks/task_crud.py b/src/backend/app/tasks/task_crud.py index ac42dd92..f63cdfb3 100644 --- a/src/backend/app/tasks/task_crud.py +++ b/src/backend/app/tasks/task_crud.py @@ -3,16 +3,56 @@ from app.models.enums import State +async def get_all_tasks(db: Database, project_id: uuid.UUID): + query = """ + SELECT id FROM tasks WHERE project_id = :project_id + """ + values = {"project_id": str(project_id)} + + data = await db.fetch_all(query, values) + + # Extracting the list of IDs from the data + task_ids = [task["id"] for task in data] + + return task_ids + + async def all_tasks_states(db: Database, project_id: uuid.UUID): query = """ SELECT DISTINCT ON (task_id) project_id, task_id, state FROM task_events - WHERE project_id=:project_id + WHERE project_id = :project_id ORDER BY task_id, created_at DESC - """ + """ + r = await db.fetch_all(query, {"project_id": str(project_id)}) - return [dict(r) for r in r] + # Extract task_ids and corresponding states from the query result + existing_tasks = [dict(r) for r in r] + + # Get all task_ids from the tasks table + task_ids = await get_all_tasks(db, project_id) + + # Create a set of existing task_ids for quick lookup + existing_task_ids = {task["task_id"] for task in existing_tasks} + + # task ids that are not in task_events table + remaining_task_ids = [x for x in task_ids if x not in existing_task_ids] + + # Add missing tasks with state as "UNLOCKED_FOR_MAPPING" + remaining_tasks = [ + { + "project_id": str(project_id), + "task_id": task_id, + "state": State.UNLOCKED_TO_MAP.name, + } + for task_id in remaining_task_ids + ] + + # Combine both existing tasks and remaining tasks + combined_tasks = existing_tasks + remaining_tasks + + return combined_tasks async def request_mapping(