
    "i                         d dl Zd Zd Zy)    Nc                     | ddddS 	 d}d}| j                         D ],  }||j                  dd      z  }||j                  dd      z  }. ||z   }|dkD  r||z  nd}|||dS # t        $ r	 ddddcY S w xY w)z
    Extracts Money Flow stats safely.
    Works with the structure from your logs:
    {'1': {'buy':..,'sell':..}, '5':.., '15':..}
    r         ?)buysell	buy_ratior   r   )valuesget	Exception)mf_rawr   r   tf_datatotalr   s         &/var/www/html/tradingbot/indicators.pycalc_mf_statsr      s     ~!#667}} 	+G7;;ua((CGKK**D	+ d
#(19C%K#	 "
 	
  7!#667s   AA$ $A65A6c                    | |yt        dt        d|dz  dz              }t        dt        d|dz  dz              }t        |d	z
        d
z  }	| dz  |	z   |z   |z   }
|dz  |dz  z   |dz  z   }|
|z   }t        dt        d
|            S )uN   
    Calculates 10–90 trend score.
    Tuned using real-trade analysis.
    g      I@i      g      )g      )@i@B g333333@r   Z      
         )maxminabs)smooth_ratior   	cvd_delta	whale_usd	f_mempoolf_feef_blockcvd_term
whale_termbuy_ratio_term
trend_basetrend_onchainfinal_scores                r   calc_trend_scorer'   )   s     y0 3BR2 567H UCy9'<&CDEJ S)B.N 	r		 		  
R			1	  },Kr3r;'((    )numpynpr   r'    r(   r   <module>r,      s    7D*)r(   