o
    Úœ jà  ã                   @   sv  d Z ddlmZmZ ddlmZ ddlZdddi ejej	dejdej
di“ej	ejdejdej	di“ejejd	ejd
ej	di“ejejdejd
ej
di“ejejdejd
ejdi“ejejdejdejdi“ejejdejd
ddi“ejejd	ejdddi“dejdejdej
di“ejejd	ejdej
di“ejejd	ejdejdi“ejejdejd
ej
di“ejejdejd
ejdi“ejejdejd
ejdi“ejddejdejdi“dej
ddd
ejdi“ddd
ejd
ddi“ddd
ddœejejd
ddejdiej
ddej
d
ejdiejejd
ejd
ejdiejdd	ejd
ej
dii¥dœZeG dd„ dƒƒZddededefdd„ZdS )a  
state_transitions.py

[Phase 4 -- new] Deterministic next-state probability estimation, sibling
to prediction_engine.py's existing _next_move_distribution() -- same
philosophy applied one layer up: an inspectable, config-driven heuristic
table (NOT ML, NOT statistically calibrated -- same explicit discipline as
prediction_engine.py's own docstring), operating on regime_engine.py's
market-state taxonomy instead of prediction_engine's five next-move states.

Reuses two readings that already exist rather than inventing a third bias
figure that would mean almost the same thing:
  - prediction.bullish_probability[horizon] (prediction_engine.py)
  - compression.breakout_pressure_score (compression_engine.py)

Pure function, no state, no I/O. Not consumed anywhere in the live bot yet.
é    )Ú	dataclassÚfield)Ú
get_configNgš™™™™™Ù?g333333Ó?Ú3mgš™™™™™É?gÍÌÌÌÌÌÜ?gffffffÖ?ç      à?g333333Ã?gš™™™™™á?ÚEXTENDEDg      Ð?Ú	DECLININGÚSTALEÚWEAK)r	   r   r
   )Ú nudge_bullish_probability_weightÚnudge_breakout_pressure_weightÚprediction_horizonÚbase_transitionsc                   @   sF   e Zd ZU eed< eed�Zeed< dZe	ed< ee
d�Ze
ed< dS )ÚTransitionEstimateÚcurrent_state)Údefault_factoryÚprobabilitiesFÚinsufficient_dataÚmissingN)Ú__name__Ú
__module__Ú__qualname__ÚstrÚ__annotations__r   Údictr   r   ÚboolÚlistr   © r   r   ú0/var/www/screener/premarket/state_transitions.pyr   =   s
   
 r   r   ÚcfgÚreturnc                    s†  i t ¥|ptƒ  di ¡¥}|d }| | ddi¡}d}|dur-t|ddƒs-|j |d ¡}d}|dur>t|ddƒs>|jd	 }i }| ¡ D ]e\}	}
|
}|	tjtj	tj
tjtjtjfv }|	tjtjd
dfv }|durx|rx|d|d |d  d  9 }|durŒ|rŒ|d|d |d  d  9 }|dur¢|	tj
tjfv r¢|d|d |  9 }td|ƒ||	< qDt| ¡ ƒp±d‰ ‡ fdd„| ¡ D ƒ}t| |d�S )as  
    current_state: a regime_engine.py regime label (e.g. regime.regime).
    prediction: optional prediction_engine.PredictionReading -- used for the
        bullish-probability nudge. Omit to skip that nudge (base table only).
    compression: optional compression_engine.CompressionReading -- used for
        the breakout-pressure nudge. Omit to skip that nudge.
    Ústate_transitionsr   ÚUNKNOWNg      ð?Nr   Fr   g      Y@r   r
   é   r   r   é   r   g        c                    s    i | ]\}}|t |ˆ  d ƒ“qS )é   )Úround)Ú.0ÚkÚv©Útotalr   r   Ú
<dictcomp>i   s     z'estimate_next_state.<locals>.<dictcomp>)r   r   )ÚDEFAULT_CONFIGr   ÚgetÚgetattrÚbullish_probabilityÚbreakout_pressure_scoreÚitemsÚreÚCONTINUATIONÚ	EXPANSIONÚBREAKOUT_ATTEMPTÚBREAKOUT_CONFIRMEDÚPRESSURE_BUILDINGÚRECOVERYÚSTRUCTURE_BREAKDOWNÚFAILED_BREAKOUTÚmaxÚsumÚvaluesr   )r   Ú
predictionÚcompressionr   ÚtableÚbaseÚbullish_probÚpressureÚnudgedÚ	candidateÚweightÚwÚbullish_leaningÚbearish_leaningr   r   r*   r   Úestimate_next_stateE   s4   
ÿrK   )NNN)Ú__doc__Údataclassesr   r   Úconfig_loaderr   Úregime_enginer3   ÚCHOPÚRANGEr:   ÚACCUMULATIONr8   r6   r7   r;   r5   ÚPULLBACKr4   ÚVWAP_RECLAIMr9   ÚSTRONG_UPTRENDÚWEAK_UPTRENDÚ	DOWNTRENDÚOPENING_VOLATILITYÚDISTRIBUTIONr-   r   r   r   rK   r   r   r   r   Ú<module>   sh    ÿþýüûúùø	÷
öõôóòñðïêö%