From b17e961e571f02e10cf5966e8b4e278f6a3a8531 Mon Sep 17 00:00:00 2001 From: Pradip-p Date: Fri, 9 Aug 2024 11:23:22 +0545 Subject: [PATCH 1/3] feat: update SQL query to map integer states to text with default for unknowns --- src/backend/app/tasks/task_crud.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/backend/app/tasks/task_crud.py b/src/backend/app/tasks/task_crud.py index 3a021318..b7589f02 100644 --- a/src/backend/app/tasks/task_crud.py +++ b/src/backend/app/tasks/task_crud.py @@ -55,14 +55,19 @@ async def get_tasks_by_user(user_id: str, db: Database): task_details.task_id, task_details.project_id, task_details.task_area, - task_details.created_at, + task_details.created_at, CASE - WHEN task_details.state = 'REQUEST_FOR_MAPPING' THEN 'ongoing' + WHEN task_details.state = 'REQUEST_FOR_MAPPING' THEN 'ongoing' + WHEN task_details.state = 'UNLOCKED_TO_MAP' THEN 'ready to map' + WHEN task_details.state = 'LOCKED_FOR_MAPPING' THEN 'locked for mapping' + WHEN task_details.state = 'UNLOCKED_TO_VALIDATE' THEN 'mapped' + WHEN task_details.state = 'LOCKED_FOR_VALIDATION' THEN 'mapped' WHEN task_details.state = 'UNLOCKED_DONE' THEN 'completed' - WHEN task_details.state IN ('UNLOCKED_TO_VALIDATE', 'LOCKED_FOR_VALIDATION') THEN 'mapped' - ELSE 'unknown' + WHEN task_details.state = 'UNFLYABLE_TASK' THEN 'unflyable task' + ELSE 'unknown' -- Default case if the state does not match any expected values END AS state - FROM task_details + FROM task_details; + """ records = await db.fetch_all(query, values={"user_id": user_id}) From cd5cc57c4c4f8e9a849db131cd0958d89c56c335 Mon Sep 17 00:00:00 2001 From: Pradip-p Date: Fri, 9 Aug 2024 12:00:45 +0545 Subject: [PATCH 2/3] refractor: sql query on task lists --- src/backend/app/tasks/task_crud.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend/app/tasks/task_crud.py b/src/backend/app/tasks/task_crud.py index b7589f02..19ae70f3 100644 --- a/src/backend/app/tasks/task_crud.py +++ b/src/backend/app/tasks/task_crud.py @@ -55,9 +55,9 @@ async def get_tasks_by_user(user_id: str, db: Database): task_details.task_id, task_details.project_id, task_details.task_area, - task_details.created_at, + task_details.created_at, CASE - WHEN task_details.state = 'REQUEST_FOR_MAPPING' THEN 'ongoing' + WHEN task_details.state = 'REQUEST_FOR_MAPPING' THEN 'ongoing' WHEN task_details.state = 'UNLOCKED_TO_MAP' THEN 'ready to map' WHEN task_details.state = 'LOCKED_FOR_MAPPING' THEN 'locked for mapping' WHEN task_details.state = 'UNLOCKED_TO_VALIDATE' THEN 'mapped' From 3019bd15a76ea9f5014400dd907e8dab8b6a921d Mon Sep 17 00:00:00 2001 From: Pradip-p Date: Fri, 9 Aug 2024 13:53:39 +0545 Subject: [PATCH 3/3] refractor: state of the tasks --- src/backend/app/tasks/task_crud.py | 7 ++----- src/backend/app/tasks/task_routes.py | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/backend/app/tasks/task_crud.py b/src/backend/app/tasks/task_crud.py index 19ae70f3..7f121fc0 100644 --- a/src/backend/app/tasks/task_crud.py +++ b/src/backend/app/tasks/task_crud.py @@ -57,11 +57,8 @@ async def get_tasks_by_user(user_id: str, db: Database): task_details.task_area, task_details.created_at, CASE - WHEN task_details.state = 'REQUEST_FOR_MAPPING' THEN 'ongoing' - WHEN task_details.state = 'UNLOCKED_TO_MAP' THEN 'ready to map' - WHEN task_details.state = 'LOCKED_FOR_MAPPING' THEN 'locked for mapping' - WHEN task_details.state = 'UNLOCKED_TO_VALIDATE' THEN 'mapped' - WHEN task_details.state = 'LOCKED_FOR_VALIDATION' THEN 'mapped' + WHEN task_details.state = 'REQUEST_FOR_MAPPING' THEN 'request logs' + WHEN task_details.state = 'LOCKED_FOR_MAPPING' THEN 'ongoing' WHEN task_details.state = 'UNLOCKED_DONE' THEN 'completed' WHEN task_details.state = 'UNFLYABLE_TASK' THEN 'unflyable task' ELSE 'unknown' -- Default case if the state does not match any expected values diff --git a/src/backend/app/tasks/task_routes.py b/src/backend/app/tasks/task_routes.py index 9907b27c..b1ea88b1 100644 --- a/src/backend/app/tasks/task_routes.py +++ b/src/backend/app/tasks/task_routes.py @@ -69,8 +69,8 @@ async def get_task_stats( raise HTTPException(status_code=404, detail="User profile not found") raw_sql = """ SELECT - COUNT(CASE WHEN te.state = 'LOCKED_FOR_MAPPING' THEN 1 END) AS ongoing_tasks, COUNT(CASE WHEN te.state = 'REQUEST_FOR_MAPPING' THEN 1 END) AS request_logs, + COUNT(CASE WHEN te.state = 'LOCKED_FOR_MAPPING' THEN 1 END) AS ongoing_tasks, COUNT(CASE WHEN te.state = 'UNLOCKED_DONE' THEN 1 END) AS completed_tasks, COUNT(CASE WHEN te.state = 'UNFLYABLE_TASK' THEN 1 END) AS unflyable_tasks FROM tasks t