Ë
    LµCjQ  ã                   óî   — d Z ddlZddlZddlmZmZ ddlmZ ddlmZ  ej                  ej                  d¬«       ded	ej                  fd
„Zdededeeef   dee   deded	dfd„Zddededed	dfd„Zy)uç   
Shared training utilities.

Common helpers used across all training scripts in this directory â€”
kept here once rather than copy-pasted six times, so a fix (e.g. to how
model metadata is saved) only needs to happen in one place.
é    N)ÚdatetimeÚtimezone)ÚPath)ÚAnyz%%(asctime)s %(levelname)s %(message)s)ÚlevelÚformatÚnameÚreturnc                 ó,   — t        j                  | «      S )N)ÚloggingÚ	getLogger)r	   s    úPC:\Crop_Prediction\Backend\crop-ai-system\ml_pipeline\training\training_utils.pyÚ
get_loggerr      s   € Ü×Ñ˜TÓ"Ð"ó    Ú
output_dirÚ
model_nameÚmetricsÚfeature_colsÚn_trainÚn_testc                 ó  — |t        j                  t        j                  «      j	                  «       ||||dœ}| |› d�z  }t        |dd¬«      5 }t        j                  ||dt        ¬«       ddd«       y# 1 sw Y   yxY w)	u  
    Writes a metadata JSON alongside every .pkl artifact â€” this is what
    lets you (or the client) audit exactly when a model was trained, on
    how much data, and what its validation metrics were, without having
    to re-run training or dig through terminal scrollback.
    )r   Útrained_at_utcÚn_train_samplesÚn_test_samplesÚfeature_columnsr   z_metadata.jsonÚwzutf-8)Úencodingé   )ÚindentÚdefaultN)	r   Únowr   ÚutcÚ	isoformatÚopenÚjsonÚdumpÚstr)	r   r   r   r   r   r   ÚmetadataÚmetadata_pathÚfs	            r   Úsave_training_metadatar+      s{   € ð !Ü"Ÿ,™,¤x§|¡|Ó4×>Ñ>Ó@Ø"Ø Ø'Øñ€Hð  J <¨~Ð!>Ñ>€MÜ	ˆm˜S¨7Ô	3ð 6°qÜ�	‰	�(˜A a´Õ5÷6÷ 6ñ 6ús   ÁA6Á6A?Údf_lenÚminimumc           	      ó8   — | |k  rt        d| › d|› d|› d�«      ‚y )NzOnly z! samples available for training 'z', minimum required is u‹   . Training on fewer samples than this produces unreliable models â€” collect more data or lower this threshold deliberately (not silently).)Ú
ValueError)r,   r   r-   s      r   Úcheck_minimum_samplesr0   1   s?   € Ø�ÒÜØ�F�8Ð<¸Z¸Lð I#Ø#* )ð ,:ð;ó
ð 	
ð r   )éd   )Ú__doc__r%   r   r   r   Úpathlibr   Útypingr   ÚbasicConfigÚINFOr'   ÚLoggerr   ÚdictÚlistÚintr+   r0   © r   r   ú<module>r<      s½   ðñó Û ß 'Ý Ý à €× Ñ ˜'Ÿ,™,Ð/VÕ Wð#�Sð #˜WŸ^™^ó #ð6Øð6àð6ð �#�s�(‰^ð6ð �s‘)ð	6ð
 ð6ð ð6ð 
ó6ñ6
 #ð 
°3ð 
Àð 
Ètô 
r   