Ë
    èlÖi¼.  ã                  óž  — d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZmZmZmZ d dlmZ d d	lmZ d d
lmZ d dlmZmZ d dlm Z m!Z! d dl"m#Z#m$Z$m%Z%m&Z& d dl'm(Z(  G d„ dee«      Z) G d„ dee«      Z* G d„ de«      Z+ G d„ de«      Z, G d„ de«      Z- G d„ de«      Z. G d„ de«      Z/ G d„ deeee   «      Z0y) é    )Úannotations)Údeepcopy)ÚAnyÚDictÚListÚOptionalÚSequenceÚSet)Úoverride)Úassert_values_exhausted)ÚParsingException)ÚHashableBaseModelÚModelWithMetadataParsingÚPydanticCustomInputParserÚPydanticParseableValueType)Ú"PydanticSemanticLayerElementConfig)ÚPydanticWhereFilterIntersection)ÚPydanticMetadata)ÚMetricÚProtocolHint)ÚMeasureReferenceÚMetricReference)ÚConversionCalculationTypeÚ
MetricTypeÚPeriodAggregationÚTimeGranularity)ÚFieldc                  ó‚   — e Zd ZU dZded<   ded<   ded<   dZd	ed
<   dZded<   edd„«       Ze	dd„«       Z
e	dd„«       Zy)ÚPydanticMetricInputMeasurezàProvides a pointer to a measure along with metric-specific processing directives.

    If an alias is set, this will be used as the string name reference for this measure after the aggregation
    phase in the SQL plan.
    ÚstrÚnameú)Optional[PydanticWhereFilterIntersection]ÚfilterúOptional[str]ÚaliasFÚboolÚjoin_to_timespineNzOptional[int]Úfill_nulls_withc                ón   — t        |t        «      rt        |¬«      S t        dt	        |«      › d|› �«      ‚)am  Parses a MetricInputMeasure from a string (name only) or object (struct spec) input.

        For user input cases, the original YAML spec for a PydanticMetric included measure(s) specified as string names
        or lists of string names. As such, configs pre-dating the addition of this model type will only provide the
        base name for this object.
        )r!   z€MetricInputMeasure inputs from model configs are expected to be of either type string or object (key/value pairs), but got type ú with value: )Ú
