question

guilbertflavien avatar image
guilbertflavien asked

How to get the value of a field in Player data for all user ?

Hi !

I have a field "my_field" in Player Data (title) that I want to get for all user, in order to do statistics : some values of "my_field" are "foo", others are "bar", and I want to count how many user have "foo" and "bar".

In SQL, I would have done something like:

SELECT my_field, count(*)

FROM playerdata

group by my_field;

Right now, I'm doing it by doing a first query "/Server/GetPlayersInSegment" to have a list of all my users, then for each user, I do a "/Server/GetUserData" Query. But it does not seems very efficient to me. Is there a better way ?

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

·
Citrus Yan avatar image
Citrus Yan answered

Iterating through the whole player base might be a big problem especially when the player base is huge. In your case, you can use Player Segmentation to achieve this, use Statistics or Player Tag to specify which category a player belongs to – “foo” or “bar”, and

use different segments to represent each group of players, here is example of using Statistics to differentiate each player group:


1.png (10.2 KiB)
2.png (10.5 KiB)
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.

guilbertflavien avatar image guilbertflavien commented ·

Thank you for taking your time to answer !

However, I still have questions. "my_field" is stored in "Player Data (Ttitle)". By the way, it is not an information that cannot be public. I however need to know how many players have "foo" in "my_field", and how many players have "bar".

Speaking of segment, can I have players in multiples Segment ? Because let's that that next week I want to make stats about a second field... Will I be able to do that ?

Second question, if I want to use Statistics or user tags, can I somehow link it with the existing "my_field" in Player Data ? I do not want to break my actual program, so I wont modify where "my field" is stored.

Do you think you can provide me with API routes instead of the GUI ? It would be really helpfull to me :)

Thanks again for taking your time to answer me.

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan guilbertflavien commented ·

>>can I have players in multiples Segment

Sure, a player can be in multiple segments, making more stats later on won't be an issue.

>>can I somehow link it with the existing "my_field" in Player Data ?

I'm afraid not, you cannot link it with Player Data, you might need more logic in the code.

>>Do you think you can provide me with API routes instead of the GUI ?

Segment configurations are set via the Game Manager: https://developer.playfab.com/en-US/r/t/your_title_id/segments, currently there is no API to do that, that's why I provided some screenshots for you.

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Citrus Yan commented ·

And, here a possible solution for your case:

1) Prepare a local script that iterate all the players and do the "check player data and update it in statistics" work. Please note that you should control the API rate so that you don't get throttled.

2)Update the client code logic: also update the value in statistics when updating it in Player Data, this helps avoid the situation where newly created players are overlooked when you're processing the "migrating player data to statistics" transaction using the local script in step 1.

3) Run the local script in step 1.

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.