Exemple #1
0
    def to_husky(origin: PanoField) -> Taxon:
        """Maps external field definitions to internal taxon representation"""

        slug = origin.slug if origin.data_source is None else f'{origin.data_source}{NAMESPACE_DELIMITER}{origin.slug}'
        aggregation = None
        if origin.aggregation:
            aggregation = AggregationDefinition.parse_obj(
                origin.aggregation.to_dict())

        validation = EnumHelper.from_value(ValidationType, origin.data_type)
        assert validation

        return Taxon(
            slug=slug,
            taxon_group=origin.group,
            display_name=origin.display_name,
            taxon_type=origin.field_type,
            validation_type=validation,
            taxon_description=origin.description,
            data_source=origin.data_source,
            calculation=origin.calculation,
            aggregation=aggregation,
            display_state=DisplayState.visible,
            company_id=get_company_id(),
        )
 def _parse_taxon_expr(
     ctx: HuskyQueryContext,
     taxon: Taxon,
     tel_prefix: str,
     data_sources: Iterable[str],
     all_taxons: TaxonMap,
     subrequest_only=False,
 ):
     taxon_type = EnumHelper.from_value(TaxonTypeEnum, taxon.taxon_type)
     try:
         return TaxonTelDialect().render(
             expr=cast(str, taxon.calculation),
             ctx=ctx,
             taxon_map=all_taxons,
             taxon_slug=tel_prefix,
             comparison=taxon.is_comparison_taxon,
             data_sources=data_sources,
             taxon_type=taxon_type,
             aggregation=taxon.aggregation,
             subrequest_only=subrequest_only,
         )
     except TelExpressionException as error:
         raise HuskyInvalidTelException(error, taxon.slug)