# Identities & Accounts

The identity and account metrics aim to provide an understanding of the involvement and behavior of participants on the network.

| Metric Category | Metric                                  | Metric Description                                                                                      |
| --------------- | --------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| Identities      | Nb of identities                        | Total number of identities created on the network                                                       |
| Identities      | Identities created by month             | Number to identities created per month                                                                  |
| Identities      | Average number of accounts per identity | Average number of accounts related to identities                                                        |
| Identities      | Max accounts - Identity                 | Identity associated with the highest number of accounts on the network.                                 |
| Identities      | Average number of assets by identity    | Average number of assets by identity                                                                    |
| Identities      | Max assets - Identity                   | Identity holding the highest number of assets                                                           |
| Identities      | Max  Legs - Identity                    | The identity involved in the most number of legs (settlement legs) across both the from\_id and to\_id. |

## Nb of identities

This metric reflects the growth and adoption of the Polymesh network by indicating how many unique entities are participating. It's helpful for gauging overall ecosystem health and expansion.

**How many participants are on the network ?**

<mark style="color:purple;">**SQL**</mark>

```
SELECT COUNT(DISTINCT did)
FROM identities
```

<figure><img src="https://243096197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEJbeWS9CeNvCKkvrw412%2Fuploads%2FpaA9thbuTKjWR3Usy6iJ%2Fimage.png?alt=media&#x26;token=e89e4d38-10cb-4136-8e0f-9e54510dde21" alt=""><figcaption></figcaption></figure>

<mark style="color:purple;">**GraphQL**</mark>

```
query {
  identities {
    totalCount
  }
}
```

<figure><img src="https://243096197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEJbeWS9CeNvCKkvrw412%2Fuploads%2F9hg7j1PMliUJFBORP8NN%2Fimage.png?alt=media&#x26;token=ed6af965-c703-43d6-aa2a-5fadf79d5f79" alt=""><figcaption></figcaption></figure>

## Identities created by month

This metric offers insights into the growth trend of network participation over time. Tracking identities created each month can help identify patterns, seasonal fluctuations, or the impact of specific events on network adoption. The rate of new identity creation can serve as an indirect measure of market sentiment and the attractiveness of the Polymesh network to potential users. A steady or increasing rate of new identities may indicate positive sentiment and growing interest.

**How is the Polymesh network growing in terms of new participants?**

<mark style="color:purple;">**SQL**</mark>

```
SELECT COUNT(*) as "nb Identities", DATE_TRUNC('month', datetime) AS createdMonth
FROM identities
GROUP BY createdMonth
ORDER BY createdMonth ASC
```

<figure><img src="https://243096197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEJbeWS9CeNvCKkvrw412%2Fuploads%2FSJq3eUBYNFCfOXvrgiBo%2Fimage.png?alt=media&#x26;token=91a8fefb-ed10-4ce7-9df6-b312bb8cd511" alt=""><figcaption><p>Identities created by month</p></figcaption></figure>

<mark style="color:purple;">**GraphQL**</mark>

```
query {
  identities {
    nodes {
      createdBlock {
        datetime
      }
    }
  }
}
```

This query retrieves all the identities along with their corresponding `createdBlock.datetime` field. Since the provided schema doesn't support aggregation and grouping directly in the query, you'll need to handle the grouping and counting of identities by month in the application code.

{% hint style="info" %}
**Possible improvement #10**

To support the query for counting identities grouped by creation month directly in GraphQL, . one idea could be to modify the schema by introducing a new entity called `IdentityAggregateByMonth and then`modify the `Identity` entity to include a reference to the `IdentityAggregateByMonth.`
{% endhint %}

## Average number of accounts per identity

This metric provides an understanding of how identities typically distribute their activities across multiple accounts. A higher average could indicate a preference or need for compartmentalization of operations within the network. A higher average suggests that identities typically manage multiple accounts, indicating a robust engagement with the network's features and capabilities.

**How actively are identities engaging with the network?**&#x20;

<mark style="color:purple;">**SQL**</mark>

```
SELECT 
    AVG(account_count) AS "Average Accounts per Identity"
FROM (
    SELECT 
        identity_id,
        COUNT(id) AS account_count
    FROM 
        accounts
    GROUP BY 
        identity_id
) AS counts;
```

<mark style="color:purple;">**GraphQL**</mark>

```
query {
  accounts {
    nodes {
      identity {
        id
      }
    }
  }
}
```

This query retrieves all the accounts along with their associated identity ID then it will necessary to process the results to calculate the average number of accounts per identity.

{% hint style="info" %}
**Possible improvement #11**

To support the query for calculating the average number of accounts per identity directly in GraphQL, one idea could be to modify the schema by introducing a new field in the `Query` type.  Add the `averageAccountsPerIdentity` field to the `Query` type then Implement the resolver for the `averageAccountsPerIdentity` field in your GraphQL server.&#x20;
{% endhint %}

## Max accounts - Identity

This metric highlights the identity with the most accounts, which could be indicative of a major player in the ecosystem or a specific operational strategy that involves managing numerous accounts. An identity with a significantly high number of accounts could indicate a business or organizational user leveraging the Polymesh network for various operations, reflecting on the network's utility for complex organizational structures.

**What does the distribution of accounts across identities tell us about how the network is being used?**&#x20;

<mark style="color:purple;">**SQL**</mark>

```
SELECT 
    identity_id,
    COUNT(id) AS account_count
FROM 
    accounts
GROUP BY 
    identity_id
ORDER BY 
    account_count DESC
LIMIT 1;
```