isinstancer    r   Ú
ValueErrorÚtype©ÚclsÚinputs     ús/var/www/html/strategist-ai/venv_dbt/lib/python3.12/site-packages/dbt_semantic_interfaces/implementations/metric.pyÚ_from_yaml_valuez+PydanticMetricInputMeasure._from_yaml_value/   sB   € ô �eœSÔ!Ü-°5Ô9Ð9äð:Ü:>¸u»+¸ÀmÐTYÐSZð\óð ó    c                ó.   — t        | j                  ¬«      S )zXProperty accessor to get the MeasureReference associated with this metric input measure.©Úelement_name)r   r!   ©Úselfs    r1   Úmeasure_referencez,PydanticMetricInputMeasure.measure_reference?   s   € ô  ¨T¯Y©YÔ7Ð7r3   c                óJ   — t        | j                  xs | j                  ¬«      S )zTProperty accessor to get the MeasureReference with the aliased name, if appropriate.r5   )r   r%   r!   r7   s    r1   Ú"post_aggregation_measure_referencez=PydanticMetricInputMeasure.post_aggregation_measure_referenceD   s   € ô  ¨T¯Z©ZÒ-D¸4¿9¹9ÔEÐEr3   )r0   r   Úreturnr   )r<   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r'   r(   Úclassmethodr2   Úpropertyr9   r;   © r3   r1   r   r   "   sk   … ñð ƒIØ5Ó5ØÓØ#Ð�tÓ#Ø%)€O�]Ó)àòó ðð ò8ó ð8ð òFó ñFr3   r   c                  ón   — e Zd ZU dZded<   ded<   edd„«       Zedd„«       Zedd„«       Z	e
dd	„«       Zy
)ÚPydanticMetricTimeWindowzbDescribes the window of time the metric should be accumulated over, e.g., '1 day', '2 weeks', etc.ÚintÚcountr    Úgranularityc                óž   — t        |t        «      r$t        j                  |j	                  «       ¬«      S t        dt        |«      › d|› �«      ‚)zÎParses a MetricTimeWindow from a string input found in a user provided model specification.

        The MetricTimeWindow is always expected to be provided as a string in user-defined YAML configs.
        )ÚwindowzbMetricTimeWindow inputs from model configs are expected to always be of type string, but got type r*   )r+   r    rF   ÚparseÚlowerr,   r-   r.   s     r1   r2   z)PydanticMetricTimeWindow._from_yaml_valueP   sN   € ô �eœSÔ!Ü+×1Ñ1¸¿¹»Ð1ÓGÐGäðÜ˜U›�} M°%°ð:óð r3   c                ó˜   — | j                   j                  «       t        D �ch c]  }|j                  j                  «       ’Œ c}v S c c}w )z9Returns whether the window uses standard TimeGranularity.)rI   Úcasefoldr   Úvalue)r8   Úitems     r1   Úis_standard_granularityz0PydanticMetricTimeWindow.is_standard_granularity^   s:   € ð ×Ñ×(Ñ(Ó*ÔQ`Ö.aÈ¨t¯z©z×/BÑ/BÕ/DÒ.aÐaÐaùÒ.as   ¢!Ac                ó8   — | j                   › d| j                  › �S )z,Returns the string value of the time window.ú ©rH   rI   r7   s    r1   Úwindow_stringz&PydanticMetricTimeWindow.window_stringc   s    € ð —*‘*�˜Q˜t×/Ñ/Ð0Ð1Ð1r3   c                óþ   — | j                  «       j                  d«      }t        |«      dk7  rt        d| › d�«      ‚|d   }|d   }|j	                  «       st        d|› d| › d	�«      ‚t        t        |«      |¬
«      S )z:Returns window values if parsing succeeds, None otherwise.rT   é   zInvalid window (zV) in cumulative metric. Should be of the form `<count> <granularity>`, e.g., `28 days`é   r   zInvalid count (z') in cumulative metric window string: (ú)rU   )rM   ÚsplitÚlenr   ÚisdigitrF   rG   )rK   ÚpartsrI   rH   s       r1   rL   zPydanticMetricTimeWindow.parseh   s•   € ð —‘“×$Ñ$ SÓ)ˆÜˆu‹:˜Š?Ü"Ø" 6 (ð +"ð "óð ð
 ˜A‘hˆØ�a‘ˆØ�}‰}ŒÜ" _°U°GÐ;bÐciÐbjÐjkÐ#lÓmÐmä'Ü�e“*Ø#ô
ð 	
r3   N)r0   r   r<   rF   )r<   r&   )r<   r    )rK   r    r<   rF   )r=   r>   r?   r@   rA   rB   r2   rC   rR   rV   ÚstaticmethodrL   rD   r3   r1   rF   rF   J   s`   … ÙlàƒJØÓàòó ðð òbó ðbð ò2ó ð2ð ò
ó ñ
r3   rF   c                  ó&   — e Zd ZU dZded<   ded<   y)ÚPydanticConstantPropertyInputz8Input of a constant property used in conversion metrics.r    Úbase_propertyÚconversion_propertyN)r=   r>   r?   r@   rA   rD   r3   r1   ra   ra   }   s   … ÙBàÓØÔr3   ra   c                  óh   — e Zd ZU dZded<   ded<   ded<   ded	<   ded
<   edd„«       Zedd„«       Zy)ÚPydanticMetricInputzXProvides a pointer to a metric along with the additional properties used on that metric.r    r!   r"   r#   r$   r%   ú"Optional[PydanticMetricTimeWindow]Úoffset_windowÚoffset_to_grainc                ó.   — t        | j                  ¬«      S )zOProperty accessor to get the MetricReference associated with this metric input.r5   )r   r!   r7   s    r1   Úas_referencez PydanticMetricInput.as_reference�   s   € ô ¨D¯I©IÔ6Ð6r3   c                óJ   — t        | j                  xs | j                  ¬«      S )zSProperty accessor to get the MetricReference with the aliased name, if appropriate.r5   )r   r%   r!   r7   s    r1   Úpost_aggregation_referencez.PydanticMetricInput.post_aggregation_reference’   s   € ô ¨D¯J©JÒ,C¸$¿)¹)ÔDÐDr3   N)r<   r   )r=   r>   r?   r@   rA   rC   rj   rl   rD   r3   r1   re   re   „   sJ   … Ùbà
ƒIØ5Ó5ØÓØ5Ó5Ø"Ó"àò7ó ð7ð òEó ñEr3   re   c                  óf   — e Zd ZU dZded<   ded<   ded<   ej                  Zded<   d	ed
<   ded<   y)ÚPydanticConversionTypeParamszAType params to provide context for conversion metrics properties.r   Úbase_measureÚconversion_measurer    Úentityr   Úcalculationrf   rK   z-Optional[List[PydanticConstantPropertyInput]]Úconstant_propertiesN)r=   r>   r?   r@   rA   r   ÚCONVERSION_RATErr   rD   r3   r1   rn   rn   ˜   s3   … ÙKà,Ó,Ø2Ó2ØƒKØ-F×-VÑ-V€KÐ*ÓVØ.Ó.ØFÔFr3   rn   c                  óH   — e Zd ZU dZded<   ded<   ej                  Zded<   y)	ÚPydanticCumulativeTypeParamszAType params to provide context for cumulative metrics properties.rf   rK   r$   Úgrain_to_dater   Ú
period_aggN)r=   r>   r?   r@   rA   r   ÚFIRSTrx   rD   r3   r1   rv   rv   £   s"   … ÙKà.Ó.Ø Ó Ø$5×$;Ñ$;€JÐ!Ô;r3   rv   c                  óˆ   — e Zd ZU dZded<   ded<   ded<   ded<   d	ed
<   ded<   ded<   ded<   ded<    ee¬«      Zded<   y)ÚPydanticMetricTypeParamszdType params add additional context to certain metric types (the context depends on the metric type).z$Optional[PydanticMetricInputMeasure]ÚmeasurezOptional[PydanticMetricInput]Ú	numeratorÚdenominatorr$   Úexprrf   rK   zOptional[TimeGranularity]rw   z#Optional[List[PydanticMetricInput]]Úmetricsz&Optional[PydanticConversionTypeParams]Úconversion_type_paramsz&Optional[PydanticCumulativeTypeParams]Úcumulative_type_params)Údefault_factoryz List[PydanticMetricInputMeasure]Úinput_measuresN)r=   r>   r?   r@   rA   r   Úlistr„   rD   r3   r1   r{   r{   «   sK   … Ùnà1Ó1Ø,Ó,Ø.Ó.Ø
Óà.Ó.à,Ó,Ø0Ó0ØBÓBØBÓBá7<ÈTÔ7R€NÐ4ÔRr3   r{   c                  óø   ‡ — e Zd ZU dZedd„«       Zded<   ded<   ded<   d	ed
<   ded<   ded<   dZded<   ded<   dZded<   e	dˆ fd„«       Z
edd„«       Zedd„«       Zedd„«       Ze	 	 	 	 	 	 dd„«       Zˆ xZS )ÚPydanticMetriczDescribes a metric.c                ó   — | S )NrD   r7   s    r1   Ú_implements_protocolz#PydanticMetric._implements_protocolÀ   s   € àˆr3   r    r!   r$   Údescriptionr   r-   r{   Útype_paramsr"   r#   zOptional[PydanticMetadata]ÚmetadataNÚlabelz,Optional[PydanticSemanticLayerElementConfig]ÚconfigÚtime_granularityc                óª  •— t        |«      }|j                  d«      xs i }|j                  d«      xs i j                  d«      }t        |t        «      r|j	                  «       |d   d   d<   |j                  dg «      }|r?|D ]:  }|j                  d«      }|sŒt        |t        «      sŒ(|j	                  «       |d<   Œ< t
        t        | �  |«      S )z*Adds custom parsing to the default method.r‹   r‚   rw   r€   rh   )r   Úgetr+   r    rM   Úsuperr   Ú	parse_obj)	r/   r0   Údatar‹   rw   Úinput_metricsÚinput_metricrh   Ú	__class__s	           €r1   r“   zPydanticMetric.parse_objÎ   sÖ   ø€ ô ˜‹ˆð —h‘h˜}Ó-Ò3°ˆØ$Ÿ™Ð)AÓBÒHÀb×MÑMÈoÓ^ˆÜ�m¤SÔ)ØMZ×M`ÑM`ÓMbˆD�ÑÐ 8Ñ9¸/ÑJð $Ÿ™¨	°2Ó6ˆÙØ -ò N�Ø".×"2Ñ"2Ð3DÓ"E�Ú"¤z°/Ä3Õ'GØ6E×6KÑ6KÓ6M�LÐ!2Ò3ðNô
 Ô&¨Ñ6°tÓ<Ð<r3   c                ó.   — | j                   j                  S )zIReturn the complete list of input measure configurations for this metric.)r‹   r„   r7   s    r1   r„   zPydanticMetric.input_measuresã   s   € ð ×Ñ×.Ñ.Ð.r3   c                óT   — | j                   D �cg c]  }|j                  ‘Œ c}S c c}w )z_Return the measure references associated with all input measure configurations for this metric.)r„   r9   )r8   Úxs     r1   Úmeasure_referencesz!PydanticMetric.measure_referencesè   s$   € ð .2×-@Ñ-@ÖA¨�×#Ó#ÒAÐAùÒAs   �%c                ó¶  — | j                   t        j                  u s8| j                   t        j                  u s| j                   t        j                  u ry| j                   t        j
                  u rD| j                  j                  €J t        j
                  › d�«       ‚| j                  j                  S | j                   t        j                  u rs| j                  j                  �| j                  j                  €J | › dt        j                  › d�«       ‚| j                  j                  | j                  j                  fS t        | j                   «       y)z4Return the associated input metrics for this metric.rD   Nz$ should have type_params.metrics setz is metric type z=, so neither the numerator and denominator should not be None)r-   r   ÚSIMPLEÚ
