Ejemplo n.º 1
0
    def session(self, request: Request, *args: Any, **kwargs: Any) -> Response:

        team = request.user.team
        filter = Filter(request=request)

        limit = int(request.GET.get("limit", SESSIONS_LIST_DEFAULT_LIMIT))
        offset = int(request.GET.get("offset", 0))

        response = ClickhouseSessions().run(team=team,
                                            filter=filter,
                                            limit=limit + 1,
                                            offset=offset)

        if "distinct_id" in request.GET and request.GET["distinct_id"]:
            try:
                person_ids = get_persons_by_distinct_ids(
                    team.pk, [request.GET["distinct_id"]])[0].distinct_ids
                response = [
                    session for i, session in enumerate(response)
                    if response[i]["distinct_id"] in person_ids
                ]
            except IndexError:
                response = []

        if len(response) > limit:
            response.pop()
            return Response({"result": response, "offset": offset + limit})
        else:
            return Response({
                "result": response,
            })
Ejemplo n.º 2
0
 def calculate_session(self, request: Request) -> Dict[str, Any]:
     return {
         "result":
         ClickhouseSessions().run(team=self.team,
                                  filter=SessionsFilter(
                                      request=request,
                                      data={"insight": INSIGHT_SESSIONS}))
     }
Ejemplo n.º 3
0
    def session(self, request: Request, *args: Any, **kwargs: Any) -> Response:
        response = ClickhouseSessions().run(
            team=self.team,
            filter=Filter(request=request, data={"insight": INSIGHT_SESSIONS}))

        return Response({
            "result": response,
        })