Ejemplo n.º 1
0
    def run(self, filter: Filter, team: Team, *args,
            **kwargs) -> List[Dict[str, Any]]:
        actions = Action.objects.filter(team_id=team.pk).order_by("-id")
        if len(filter.actions) > 0:
            actions = Action.objects.filter(
                pk__in=[entity.id for entity in filter.actions],
                team_id=team.pk)
        actions = actions.prefetch_related(
            Prefetch("steps", queryset=ActionStep.objects.order_by("id")))

        filter = self._set_default_dates(filter, team.pk)

        if filter.formula:
            return handle_compare(filter, self._run_formula_query, team)

        for entity in filter.entities:
            if entity.type == TREND_FILTER_TYPE_ACTIONS:
                try:
                    entity.name = actions.get(id=entity.id).name
                except Action.DoesNotExist:
                    return []

        if len(filter.entities) == 1 or filter.compare:
            result = []
            for entity in filter.entities:
                result.extend(
                    handle_compare(filter,
                                   self._run_query,
                                   team,
                                   entity=entity))
        else:
            result = self._run_parallel(filter, team)

        return result
Ejemplo n.º 2
0
    def run(self, filter: StickinessFilter, team: Team, *args,
            **kwargs) -> List[Dict[str, Any]]:

        response = []
        for entity in filter.entities:
            if entity.type == TREND_FILTER_TYPE_ACTIONS:
                entity.name = Action.objects.only("name").get(
                    team=team, pk=entity.id).name

            entity_resp = handle_compare(filter=filter,
                                         func=self._serialize_entity,
                                         team=team,
                                         entity=entity)
            response.extend(entity_resp)
        return response