Exemplo n.º 1
0
    async def stats(self, id: OrganizationID) -> OrganizationStats:
        await self.get(id)

        metadata_size = 0
        for (vlob_organization_id,
             _), vlob in self._vlob_component._vlobs.items():
            if vlob_organization_id == id:
                metadata_size += sum(len(blob) for (blob, _, _) in vlob.data)

        data_size = 0
        for (vlob_organization_id,
             _), blockmeta in self._block_component._blockmetas.items():
            if vlob_organization_id == id:
                data_size += blockmeta.size

        users = len(self._user_component._organizations[id].users)

        workspaces = len([
            realm_id for organization_id, realm_id in
            self._realm_component._realms.keys() if organization_id == id
        ])

        return OrganizationStats(users=users,
                                 data_size=data_size,
                                 metadata_size=metadata_size,
                                 workspaces=workspaces)
Exemplo n.º 2
0
 async def stats(self, id: OrganizationID) -> OrganizationStats:
     async with self.dbh.pool.acquire() as conn, conn.transaction():
         await self._get(conn, id)  # Check organization exists
         result = await conn.fetchrow(*_q_get_stats(organization_id=id))
     return OrganizationStats(
         users=result["users"],
         data_size=result["data_size"],
         metadata_size=result["metadata_size"],
     )
Exemplo n.º 3
0
    async def stats(self, id: OrganizationID) -> OrganizationStats:
        await self.get(id)

        metadata_size = 0
        for (vlob_organization_id,
             _), vlob in self._vlob_component._vlobs.items():
            if vlob_organization_id == id:
                metadata_size += sum(len(blob) for (blob, _, _) in vlob.data)

        data_size = 0
        for (vlob_organization_id,
             _), blockmeta in self._block_component._blockmetas.items():
            if vlob_organization_id == id:
                data_size += blockmeta.size

        users = 0
        active_users = 0
        users_per_profile_detail = {
            p: {
                "active": 0,
                "revoked": 0
            }
            for p in UserProfile
        }
        for user in self._user_component._organizations[id].users.values():
            users += 1
            if user.revoked_on:
                users_per_profile_detail[user.profile]["revoked"] += 1
            else:
                users_per_profile_detail[user.profile]["active"] += 1
                active_users += 1

        realms = len([
            realm_id for organization_id, realm_id in
            self._realm_component._realms.keys() if organization_id == id
        ])
        users_per_profile_detail = [
            UsersPerProfileDetailItem(profile=profile, **data)
            for profile, data in users_per_profile_detail.items()
        ]

        return OrganizationStats(
            data_size=data_size,
            metadata_size=metadata_size,
            realms=realms,
            users=users,
            active_users=active_users,
            users_per_profile_detail=users_per_profile_detail,
        )
Exemplo n.º 4
0
    async def stats(self, id: OrganizationID) -> OrganizationStats:
        async with self.dbh.pool.acquire() as conn, conn.transaction():
            result = await conn.fetchrow(*_q_get_stats(organization_id=id.str))
            if not result["exist"]:
                raise OrganizationNotFoundError()

            users = 0
            active_users = 0
            users_per_profile_detail = {
                p: {
                    "active": 0,
                    "revoked": 0
                }
                for p in UserProfile
            }
            for u in result["users"]:
                is_revoked, profile = u
                users += 1
                if is_revoked:
                    users_per_profile_detail[
                        UserProfile[profile]]["revoked"] += 1
                else:
                    active_users += 1
                    users_per_profile_detail[
                        UserProfile[profile]]["active"] += 1

            users_per_profile_detail = [
                UsersPerProfileDetailItem(profile=profile, **data)
                for profile, data in users_per_profile_detail.items()
            ]

        return OrganizationStats(
            data_size=result["data_size"],
            metadata_size=result["metadata_size"],
            realms=result["realms"],
            users=users,
            active_users=active_users,
            users_per_profile_detail=users_per_profile_detail,
        )