grantforge-api / backend /agents /timeline.py
GrantForge Bot
Deploy to Hugging Face
afd56bc
import logging
from typing import Dict, Any
from schemas import AgentState
logger = logging.getLogger(__name__)
def timeline_node(state: AgentState) -> Dict[str, Any]:
"""
W臋ze艂 generuj膮cy harmonogram (timeline_events) dla nabor贸w w kt贸rych firma mo偶e wzi膮膰 udzia艂.
"""
grants = state.eligible_grants
if not grants:
return {"current_agent": "supervisor"}
# Posortuj po skorygowanym relevance_score, we藕 max 3 by nie za艣mieca膰 widoku
top_grants = sorted(
grants,
key=lambda x: x.relevance_score if x.relevance_score else 0.0,
reverse=True,
)[:3]
events = []
# Tworzymy symulowany kalendarz na podstawie zebranych dotacji
for idx, grant in enumerate(top_grants):
# Wydarzenie startowe: rozpocz臋cie prac nad wnioskiem
events.append(
{
"id": f"start_prep_{grant.id}",
"title": f"Rozpocz臋cie przygotowa艅 do: {grant.title}",
"description": "Zebranie dokumentacji technicznej i finansowej",
"date": "Dzisiaj",
"status": "upcoming",
}
)
# Ostateczny termin
deadline_str = grant.deadline if grant.deadline else "Brak podanej daty"
events.append(
{
"id": f"deadline_{grant.id}",
"title": f"Wys艂anie wniosku: {grant.title}",
"description": f"Instytucja przyjmuj膮ca: {grant.institution}. Bud偶et: ok. {grant.max_amount} PLN",
"date": deadline_str,
"status": "pending",
}
)
# Przewidywana ocena wniosku (zak艂adamy 90 dni)
events.append(
{
"id": f"evaluation_{grant.id}",
"title": f"Spodziewane og艂oszenie wynik贸w: {grant.title}",
"description": "Zako艅czenie oceny eksperckiej wniosku przez instytucj臋",
"date": "+90 dni od wp艂yni臋cia",
"status": "future",
}
)
logger.info(
f"Timeline node wygenerowa艂 {len(events)} wydarze艅 na osi czasu dla top {len(top_grants)} dotacji."
)
return {"timeline_events": events, "current_agent": "supervisor"}