(cohort: Cohort, team: Team)
'Simplifies' cohort property filters, removing team-specific context from properties.
'Simplifies' cohort property filters, removing team-specific context from properties.
Simplifies cohort property filters removing team - specific context from properties .
def simplified_cohort_filter_properties(cohort: Cohort, team: Team) -> List[Property]:
    """
    'Simplifies' cohort property filters, removing team-specific context from properties.
    """
    from ee.clickhouse.models.cohort import is_precalculated_query

    if cohort.is_static:
        return [Property(type="static-cohort", key="id", value=cohort.pk)]

    # Cohort has been precalculated
    if is_precalculated_query(cohort):
        return [Property(type="precalculated-cohort", key="id", value=cohort.pk)]

    # Cohort can have multiple match groups.
    # Each group is either
    # 1. "user has done X in time range Y at least N times" or
    # 2. "user has properties XYZ", including belonging to another cohort
    #
    # Users who match _any_ of the groups are considered to match the cohort.
    group_filters: List[List[Property]] = []
    for group in cohort.groups:
        if group.get("action_id") or group.get("event_id"):
            # :TODO: Support hasdone as separate property type
            return [Property(type="cohort", key="id", value=cohort.pk)]
        elif group.get("properties"):
            # :TRICKY: This will recursively simplify all the properties
            filter = Filter(data=group, team=team)
            group_filters.append(filter.properties)

    if len(group_filters) > 1:
        # :TODO: Support or properties
        return [Property(type="cohort", key="id", value=cohort.pk)]
    elif len(group_filters) == 1:
        return group_filters[0]
    else:
        return []
def simplified_cohort_filter_properties ( cohort : Cohort , team : Team ) -> List [ Property ] : from ee . clickhouse . models . cohort import is_precalculated_query if cohort . is_static : return [ Property ( type = "static-cohort" , key = "id" , value = cohort . pk ) ] # Cohort has been precalculated if is_precalculated_query ( cohort ) : return [ Property ( type = "precalculated-cohort" , key = "id" , value = cohort . pk ) ] # Cohort can have multiple match groups. # Each group is either # 1. "user has done X in time range Y at least N times" or # 2. "user has properties XYZ", including belonging to another cohort # # Users who match _any_ of the groups are considered to match the cohort. group_filters : List [ List [ Property ] ] = [ ] for group in cohort . groups : if group . get ( "action_id" ) or group . get ( "event_id" ) : # :TODO: Support hasdone as separate property type return [ Property ( type = "cohort" , key = "id" , value = cohort . pk ) ] elif group . get ( "properties" ) : # :TRICKY: This will recursively simplify all the properties filter = Filter ( data = group , team = team ) group_filters . append ( filter . properties ) if len ( group_filters ) > 1 : # :TODO: Support or properties return [ Property ( type = "cohort" , key = "id" , value = cohort . pk ) ] elif len ( group_filters ) == 1 : return group_filters [ 0 ] else : return [ ]