from core.pipeline.step import PipelineStep from observability import logger as obs_logger from observability import components as obs_components class PositioningStep(PipelineStep): name = "positioning_detection" def __init__(self, positioning_service, recommendation_service, goal_progress_service, goal_service): self.positioning_service = positioning_service self.recommendation_service = recommendation_service self.goal_progress_service = goal_progress_service self.goal_service = goal_service async def run(self, context): if not context.weekly_snapshot or not context.weekly_trend: context.positioning = None context.recommendation = None return goal = self.goal_service.get_active_goal(context.runner_profile.runner_id) goal_progress = self.goal_progress_service.compute( self.goal_service, goal, context.weekly_snapshot, context.weekly_trend ) context.positioning = self.positioning_service.generate( snapshot=context.weekly_snapshot, trend=context.weekly_trend, goal_progress=goal_progress ) obs_logger.log_event( "info", "Positioning applied to pipeline", event="positioning_used", component=obs_components.ORCHESTRATOR, week=str(context.weekly_snapshot.week_start_date), status=context.positioning.position_status, ) obs_logger.log_event( "info", "Training phase detected", event="training_phase_detected", component=obs_components.APPLICATION, phase=context.positioning.training_phase, ) # Recommendation Generation with obs_logger.start_span("recommendation.generate", obs_components.SERVICE): context.recommendation = self.recommendation_service.generate( snapshot=context.weekly_snapshot, trend=context.weekly_trend, positioning=context.positioning, language=context.language ) obs_logger.log_event( "info", "Training recommendation generated", event="recommendation_generated", component=obs_components.SERVICE, focus=context.recommendation.focus, session_type=context.recommendation.session_type, confidence=context.recommendation.confidence )