feat(mma): Implement track progress calculation and refactor get_all_tracks
This commit is contained in:
@@ -318,10 +318,10 @@ def get_all_tracks(base_dir: Union[str, Path] = ".") -> list[dict[str, Any]]:
|
||||
track_info["id"] = state.metadata.id or track_id
|
||||
track_info["title"] = state.metadata.name or track_id
|
||||
track_info["status"] = state.metadata.status or "unknown"
|
||||
track_info["complete"] = len([t for t in state.tasks if t.status == "completed"])
|
||||
track_info["total"] = len(state.tasks)
|
||||
if track_info["total"] > 0:
|
||||
track_info["progress"] = track_info["complete"] / track_info["total"]
|
||||
progress = calculate_track_progress(state.tasks)
|
||||
track_info["complete"] = progress["completed"]
|
||||
track_info["total"] = progress["total"]
|
||||
track_info["progress"] = progress["percentage"] / 100.0
|
||||
state_found = True
|
||||
except Exception:
|
||||
pass
|
||||
@@ -352,3 +352,35 @@ def get_all_tracks(base_dir: Union[str, Path] = ".") -> list[dict[str, Any]]:
|
||||
pass
|
||||
results.append(track_info)
|
||||
return results
|
||||
|
||||
def calculate_track_progress(tickets: list) -> dict:
|
||||
"""
|
||||
Calculates track progress based on ticket statuses.
|
||||
percentage (float), completed (int), total (int), in_progress (int), blocked (int), todo (int)
|
||||
"""
|
||||
total = len(tickets)
|
||||
if total == 0:
|
||||
return {
|
||||
"percentage": 0.0,
|
||||
"completed": 0,
|
||||
"total": 0,
|
||||
"in_progress": 0,
|
||||
"blocked": 0,
|
||||
"todo": 0
|
||||
}
|
||||
|
||||
completed = sum(1 for t in tickets if t.status == "completed")
|
||||
in_progress = sum(1 for t in tickets if t.status == "in_progress")
|
||||
blocked = sum(1 for t in tickets if t.status == "blocked")
|
||||
todo = sum(1 for t in tickets if t.status == "todo")
|
||||
|
||||
percentage = (completed / total) * 100.0
|
||||
|
||||
return {
|
||||
"percentage": float(percentage),
|
||||
"completed": completed,
|
||||
"total": total,
|
||||
"in_progress": in_progress,
|
||||
"blocked": blocked,
|
||||
"todo": todo
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user