def session(self, request: request.Request, *args: Any, **kwargs: Any) -> Response: from posthog.queries.sessions import SESSIONS_LIST_DEFAULT_LIMIT team = self.team filter = SessionsFilter(request=request) limit = SESSIONS_LIST_DEFAULT_LIMIT + 1 result: Dict[str, Any] = { "result": sessions.Sessions().run(filter=filter, team=team, limit=limit) } if filter.distinct_id: result = self._filter_sessions_by_distinct_id( filter.distinct_id, result) if filter.session_type is None: offset = filter.offset + limit - 1 if len(result["result"]) > SESSIONS_LIST_DEFAULT_LIMIT: result["result"].pop() date_from = result["result"][0]["start_time"].isoformat() result.update({OFFSET: offset}) result.update({DATE_FROM: date_from}) return Response(result)
def session(self, request: request.Request, *args: Any, **kwargs: Any) -> Response: team = self.request.user.team_set.get() filter = Filter(request=request) result: Dict[str, Any] = {"result": sessions.Sessions().run(filter, team)} # add pagination if filter.session_type is None: offset = filter.offset + 50 if len(result["result"]) > 49: date_from = result["result"][0]["start_time"].isoformat() result.update({OFFSET: offset}) result.update({DATE_FROM: date_from}) return Response(result)
def calculate_session(self, request: request.Request) -> Dict[str, Any]: team = self.request.user.team filter = Filter(request=request) result: Dict[str, Any] = {"result": sessions.Sessions().run(filter, team)} if "distinct_id" in request.GET and request.GET["distinct_id"]: result = self._filter_sessions_by_distinct_id(request.GET["distinct_id"], result) # add pagination if filter.session_type is None: offset = filter.offset + 50 if len(result["result"]) > 49: date_from = result["result"][0]["start_time"].isoformat() result.update({OFFSET: offset}) result.update({DATE_FROM: date_from}) return result
def session(self, request: request.Request, *args: Any, **kwargs: Any) -> Response: team = self.request.user.team filter = Filter(request=request) limit = SESSIONS_LIST_DEFAULT_LIMIT + 1 result: Dict[str, Any] = { "result": sessions.Sessions().run(filter=filter, team=team, limit=limit) } # add pagination if filter.session_type is None: offset = filter.offset + limit - 1 if len(result["result"]) > SESSIONS_LIST_DEFAULT_LIMIT: result["result"].pop() date_from = result["result"][0]["start_time"].isoformat() result.update({OFFSET: offset}) result.update({DATE_FROM: date_from}) return Response(result)
def calculate_session(self, request: request.Request) -> List[Dict[str, Any]]: return sessions.Sessions().run(filter=SessionsFilter(request=request), team=self.team)