Skip to content

Commit

Permalink
fix(backend): use task ids to count validated and mapped status (#1485)
Browse files Browse the repository at this point in the history
* fix: use task ids to count validated and mapped status

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Sujanadh and pre-commit-ci[bot] authored Apr 26, 2024
1 parent befdf9d commit 25992b3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
28 changes: 15 additions & 13 deletions src/backend/app/tasks/tasks_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,10 @@ async def get_project_task_history(
comment: bool,
end_date: datetime,
db: Session,
):
) -> list:
"""Retrieves the task history records for a specific project.
Args:
project_id (int): The ID of the project.
task_id (int): The task_id of the project.
comment (bool): True or False, True to get comments
from the project tasks and False by default for
Expand Down Expand Up @@ -382,7 +381,7 @@ async def get_project_task_history(


async def count_validated_and_mapped_tasks(
task_history: list[db_models.DbTaskHistory], end_date: datetime
task_history: list, end_date: datetime
) -> list[tasks_schemas.TaskHistoryCount]:
"""Counts the number of validated and mapped tasks.
Expand All @@ -407,16 +406,19 @@ async def count_validated_and_mapped_tasks(
current_date += timedelta(days=1)

# Populate cumulative_counts with counts from task_history
for result in task_history:
task_status = (result.get("action_text")).split()[5]
date_str = (result.get("action_date")).strftime("%m/%d")
entry = next((entry for entry in results if entry["date"] == date_str), None)

if entry:
if task_status == "VALIDATED":
entry["validated"] += 1
elif task_status == "MAPPED":
entry["mapped"] += 1
for history in task_history:
for result in history:
task_status = result.get("status")
date_str = (result.get("action_date")).strftime("%m/%d")
entry = next(
(entry for entry in results if entry["date"] == date_str), None
)

if entry:
if task_status == "VALIDATED":
entry["validated"] += 1
elif task_status == "MAPPED":
entry["mapped"] += 1

total_validated = 0
total_mapped = 0
Expand Down
12 changes: 8 additions & 4 deletions src/backend/app/tasks/tasks_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#
"""Routes for FMTM tasks."""

import asyncio
from datetime import datetime, timedelta
from typing import List

Expand Down Expand Up @@ -171,10 +172,13 @@ async def task_activity(
"""
end_date = datetime.now() - timedelta(days=days)
task_history = await tasks_crud.get_project_task_history(
project_id, False, end_date, None, db
)

task_list = await tasks_crud.get_task_id_list(db, project_id)
tasks = []
for task_id in task_list:
tasks.extend(
[tasks_crud.get_project_task_history(task_id, False, end_date, db)]
)
task_history = await asyncio.gather(*tasks)
return await tasks_crud.count_validated_and_mapped_tasks(
task_history,
end_date,
Expand Down

0 comments on commit 25992b3

Please sign in to comment.