def _serialize_entity(self, entity: Entity, filter: Filter, team_id: int) -> List[Dict[str, Any]]: if filter.interval is None: filter.interval = "day" serialized: Dict[str, Any] = { "action": entity.to_dict(), "label": entity.name, "count": 0, "data": [], "labels": [], "days": [], } response = [] events = process_entity_for_events(entity=entity, team_id=team_id, order_by="-timestamp",) events = events.filter(filter_events(team_id, filter, entity)) items = aggregate_by_interval( filtered_events=events, team_id=team_id, entity=entity, filter=filter, breakdown="properties__{}".format(filter.breakdown) if filter.breakdown else None, ) for value, item in items.items(): new_dict = copy.deepcopy(serialized) if value != "Total": new_dict.update(breakdown_label(entity, value)) new_dict.update(append_data(dates_filled=list(item.items()), interval=filter.interval)) if filter.display == TRENDS_CUMULATIVE: new_dict["data"] = np.cumsum(new_dict["data"]) response.append(new_dict) return response
def _serialize_entity(self, entity: Entity, filter: Filter, team_id: int) -> List[Dict[str, Any]]: if filter.interval is None: filter.interval = "day" serialized: Dict[str, Any] = { "action": entity.to_dict(), "label": entity.name, "count": 0, "data": [], "labels": [], "days": [], } response = [] events = process_entity_for_events( entity=entity, team_id=team_id, order_by=None, ) events = events.filter(filter_events(team_id, filter, entity)) new_dict = copy.deepcopy(serialized) new_dict.update( self.stickiness(filtered_events=events, entity=entity, filter=filter, team_id=team_id)) response.append(new_dict) return response
def run(self, filter: Filter, team: Team, *args, **kwargs) -> List[Dict[str, Any]]: if not filter._date_from: filter._date_from = relative_date_parse("-7d") if not filter._date_to: filter._date_to = timezone.now() if filter.interval is None: filter.interval = "day" 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