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

# アーカイブされたトーナメントの結果へのアクセス

> 手動またはスケジュールされたリセットの後に PlayFab のトーナメント リーダーボードのスナップショットにアクセスし、以前のバージョンのプレイヤー ランキングと統計を取得します。

このチュートリアルでは、アーカイブされたリーダーボードの状態にアクセスする方法について説明します。

各リーダーボードは、手動または自動でリセットできます。つまり、すべてのプレイヤーの統計値が削除されて *クリア* な状態になり、リーダーボードのバージョンが更新されます。

ただし、これが発生する前に、PlayFab は各プレイヤーのすべてのリーダーボード統計値のスナップショットを作成します。これにより、リーダーボードの *アーカイブ* されたバージョンにアクセスできます。

<Note>
  すべてのタイトルで、直近にアーカイブされたバージョンのリーダーボードにアクセスできます。これにより、現在のバージョンと直前のバージョンを取得できます。たとえば、現在のリーダーボード バージョンが **3** の場合、バージョン **3** とアーカイブされたバージョン **2** のみアクセスできます。
</Note>

## 初期セットアップ

このガイドを使用する前に、タイトルに何人かのプレイヤーが既に登録されていることを確認してください。次のスクリーンショットは、[LoginWithCustomID](xref:titleid.playfabapi.com.client.authentication.loginwithcustomid) API 呼び出しを使用して 5 人のプレイヤーを人工的に登録した状態を示しています。

<img src="https://mintcdn.com/microsoft-4404708b/IwSYTY5BEqd_x-HK/images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-players-most-recent-logins.png?fit=max&auto=format&n=IwSYTY5BEqd_x-HK&q=85&s=82e4840d634e73c5e5e9f0878f0365ab" alt="Game Manager - Players - Most recent logins" width="946" height="577" data-path="images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-players-most-recent-logins.png" />

## リーダーボードの定義とシミュレーション

このステップでは、テスト目的でリーダーボードを作成します。その後、リーダーボードに数回データを入力してリセットし、リーダーボードのイテレーション プロセスをシミュレートします。

Game Manager を開きます:

1. **Leaderboards** セクションに移動します。
2. 以下に示すように、**New Leaderboard** ボタンを選択します。

新しいリーダーボードを構成するには:

1. **Statistic** の名前を **TestScore** に設定します。
2. **Reset Frequency** は **Manually** のままにします。
3. デフォルトの **Aggregation** メソッドをそのままにします。
4. **Save Leaderboard** を選択して送信します。

<img src="https://mintcdn.com/microsoft-4404708b/IwSYTY5BEqd_x-HK/images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-leaderboards-new-leaderboard-properties.png?fit=max&auto=format&n=IwSYTY5BEqd_x-HK&q=85&s=2cd9b12e09ccfe716626232cb6967815" alt="Game Manager - Leaderboards - New Leaderboard - Properties" width="1280" height="900" data-path="images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-leaderboards-new-leaderboard-properties.png" />

新しい **Leaderboards** ページに移動し、空のデータが表示されます (以下参照)。

<img src="https://mintcdn.com/microsoft-4404708b/IwSYTY5BEqd_x-HK/images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-leaderboards-edit-leaderboard.png?fit=max&auto=format&n=IwSYTY5BEqd_x-HK&q=85&s=f3b2e105a30073db23eb36d8cf232e92" alt="Game Manager - Leaderboards - Edit Leaderboard" width="1920" height="910" data-path="images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-leaderboards-edit-leaderboard.png" />

## テスト セクションの開始

<Info>
  以下のセクションは、この例の目的でテスト データを入力する方法の一例です。*実際の* ゲームでは、このデータをより自然な方法で入力します。
</Info>

次のステップは、リーダーボードのデータをシミュレートすることです。最も簡単な方法は、指定されたプレイヤーにランダムな統計を設定する CloudScript ハンドラーを作成することです。このハンドラーを All Players セグメントのすべてのプレイヤーに対して呼び出します。

