> ## Documentation Index
> Fetch the complete documentation index at: https://docs.opigno.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Ranking by the number of passed trainings

User ranking by the number of passed trainings is available as a part of gamification in Opigno Enterprise.
Calculation rules:

1. The ranking is calculated based on the number of successfully completed (passed) trainings.
2. The average score is used as a secondary factor for the ranking calculation.
3. Users associated with an ANONYMOUS scope are excluded from the ranking system.

## PassedTrainingsRanking object

On the API level user ranking based on the passed trainings is represented by `PassedTrainingsRanking` data type.

| Parameter                  | Type    | Description                                                                                            |
| :------------------------- | :------ | :----------------------------------------------------------------------------------------------------- |
| `rank`                     | `Int`   | **Required**. The user's rank based on the number of passed trainings and an average score.            |
| `averageScore`             | `Float` | **Required**. The average score obtained by the user for all completed (passed and failed) trainings.  |
| `passedTrainingsNumber`    | `Int`   | **Required**. The number of the trainings successfully passed by the user associated with the context. |
| `completedTrainingsNumber` | `Int`   | **Required**. The number of the trainings completed by the user associated with the context.           |

## Retrieve the ranking

`UserContext` API object contains property `passedTrainingsRanking`.

Also, ranking can be retrieved by calling the `getUserPassedTrainingsRanking` query.
It has one optional argument - `userContextUuid`. If it's not set, the current API user context will be used by default.
The query returns a `PassedTrainingsRanking` object as a response.

<CodeGroup>
  ```filename GraphQL theme={null}
    query getUserPassedTrainingsRanking {
      getUserPassedTrainingsRanking {
        rank
        averageScore
      }
    }
  ```

  ```File Query result [expandable] theme={null}
    {
      "data": {
        "getUserPassedTrainingsRanking": {
          "rank": 5,
          "averageScore": 78.55
        }
      }
    }
  ```
</CodeGroup>
