
    ZTh=                         d dl mZ d dlmZmZmZmZ d dlZd dlm	Z	 d dl
mZ d dlmZ dee   dee	   fd	Zd
edee	   fdZy)    )Path)AnyDictListcastN)CalculatedChannelConfig)YamlConfigError)_handle_subdirpathsreturnc                     g dt         ffd}| D ]8  }|j                         rt        ||        |j                         s1 ||       : S )a  
    Takes in a list of paths to YAML files which contains calculated channel configs and processes them into a list of
    `CalculatedChannelConfig` objects. For more information on report templates see
    `sift_py.report_templates.config.CalculatedChannelConfig`.
    pathc                 :    j                  t        |              y )N)extend_read_calculated_channels_yaml)r   calculated_channel_configss    e/home/www/backend.miabetepe.com/venv/lib/python3.12/site-packages/sift_py/yaml/calculated_channels.pyupdate_calculated_channelsz<load_calculated_channels.<locals>.update_calculated_channels   s    "))*H*NO    )r   is_dirr
   is_file)r   r   r   r   s      @r   load_calculated_channelsr      sY     ACP P  -;;=4!;<\\^&t,	-
 &%r   r   c           
         g }t        | d      5 }t        t        t        t        f   t        j                  |j                                     }|j                  dg       }|D ]  }t        |t              st        d|  d      |j                  dg       D ]r  }g }t        |t              st        d|  d      d|vr5|j                         D ]!  \  }}	|j                  t        ||	             # n|j                  |       ||d<   t  t        |t              st        d	|  d      |D ]  }	 t        di |}
|j                  |
       ! |cd d d        S # t         $ r}t        d
| d      |d }~ww xY w# 1 sw Y   y xY w)Nrcalculated_channelszFExpected 'calculated_channels' to be a list of dictionaries in yaml: ''channel_referenceszEExpected 'channel_references' to be a list of dictionaries in yaml: 'channel_reference)r   channel_identifierz6Expected 'calculated_channels' to be a list in yaml: 'z"Error parsing calculated channel ' )openr   r   strr   yaml	safe_loadreadget
isinstancedictr	   itemsappendlistr   	Exception)r   r   fchannel_config_yamlcalculated_channel_listcalc_channelchannel_refparsed_channel_refskvcalc_channel_cfges               r   r   r      s   !#	dC  *A"4S>4>>!&&(3KL"5"9"9:OQS"T3 	ILlD1%\]a\bbcd   ,//0DbI I&(#!+t4)_`d_eefg  'k9 + 1 1 3 d1+224!`a3bcd (..{;5H12I	I$ 148!$Z[_Z``a"bcc3 	cLc#:#J\#J *112BC	c *A *  *:  c%(J<.XY&Z[abbc; *  *s0   D"E<2EE<	E9$E44E99E<<F)pathlibr   typingr   r   r   r   r#   "sift_py.calculated_channels.configr   #sift_py.ingestion.config.yaml.errorr	   sift_py.yaml.utilsr
   r   r   r    r   r   <module>r<      sP     ( (  F ? -&DJ &48O3P &&"* "*$7N2O "*r   