o
    ®Á›jõ  ã                   @   s°   d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ dd	lmZmZ eG d
d„ dƒƒZ	ddedededededededefdd„ZdS )a°  
prediction_pipeline.py

Live wiring for this session's engine chain -- stream_features ->
trend_engine -> structure_engine -> regime_engine -> setup_engine ->
prediction_engine -> entry_score.py -- the live counterpart to
simulate_prediction_pipeline.py's offline replay, same relationship as
regime_strategies.py (live-callable) vs simulate_regime_strategies.py
(offline harness).

evaluate_entry_pipeline() is monitor.py's alternative to
entry_engine.evaluate_entry(), selected via config.json's
entry.decision_engine == "prediction_pipeline" (default stays "legacy" --
entry_engine.evaluate_entry() is unchanged and still the default path).
It returns an EntryDecision-shaped result (same field names as
entry_engine.EntryDecision: should_enter, confirmation_score,
reasons_for, reasons_against) so monitor.py's call site only needs to
choose which function to call, not restructure around a different shape.

CALLER-HELD STATE: same contract as every engine built this session --
this module holds nothing itself. monitor.py keeps one dict per symbol
(Monitor._pipeline_state[symbol]) across poll cycles and passes it in as
`state`; this function mutates it in place (prior_features/
prior_prediction/confirmation_state) and also returns it for convenience.
A fresh {} for a symbol (first call ever, or a deliberate reset) is
fine -- everything defaults to a cold start, exactly like the offline
replay's per-symbol loop.

DELIBERATELY LOW EXPECTED FIRE RATE, KNOWN GOING IN: four days of
offline replay (2026-09-01 through 09-04, see data/snapshots/<date>/
prediction_pipeline_backtest.json) found 3 entries across 4 days / 405
symbol-days -- prediction_engine.py's score rarely clears entry_score's
min_prediction_score threshold. That backtest ran with bars_sub=[]
throughout (the Yahoo snapshot data has no real sub-minute ticks) --
LIVE, stream.py's real sub-minute buffer means velocity_sub/slope_sub/
trade_flow/pressure are actually populated here, which several
prediction_engine.py components read directly and default to neutral
values without. Live behavior may therefore differ from the backtest in
either direction -- exactly why this is a paper-mode test, not a
conclusion drawn from the backtest alone.
é    )Ú	dataclassÚfield)Úcompute_features)Úclassify_trend)Úanalyze_structure)Úclassify_regime)Úevaluate_setups)Úcompute_prediction)Úcompute_entry_scoreÚACTION_READYc                   @   sJ   e Zd ZU eed< eed< eed< eed�Z	eed< eed�Z
eed< dS )ÚPipelineDecisionÚsymbolÚshould_enterÚconfirmation_score)Údefault_factoryÚreasons_forÚreasons_againstN)Ú__name__Ú
__module__Ú__qualname__ÚstrÚ__annotations__ÚboolÚfloatr   Úlistr   r   © r   r   úO/var/www/screener/trade/premarket_backup_2026-09-08_2010/prediction_pipeline.pyr   6   s   
 r   é   Nr   ÚbarsÚbars_subÚavg_vol_baselineÚsession_elapsed_minutesÚstateÚsub_bucket_secondsÚreturnc	                 C   sø   |  dd¡ |  dd¡ |  di ¡ t| |||||d ||d�}	t|	ƒ}
t| |ƒ}t| |	|
||ƒ}t|	|
||ƒ}t| |	|
||||d d�}t| |	|
|||||d |d�	}|	|d< ||d< |j|d< |j	t
k}t| ||j|rp|jng |rwg d�S |jd�S )	aë  
    bars / bars_sub / quote: same shapes stream.StreamManager already
        hands entry_engine.evaluate_entry() (bars, quote) plus the new
        get_bars_sub() this session added.
    avg_vol_baseline: same "expected normal volume" baseline
        entry_engine/intraday_health already use.
    session_elapsed_minutes: market_time.minutes_since_open() -- drives
        regime_engine's OPENING_VOLATILITY window check.
    state: caller-held per-symbol dict, see module docstring.
    Úprior_featuresNÚprior_predictionÚconfirmation_state)r    Úpriorr#   Úas_of)ÚregimeÚsetupsr(   )r*   r+   r'   r)   )r   r   r   r   r   )Ú
setdefaultr   r   r   r   r   r	   r
   ÚconfirmationÚactionr   r   Úentry_scoreÚreasons)r   r   r   Úquoter    r!   r"   r#   r)   ÚfeaturesÚtrendÚ	structurer*   r+   Ú
predictionÚentry_readingr   r   r   r   Úevaluate_entry_pipeline?   s:   þ
ÿþ

ýýr7   )r   N)Ú__doc__Údataclassesr   r   Ústream_featuresr   Útrend_enginer   Ústructure_enginer   Úregime_enginer   Úsetup_enginer   Úprediction_enginer	   r/   r
   r   r   r   r   r   ÚdictÚintr7   r   r   r   r   Ú<module>   s.    *
þÿÿþþþ