その結果、各プレイヤーがランダムな統計値を取得します。これは実世界のシナリオに *十分近い* 近似です。

まず、CloudScript の定義から始めましょう (詳細についてはコード コメントを参照してください)。

```javascript theme={null}
// Should be invoked from a task that runs over certain segment
handlers.PopulateLeaderboard = (args,ctx) => {
    // When handler is executed as a task over the segment
    // we can extract individual player id using the next line:
    let playerId = ctx.playerProfile.PlayerId;

    // Use player id and update player statistics as follows:
    server.UpdatePlayerStatistics({
        PlayFabId : playerId,
        Statistics : [
            {
                "StatisticName": "TestScore",
                "Value": getRandomInRange(100,1000)
            }
        ]
    });
}

// Utility method to generate random number
let getRandomInRange = (min, max) => {
    return Math.round(Math.random() * (max - min) + min);
}
```

CloudScript をアップロードしましょう。Game Manager を使用します:

1. **Automation** タブに移動します。
2. 次に **CloudScript** サブタブに移動します。
3. **CloudScript** コードを挿入します。
4. **Save as Revision** を選択します。
5. 最後に **Deploy Revision** を選択します。

<img src="https://mintcdn.com/microsoft-4404708b/5IpvKlT-jmAaVkeY/images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-automation-cloudscript-upload-cloudscript.png?fit=max&auto=format&n=5IpvKlT-jmAaVkeY&q=85&s=7aad030809ec7893abbc42ae6f928ca0" alt="Game Manager - Automation - CloudScript - upload CloudScript" width="1292" height="707" data-path="images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-automation-cloudscript-upload-cloudscript.png" />

次に、特定のセグメントに対して CloudScript を実行するタスクを定義する必要があります:

1. **Players** タブに移動します。
2. 次に **Segments** サブタブに移動します。

デフォルトでは、**PlayFab** は **All Players** セグメントを生成します。このセグメントは、タイトルに登録されているすべてのプレイヤーが必要な場合 (まさに今回のケース) に特に便利です。

3. **All Players Segment** を選択します。
4. 最後に、**Run Task...** を選択します。

<Note>
  リストに All Players セグメントがない場合は、[Player Segmentation](/services/playfab/live-service-management/game-configuration/segmentation/segmentation-quickstart) クイックスタートを参照して作成してください。
</Note>

<img src="https://mintcdn.com/microsoft-4404708b/IwSYTY5BEqd_x-HK/images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-players-segments-all-players-run-task.png?fit=max&auto=format&n=IwSYTY5BEqd_x-HK&q=85&s=38b80b93c15928a0f22495e8a555b82d" alt="Game Manager - Players - Segments - All Players - Run Task" width="983" height="580" data-path="images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-players-segments-all-players-run-task.png" />

タスクを構成するには:

1. **Name** を設定します。
2. タスクの種類が **Run actions on each Player in a Segment** に設定されていることを確認します。
   * さらに、**Segment** の下で **All Players** が選択されていることを確認します。
3. 新しい **Action** を追加します。
4. **Type** の下で **Execute CloudScript** を選択します。
5. 次に、**CloudScript Function** の下で **PopulateLeaderboard** ハンドラーを選択します。
6. 最後に、**Save and Run** ボタンを選択します。

<img src="https://mintcdn.com/microsoft-4404708b/5IpvKlT-jmAaVkeY/images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-configure-task.png?fit=max&auto=format&n=5IpvKlT-jmAaVkeY&q=85&s=b0de60452d7b3bf3d2e4198ed1b11764" alt="Game Manager - Configure Task" width="1175" height="850" data-path="images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-configure-task.png" />

* 実行結果が **Successful** であることを確認します。

<img src="https://mintcdn.com/microsoft-4404708b/IwSYTY5BEqd_x-HK/images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-task-execution-succeeded.png?fit=max&auto=format&n=IwSYTY5BEqd_x-HK&q=85&s=80cba8a4162a8d74ec513be09bd71849" alt="Game Manager - Task Execution Succeeded" width="907" height="212" data-path="images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-task-execution-succeeded.png" />

