question

Yoo SeungJi avatar image
Yoo SeungJi asked

How to know the latest version of statistics?

We are going to make total statistics based on the sum of statistics that upload scores for each stage. At the end of the stage, update the statistics and get a profile to sum up the statistics within it. However, the statistics in the profile are included up to the previous version. Is there a way to filter only the latest version of statistics? Or is there a way to get the latest version of statistics?

Player Data
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

>> Is there a way to filter only the latest version of statistics?

Could you please clarify which one API you called to get user’s statistics? For example, could you please provide the sample code? We testedthe API GetPlayerProfile, it returned the latest statistic. And if you don’t specify the version in the request body, the API GetPlayerStatistics wouldalso return the latest statistics.

>> Or is there a way to get the latest version of statistics?

If you want to know the latest version of a statistics, you can call the GetPlayerStatisticVersions. The version in the last entry of the array StatisticVersions is the latest version. For the clarification, updating one player’s statistics value won’t cause the version number to increase. The version number would be increased when you reset the corresponding leaderboard.

3 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Yoo SeungJi avatar image Yoo SeungJi commented ·

We get Statistics from GetPlayerProfile. But PlayerProfileModel.Statistics contain all of previous version. For example some player's "A" statistics version 1 is 150. And "A" statistics lasted version is 2. But that player's profile.Statistics contain version 1's statistics data. We need only lasted version's statistics. Could you help us?

Here is my code for upload total score.

0 Likes 0 ·
Yoo SeungJi avatar image Yoo SeungJi commented ·
handlers.UpdateTotalScore = function(args){
    var request = {
	PlayFabId : currentPlayerId,
	ProfileConstraints:{
	ShowStatistics :true
    }
    };
    var total = 0;
    var profile = server.GetPlayerProfile(request);
    var statisticsNames = [];
    profile.PlayerProfile.Statistics.forEach(element => {
	if(statisticsNames.includes(element.Name)==false)
	statisticsNames.push(element.Name);
    });
    var lastedVersion = {};
    statisticsNames.forEach(element=>{
	var request = {
		StatisticName : element
	};
	var version = server.GetPlayerStatisticVersions(request);
	lastedVersion[element] = version.StatisticVersions[version.StatisticVersions.length-1].Version;
    })
    profile.PlayerProfile.Statistics.forEach(element => {
        if(!element.Name.includes("TotalRank")){
            if(element.Version == lastedVersion[element.Name]){
                total+=element.Value;
		}
        }
    });
    if(total>0){
        var req = {
		PlayfabId:currentPlayerId,
		Statistics : [{
		StatisticName:"TotalRank"
		Value:total
            }]       
        }
        server.UpdatePlayerStatistics(req);
    }
};
0 Likes 0 ·
Yoo SeungJi avatar image Yoo SeungJi commented ·

Oh... Sorry. Call GetPlayerStatistics instead of GetPlayerProfile, work perfect! Thank you.

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.