question

v-throch avatar image
v-throch asked

Implementing an item rating system

Hello, I need to implement a rating system for all my catalogs.

To make this, I’ve decided to add a new player stat for each item.

For example :

if “player 1” and “player 2” both rate Item1 and Item2, 2 new player stats “Item1” and “Item2” will be added into their statistics.

With such information, I can retrieve the rate given by a player for a specific item.

Now, if I want to compute an average rate, I must:
1. parse all the catalog’s Items of any catalogs

2. find its associated leaderboard.

3. sum all the value for the item’s leaderboard and divide it by the number of leaderboard’s entries.

For example :

if “player 1” rate both Item1 ( 5 Stars) and item2 ( 3 Stars) and “player 2” rate both Item1 ( 3 Stars) and rate item2 ( 3 Stars), I now have 2 leaderboards.

Leaderboard item1 contains 2 entries so the average will be ((5 + 3)/2)=4

Leaderboard item2 contains also 2 entries so the average will be ((3 + 3)/2)=3

Currently, my strategy is to store those averages into the customData of each item and to run an admin tool which would update those averages (daily, for instance).

Would that strategy be able to handle a large number of players?

Do you recommend a better way to implement a rating system?

Thanks in advance

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

·
brendan avatar image
brendan answered

That's not really going to work for any non-trivial number of players. What you're trying to do is aggregate information across all users into a single row of data - that's not supported by the existing data systems. I'd have to recommend using a Redis Int per item (or similar) for this, so that you can do the aggregation there, and query it directly.

Alternately, given that you're trying to create ratings on items, I do need to ask: Are you trying to build a User Generated Content system, perhaps? If so, we'll be adding the UGC service originally developed for Minecraft to the service in the near future (https://blog.playfab.com/blog/upcoming-roadmap-2018-q4-oct-dec-edition).

4 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.

v-throch avatar image v-throch commented ·

For the moment, i'm just trying to create ratings on items.

To solve my issue, i've used title data to store key/value information.

Key is the itemID

Value is the average rate.

I know that's a temporary solution, so if in the future, Playfab could implement a user-friendly rating system it could appreciate.

Thanks a lot Brendan

0 Likes 0 ·
Andy avatar image Andy ♦♦ v-throch commented ·

Unfortunately, you're going to run into problems using TitleData for this as well. Title Data is meant to be edited infrequently and read by every client. To facilitate this, we employ caching and sharding. You should never allow for a single player's (or small group of players) actions to result in an update to Title Data. It will break the caching and sharding strategy and lead to problems in your game reaching even modest scale.

If you're able to constrain the Title Data updates to periodic updates initiated from your back end or tooling, that's fine. But it should never be driven off the actions of a single player.

0 Likes 0 ·
v-throch avatar image v-throch commented ·

Hello Brendan,

I understand that the title data must not be changed by a player or a group of player.

I've added a scheduled task to update periodically my rating system.

It works perfectly.

Thanks you

0 Likes 0 ·
brendan avatar image brendan v-throch commented ·

I had a quick look at the Cloud Script, and that's not actually going to work once your title is live - the only reason it does right now is because you have very few player accounts. Cloud Scripts are limited in terms of total CPU time and the number of PlayFab API calls they make. So once you have a non-trivial number of players, the loop that's trying to iterate through the players by querying the leaderboard over and over is going to fail. We've had quite a few threads on this type of concept (aggregating data from all users) in the forums - short version, there's no support for that right now. We will be adding support in the future, but you'd really need to use something like Redis for this, at the moment.

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.