## テスト セクションの終了

### テスト データを入力する

1. 再び **Leaderboards** タブに移動します。
2. 作成した **Leaderboard** を選択します。

<img src="https://mintcdn.com/microsoft-4404708b/IwSYTY5BEqd_x-HK/images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-leaderboards-test-score.png?fit=max&auto=format&n=IwSYTY5BEqd_x-HK&q=85&s=5b9e840d77457f6a5d497a7b83d81d3a" alt="Game Manager - Leaderboards - Test Score" width="1272" height="668" data-path="images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-leaderboards-test-score.png" />

1. **Leaderboard** にランダムな値が入力されているのが確認できます。
2. **Leaderboard** をリセットします。

<img src="https://mintcdn.com/microsoft-4404708b/IwSYTY5BEqd_x-HK/images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/reset-the-test-score-leaderboard.png?fit=max&auto=format&n=IwSYTY5BEqd_x-HK&q=85&s=f91b98680e788338e37520102bb78f4f" alt="Reset the Test Score Leaderboard" width="1038" height="464" data-path="images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/reset-the-test-score-leaderboard.png" />

これにより、現在のすべてのデータのスナップショットが作成され、その後すべてのプレイヤーの統計値が *ゼロ化* され、バージョンがインクリメントされます。

* リーダーボードがリセットされたら、CloudScript タスクを再度実行します。
* これを 2 ～ 3 回繰り返し、リセットして再入力します。

複数の **Leaderboard** バージョン **(1)** が得られます:

* **現在のバージョンのデータ** が左側のテーブルに表示されます **(3)**。
* **アーカイブされたデータ** は以前のバージョンで利用可能になります **(2)**。
* 最新バージョンのみが利用可能です。これはすべてのタイトルに適用されます。

<img src="https://mintcdn.com/microsoft-4404708b/IwSYTY5BEqd_x-HK/images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-leaderboards-leaderboard-versions.png?fit=max&auto=format&n=IwSYTY5BEqd_x-HK&q=85&s=2ca281d95f15295de606458c9f450734" alt="Game Manager - Leaderboards - Leaderboard Versions" width="1204" height="694" data-path="images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-leaderboards-leaderboard-versions.png" />

### Game Manager を使用してアーカイブされたデータにアクセスする

**Leaderboard** ページから直接アーカイブされた結果にアクセスできます:

1. **Leaderboards** タブに移動します。
2. 必要な **Leaderboard** を選択します。

<img src="https://mintcdn.com/microsoft-4404708b/IwSYTY5BEqd_x-HK/images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-leaderboards-select-leaderboard.png?fit=max&auto=format&n=IwSYTY5BEqd_x-HK&q=85&s=db629e9b5dec8a479629276004bbf22d" alt="Game Manager - Leaderboards - Select Leaderboard" width="921" height="271" data-path="images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-leaderboards-select-leaderboard.png" />

1. **Leaderboard** にアーカイブされたリビジョンが含まれている場合、以下のスクリーンショットに示されているダウンロード リンクを使用して **JSON** データをダウンロードできます。

<img src="https://mintcdn.com/microsoft-4404708b/IwSYTY5BEqd_x-HK/images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-leaderboards-download-archived-revision.png?fit=max&auto=format&n=IwSYTY5BEqd_x-HK&q=85&s=4395cb8990431b53f7457010fd21fcab" alt="Game Manager - Leaderboards - Download Archived Revision" width="1204" height="694" data-path="images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/game-manager-leaderboards-download-archived-revision.png" />

### API を使用してアーカイブされたデータにアクセスする

次のコードを使用すると、リーダーボードの最新 (現在) バージョンを取得できます。

