All checks were successful
Deploy Development / deploy (push) Successful in 50s
Test Suite / pytest-backend (push) Successful in 2m21s
Test Suite / lint-backend (push) Successful in 2s
Test Suite / compose-smoke (push) Has been skipped
Test Suite / k6 /api/health Baseline (push) Successful in 18s
Test Suite / playwright-smoke (push) Successful in 21s
Co-authored-by: Cursor <cursoragent@cursor.com>
40 lines
1.2 KiB
Python
40 lines
1.2 KiB
Python
"""Portfolio-Priorität — Sortierung für Next Action (AP1.8a)."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, Optional
|
|
|
|
|
|
def portfolio_rank_sort_key(
|
|
initiative_id: Optional[str],
|
|
rank_map: dict[str, Optional[int]],
|
|
) -> tuple[int, str]:
|
|
"""Niedrigerer Rank = höhere Priorität; NULL ans Ende."""
|
|
if not initiative_id:
|
|
return (1_000_000, "")
|
|
rank = rank_map.get(initiative_id)
|
|
if rank is None:
|
|
return (999_999, initiative_id)
|
|
return (rank, initiative_id)
|
|
|
|
|
|
def sort_candidates_by_portfolio_rank(
|
|
candidates: list[dict[str, Any]],
|
|
rank_map: dict[str, Optional[int]],
|
|
) -> list[dict[str, Any]]:
|
|
"""Sortiert Next-Action-Kandidaten nach Portfolio-Rang."""
|
|
enriched = []
|
|
for candidate in candidates:
|
|
item = dict(candidate)
|
|
initiative_id = item.get("initiative_id")
|
|
if initiative_id:
|
|
item["portfolio_rank"] = rank_map.get(str(initiative_id))
|
|
enriched.append(item)
|
|
enriched.sort(
|
|
key=lambda c: portfolio_rank_sort_key(
|
|
str(c["initiative_id"]) if c.get("initiative_id") else None,
|
|
rank_map,
|
|
)
|
|
)
|
|
return enriched
|