CUMULATIVEÚ
CONVERSIONÚDERIVEDr‹   r€   ÚRATIOr}   r~   r   r7   s    r1   r•   zPydanticMetric.input_metricsí   s  € ð �9‰9œ
×)Ñ)Ñ)¨T¯Y©Y¼*×:OÑ:OÑ-OÐSW×S\ÑS\Ô`j×`uÑ`uÑSuØØ�Y‰Yœ*×,Ñ,Ñ,Ø×#Ñ#×+Ñ+Ð7Ðt¼J×<NÑ<NÐ;OÐOsÐ9tÓtÐ7Ø×#Ñ#×+Ñ+Ð+Ø�Y‰Yœ*×*Ñ*Ñ*à× Ñ ×*Ñ*Ð6¸4×;KÑ;K×;WÑ;WÐ;cðxà�Ð'¬
×(8Ñ(8Ð'9Ð9vÐwóxØcà×$Ñ$×.Ñ.°×0@Ñ0@×0LÑ0LÐMÐMä# D§I¡IÕ.r3   c                óÀ  — t        «       }| j                  t        j                  u s| j                  t        j                  u r\| j
                  j                  €J d| j                  › d�«       ‚|j                  | j
                  j                  j                  «       |S | j                  t        j                  u s| j                  t        j                  u rk| j                  D ]Z  }|j                  |j                  «      }|sJ d|j                  › d�«       ‚|j                  t         j#                  ||¬«      «       Œ\ |S | j                  t        j$                  u rk| j
                  j&                  }|sJ d«       ‚|j                  |j(                  j                  «       |j                  |j*                  j                  «       |S t-        | j                  «       |S )z_Gets all input measures for the metric, including those defined on input metrics (recursively).zMetric z0 should have a measure defined, but it does not.zCould not find metric z in semantic manifest.)ÚmetricÚmetric_indexz5Conversion metric should have conversion_type_params.)Úsetr-   r   r�   rž   r‹   r|   r!   Úaddr9   r    r¡   r•   r‘   rj   Úupdater‡   Úall_input_measures_for_metricrŸ   r�   ro   rp   r   )r£   r¤   Úmeasuresr–   Únested_metricr�   s         r1   r¨   z,PydanticMetric.all_input_measures_for_metricý   sœ  € ô
 +.«%ˆØ�;‰;œ*×+Ñ+Ñ+¨v¯{©{¼j×>SÑ>SÑ/Sà×"Ñ"×*Ñ*Ð6ðWà˜Ÿ™˜Ð%UÐVóWØ6à�L‰L˜×+Ñ+×3Ñ3×EÑEÔFð  ˆð �[‰[œJ×.Ñ.Ñ.°&·+±+Ä×AQÑAQÑ2QØ &× 4Ñ 4ò �Ø ,× 0Ñ 0°×1JÑ1JÓ K�Ù$ÐhÐ(>¸|×?PÑ?PÐ>QÐQgÐ&hÓh�}Ø—‘Ü"×@Ñ@ÈÐdpÐ@Óqõðð ˆð �[‰[œJ×1Ñ1Ñ1Ø%+×%7Ñ%7×%NÑ%NÐ"Ù)ÐbÐ+bÓbÐ)Ø�L‰LÐ/×<Ñ<×NÑNÔOØ�L‰LÐ/×BÑB×TÑTÔUð ˆô $ F§K¡KÔ0àˆr3   )r<   r   )r0   r   r<   r‡   )r<   z$Sequence[PydanticMetricInputMeasure])r<   zList[MeasureReference])r<   zSequence[PydanticMetricInput])r£   r   r¤   zDict[MetricReference, Metric]r<   zSet[MeasureReference])r=   r>   r?   r@   r   r‰   rA   r�   r�   rB   r“   rC   r„   r›   r•   r_   r¨   Ú__classcell__)r—   s   @r1   r‡   r‡   ½   sÔ   ø… Ùàòó ðð ƒIØÓØ
ÓØ)Ó)Ø5Ó5Ø(Ó(Ø€Eˆ=ÓØ8Ó8Ø&*Ð�mÓ*àô=ó ð=ð( ò/ó ð/ð òBó ðBð ò/ó ð/ð ðØðØ&Cðà	òó ôr3   r‡   N)1Ú
__future__r   Úcopyr   Útypingr   r   r   r   r	   r
   Útyping_extensionsr   Ú&dbt_semantic_interfaces.enum_extensionr   Údbt_semantic_interfaces.errorsr   Ú,dbt_semantic_interfaces.implementations.baser   r   r   r   Ú6dbt_semantic_interfaces.implementations.element_configr   Ú<dbt_semantic_interfaces.implementations.filters.where_filterr   Ú0dbt_semantic_interfaces.implementations.metadatar   Ú!dbt_semantic_interfaces.protocolsr   r   Ú"dbt_semantic_interfaces.referencesr   r   Ú"dbt_semantic_interfaces.type_enumsr   r   r   r   Údsi_pydantic_shimr   r   rF   ra   re   rn   rv   r{   r‡   rD   r3   r1   ú<module>rº      sÍ   ðÝ "å ß ;× ;å &å JÝ ;÷ó õõõ Nß Bß P÷ó õ $ô%FÐ!:Ð<Mô %FôP0
Ð8Ð:Kô 0
ôfÐ$5ô ôEÐ+ô Eô(GÐ#4ô Gô<Ð#4ô <ôSÐ0ô Sô$ZÐ&Ð(@À,ÈvÑBVõ Zr3   