Rank user’s points and store in Database

I currently have ‘Users’ with a points score saved to the database. The more they submit, the more they score. I have User profile page, where data is displayed relating to that user, as well as a repeating group for anyone to view on a global page, whether they are logged in or not.

There are several repeating groups on the global page, where each user is then part of one of these depending on a data point/use of the system - ‘If value = X then User is in RG 1’ kinda thing. I have managed to get an index/rank cell in the global repeating groups that rank in descending order, which is great! However, I am trying to enable it so that the members’ page has access to the rank/index. I have not been able to get a rank data type in the database created to store the data and ‘Index’ is only front end and does not affect the database.

I need some assistance in heading in the right direction as I do not know where to go next. Is it possible to allow the database to be affected by the ‘User Index’ value front end via autowinding so when the rank that is displayed front end changes, it auto binds and changes the database automatically?

Im going round in circles!
I appreciate that you will want to see screenshots etc but I’m not ready to share too much of the project just yet… :confused:

I’ll have a shot :slight_smile: It is tricky in Bubble with calculated values as you only have a few tools to achieve those calculations, then they exist only on the UI so are difficult to sort in a Repeating Group. I’ve always found it much easier to calculate the scores/ranks/ratings and store these on the User (ie in the DB). I think you’ve found similar limitations of calculating the rank on the fly. (eg Group by)

For me I would approach this by either;

  • updating a score/rank on a User as they “submit” - ie I submit 10 times, so I increment the score on every submit. submit_count = submit_count +1 type of thing.
  • run a workflow to update the Users rankings - eg end of day, when a user logs in, when someone goes to look at the report pages. Be efficient and do something like
    update this Users rank when this Users last submit time is after the last time I ran this workflow

Which approach? - probably the first one for simplicity. But I’d guess that mostly depends on the frequency of submits and number of users in your DB.

You’ll need to think about your Privacy Rules on the User so not logged in Users can see the rankings. I’d probably do that rather than create a new table just to hold scores, but that would depend on the type of app and what your Users are doing. Though it’s not a big issue to create a separate “ranking” table.

Once you have the score on the Users (or in the DB) - having your RG of Users with different ranks should be straight forward eg Select users where rank > 10 and rank < 50

Good luck with your project :slight_smile:

Yes, but that may not be an ideal way.

I would look at “database triggers” so that when a value is updated you can run a backend process to do a calculation and store it.

1 Like