Skip to content

Commit

Permalink
Merge pull request #135 from hotosm/feat/task-stats-endpoint
Browse files Browse the repository at this point in the history
hotfix: query to update state labels in task_details
  • Loading branch information
nrjadkry authored Aug 9, 2024
2 parents e55315e + 3019bd1 commit 26ba1ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/backend/app/tasks/task_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ 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 = '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 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})
Expand Down
2 changes: 1 addition & 1 deletion src/backend/app/tasks/task_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 26ba1ea

Please sign in to comment.