Skip to content

Commit

Permalink
fix: use task ids to count validated and mapped status
Browse files Browse the repository at this point in the history
  • Loading branch information
Sujanadh committed Apr 26, 2024
1 parent 6fde4f9 commit 9464247
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
26 changes: 13 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,17 @@ 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
17 changes: 14 additions & 3 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,20 @@ 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 9464247

Please sign in to comment.