Obtaining Entries around user from leaderboard

0 votes
Hello!

Is there exists some request that will return entries around user (by userId) from leaderboard? For instance

Input: userId and entries count limit (let's call it N)

Output: userId LB entry, N entries before user's entry and N entries after user's entry

 

Such call would be very useful.

 

Thanks!
asked Nov 12, 2014 in App42 Cloud API-BaaS by zveroid (22 points)
recategorized Apr 7, 2015 by sushil

1 Answer

+1 vote
 
Best answer

Hello,

You can easily achieve this by first finding the rank of user in the leader-board by GetUserRanking method. After that you can find the TopNRankers in the game using page offset and max result parameter as described below. Here page offset would be UserRank -N/2, and max result would be N. This will give the rankings of user who are N/2 above user and N/2 below user ranking.

String gameName = "<Enter_your_game_name>";

int max = 10; //Max result in leaderboard

// Page offset is from where you need to fetch the records.

//Lets say user has rank as 15 and you are looking 5 users above and below from this user. Offset would be in this case 15-10/2=10 (UserRank –N/2)

scoreBoardService.setPageOffset(10);  

image

scoreBoardService.getTopNRankers(gameName, max, new App42CallBack() {

public void onSuccess(Object response) 

{

            Game game = (Game)response;

            System.out.println("Game Name is : "+game.getName());

            for(int i = 0;i<game.getScoreList().size();i++)

            {

                        System.out.println("userName is : " + game.getScoreList().get(i).getUserName());

                        System.out.println("score is : " + game.getScoreList().get(i).getValue());

                        System.out.println("Created On is  :"+game.getScoreList().get(i).getCreatedOn());

                        System.out.println("scoreId is : " + game.getScoreList().get(i).getScoreId());

            }

}

public void onException(Exception ex) 

{

            System.out.println("Exception Message"+ex.getMessage());

}

});

 

Let us know if it helps.

Thanks,

Himanshu Sharma

 

answered Nov 13, 2014 by hs00105 (2,005 points)
selected Nov 13, 2014 by zveroid
Thanks!
But anyway it would be cool to do this operation by single request in the future :)
Thanks for your feedback. We will add this in our backlog and update this thread with timeline.
Thanks,
Himanshu Sharma
Thanks, I'll see those SetPageOffset methods in Unity/MonoDevelop now. But where is the documentation for this? I've gone through http://api.shephertz.com/app42-docs/leaderboard-service but found nothing about this.
Hello Info,
 
Thanks for your feedback. We are adding this in doc too and would be live soon.  
Let me know if you have more question for us.

Himanshu Sharma
I have the same requirement. In fact what would be even greater would be to get the ranking in the response when you post a score (but I understand this might not be feasible reliably in a NoSQL database)
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...