```csharp theme={null}
PlayFabClientAPI.GetLeaderboard(new GetLeaderboardRequest()
{
    StatisticName = "TestScore",
}, result =>
{
    Debug.Log("Leaderboard version: "+result.Version);
    foreach (var entry in result.Leaderboard)
    {
        Debug.Log(entry.PlayFabId+" "+entry.StatValue);
    }
}, FailureCallback);
```

結果は以下の例のようになります。

<img src="https://mintcdn.com/microsoft-4404708b/5IpvKlT-jmAaVkeY/images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/debug-output-display-leaderboard-versions.png?fit=max&auto=format&n=5IpvKlT-jmAaVkeY&q=85&s=e345a4db86df875b598d2feec2458ca3" alt="Debug output - Display Leaderboard Versions" width="267" height="225" data-path="images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/debug-output-display-leaderboard-versions.png" />

または、読み込むリーダーボードのバージョンを指定することもできます。

```csharp theme={null}
PlayFabClientAPI.GetLeaderboard(new GetLeaderboardRequest()
{
    StatisticName = "TestScore",
    Version = 1
}, result =>
{
    Debug.Log("Leaderboard version: "+result.Version);

    foreach (var entry in result.Leaderboard)
    {
        Debug.Log(entry.PlayFabId+" "+entry.StatValue);
    }
}, FailureCallback);
```

結果は以下の例のようになります。

<img src="https://mintcdn.com/microsoft-4404708b/5IpvKlT-jmAaVkeY/images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/debug-output-display-leaderboard-version-1.png?fit=max&auto=format&n=5IpvKlT-jmAaVkeY&q=85&s=068921c7f391fca2889ee300c6504a4d" alt="Debug output - Display Leaderboard Version 1" width="272" height="221" data-path="images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/debug-output-display-leaderboard-version-1.png" />

すべてのタイトルで、リーダーボードの *最新の* アーカイブ バージョンにアクセスできます。それより古いバージョンを取得しようとするとエラーになります (以下参照)。

<img src="https://mintcdn.com/microsoft-4404708b/5IpvKlT-jmAaVkeY/images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/error-leaderboard-version-not-available.png?fit=max&auto=format&n=5IpvKlT-jmAaVkeY&q=85&s=75ed581ae4e92e67969cf002bd6b0dd7" alt="Error - Leaderboard Version not available" width="371" height="48" data-path="images/playfab/community/leaderboards/tournaments-leaderboards/tutorials/error-leaderboard-version-not-available.png" />

同じルールがすべての Leaderboard リクエストに適用されます。

* [GetLeaderboard](xref:titleid.playfabapi.com.client.playerdatamanagement.getleaderboard)
* [GetLeaderboardAroundPlayer](xref:titleid.playfabapi.com.client.playerdatamanagement.getleaderboardaroundplayer)
* [GetFriendLeaderboardAroundPlayer](xref:titleid.playfabapi.com.client.playerdatamanagement.getfriendleaderboardaroundplayer)
* [GetFriendLeaderboard](xref:titleid.playfabapi.com.client.playerdatamanagement.getfriendleaderboard)

リーダーボード データと共に取得できる便利なプロパティについて学ぶには、[GetLeaderboardResult](xref:titleid.playfabapi.com.client.playerdatamanagement.getleaderboard#getleaderboardresult) オブジェクトのドキュメントを参照してください。


## Related topics

- [高度なリーダーボードにプロファイルを使用する](/ja-jp/services/playfab/community/leaderboards/tournaments-leaderboards/using-the-profile-for-advanced-leaderboards.md)
- [S3 イベント アーカイブ](/ja-jp/services/playfab/data-analytics/legacy/s3-event-archiving.md)
- [プッシュ通知クイックスタート](/ja-jp/services/playfab/live-service-management/game-configuration/title-communications/push-notifications/quickstart.md)
- [Amazon S3 バケットのセットアップ](/ja-jp/services/playfab/data-analytics/legacy/configure-s3-bucket.md)
- [XblMultiplayerTournamentsServer](/ja-jp/reference/live/xsapi-c/multiplayer_c/structs/xblmultiplayertournamentsserver.md)