<figure><img src="https://243096197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEJbeWS9CeNvCKkvrw412%2Fuploads%2FfnjTwnM81tFf001CUUZ1%2Fimage.png?alt=media&#x26;token=2269ec5f-f48d-4159-95f7-d859ff2c3efe" alt=""><figcaption><p>Max accounts - Identity</p></figcaption></figure>

<mark style="color:purple;">**GraphQL**</mark>

```
query {
  identities(first: 1, orderBy: SECONDARY_ACCOUNTS_COUNT_DESC) {
    nodes {
      id
      secondaryAccounts {
        totalCount
      }
    }
  }
}
```

<figure><img src="https://243096197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEJbeWS9CeNvCKkvrw412%2Fuploads%2FKUIyPmOVtggGzYLz19BP%2Fimage.png?alt=media&#x26;token=f7d24604-e3fb-414d-85e7-c1b01554d789" alt=""><figcaption></figcaption></figure>

## Average number of assets by identity

This metric offers insights into how involved or invested the average identity is in terms of asset holdings. This metric can help understand the depth of engagement within the Polymesh ecosystem. A higher average number of assets per identity suggests that entities tend to hold a broader range of assets.

**How much do participants diversify asset holdings on the network?**&#x20;

<mark style="color:purple;">**SQL**</mark>

```
SELECT 
    AVG(asset_count) AS "Average Assets per Identity"
FROM (
    SELECT 
        identity_id,
        COUNT(DISTINCT asset_id) AS asset_count
    FROM 
        asset_holders
    GROUP BY 
        identity_id
) AS counts;
```

<figure><img src="https://243096197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEJbeWS9CeNvCKkvrw412%2Fuploads%2FgbL8MzPEn1PJRowQBGjl%2Fimage.png?alt=media&#x26;token=b1ded7e4-3206-4602-a145-74e137e26f88" alt=""><figcaption><p>Average number of assets by identity</p></figcaption></figure>

<mark style="color:purple;">**GraphQL**</mark>

```
query {
  assetHolders {
    nodes {
      identity {
        id
      }
      asset {
        id
      }
    }
  }
}
```

This query retrieves all the asset holders along with their associated identity ID and asset ID. The result will then need to be processed to calculate the average number of assets per identity.

{% hint style="info" %}
**Possible improvement #12**

To support the query for calculating the average number of assets per identity directly in GraphQL, one idea could be to modify the schema by introducing a new field in the `Query` type .Add the `averageAssetsPerIdentity` field to the `Query` type and then Implement the resolver for the `averageAssetsPerIdentity` field in your GraphQL server.
{% endhint %}

## Max assets - Identity

This metric identifies the identity holding the highest number of assets, which could point to a significant investor or a key institutional participant. This metric can be useful for identifying major stakeholders in the network. The identity holding the most assets may have considerable influence over market liquidity, asset prices, and overall market sentiment, depending on the types and quantities of assets held.

**Which identity has the potential to significantly influence the market?**&#x20;

<mark style="color:purple;">**SQL**</mark>

```
SELECT 
    identity_id,
    COUNT(DISTINCT asset_id) AS asset_count
FROM 
    asset_holders
GROUP BY 
    identity_id
ORDER BY 
    asset_count DESC
LIMIT 1;
```

<figure><img src="https://243096197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEJbeWS9CeNvCKkvrw412%2Fuploads%2FoQZnzaf0kEznHlvcDg9k%2Fimage.png?alt=media&#x26;token=1a428fed-560e-4e3e-a6a9-b89e95807609" alt=""><figcaption></figcaption></figure>

<mark style="color:purple;">**GraphQL**</mark>

```
query {
  identities(first: 1, orderBy: HELD_ASSETS_COUNT_DESC) {
    nodes {
      id
      heldAssets {
        totalCount
      }
    }
  }
}
```

<figure><img src="https://243096197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEJbeWS9CeNvCKkvrw412%2Fuploads%2Fnh6mD1zZVqjWcYUIDZiT%2Fimage.png?alt=media&#x26;token=115011cb-494d-4d80-bff5-eaa315a7c31e" alt=""><figcaption></figcaption></figure>

## Max  Legs - Identity

This metric identifies the identity involved in the highest number of settlement legs (as either the sender or receiver). By identifying the identity with the highest number of settlement legs, it provides insights into which entity is potentially facilitating or engaging in a significant portion of the network's liquidity and asset transfers.

**Who is the Most Active Participant in the Settlement Process?**

<mark style="color:purple;">**SQL**</mark>

```
SELECT 
    id, 
    COUNT(*) AS occurrences
FROM (
    SELECT 
        from_id AS id
    FROM 
        legs
    WHERE 
        from_id IS NOT NULL

    UNION ALL

    SELECT 
        to_id AS id
    FROM 
        legs
    WHERE 
        to_id IS NOT NULL
) AS combined
GROUP BY 
    id
ORDER BY 
    occurrences DESC
LIMIT 1;
```

<figure><img src="https://243096197-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEJbeWS9CeNvCKkvrw412%2Fuploads%2FdQ0sV4aqAk96j2ihpf5s%2Fimage.png?alt=media&#x26;token=0f68754b-0eb5-460d-974a-7947ce883371" alt=""><figcaption><p>Max Legs - Identity</p></figcaption></figure>

<mark style="color:purple;">**GraphQL**</mark>

```
query {
  legs {
    nodes {
      from {
        id
      }
      to {
        id
      }
    }
  }
}
```

This query retrieves all the legs along with their associated `from` and `to` portfolios' IDs. The result will then need to be processed to find the ID with the maximum occurrences.
