Displaying Ranks of Multiple Leader Boards

Hi all, I am working on an app where users can log their steps each day for the month of December.
The app has a global leaderboard showing every user ranked from highest to lowest.

But tonight I decided to add a ‘fantasy football style league’ where users can create a group, add their friends and compete with people they know.

This has all gone pretty well, apart from one thing that I can’t figure out and it’s really bugging me. The user has a list of leagues they are part of (displayed in a repeating group) and I want to show the rank of the current user in each of these groups based off of the ‘total steps’ count.

Attached are a few screens of the database etc, I hope that makes sense.

Thanks so much in advance.

Chris



Hi there, @toff… I made a quick example, and if I understand your post correctly, I believe the following expression should do the trick. Oh, and the sort is in descending order.

rank

By the way, if you haven’t done so already, enable the experimental parentheses feature immediately because it’s pretty darn useful.

Hope this helps.

Best…
Mike

1 Like

Hi Buddy,

Thank you so much for looking at this for me.
This feels like a really silly question, but how do I get brackets in the expression? I can only insert them as text outside it (where they are white)?

Thanks

I didn’t mention the experimental parentheses feature by accident. :slight_smile:

If you enable that feature, Bubble will insert the parentheses as you build the expression.

Doh! Sorry I totally missed that.

Unfortunately, it didn’t work though. It seems to count the number of users in the group.

Ah, yup… my test was flawed… let me play around with it some more.

1 Like

Thank you so much.

The QA folks at my day job would be so disappointed in the completely inadequate testing I did on that initial suggestion… my apologies to you and them. Anyway, this expression should work.

1 Like

Thank you so much, Mike. You are a gent. This has worked like a dream!

1 Like

And now that I look at it again, you can remove the + 1 in the expression if you change the greater than sign to greater than or equal to in the filter constraint.

Really thank you! Next thing is for me to try and work out if the rank has increased or decreased (maybe per 24hours) and show a green or red arrow.

1 Like

Hmm, I think that is going to be difficult to do (and it might not be possible) with your current setup because you don’t have a history of each user’s steps from day to day at the league level. It might be possible to hack something together where you save a list of numbers for each user every day that represents their ranking for the day in each league. Then, you might be able to use that list of numbers to compare against their new ranking in each league. Then again, that might not work at all… so, you know, there’s that, too.

1 Like

Probably a basic way to do it (without adding a new data type and start logging every step change) is add another number field called “Steps 24hr ago”, and a date field called “Steps last updated”

Then when they update their steps, have it update the steps and also set the “Steps last updated” to the current date/time.
Then have a step2 in your workflow modify the Result of step 1 with the condition When current user's Step last updated +hours (24) < Current date/time Have it set the “Steps 24 hours ago” value to the input they put in. (I feel like this could be done with a database trigger if there’s issues)

Then in your area where you want to show the up or down arrows, have it subtract the current steps from the steps 24 hours ago, to show the number, then you can have some conditional rules to make it red if it’s < 0 or green if its > 0. And show some up or down arrows with the same rules.

1 Like

For more list expression magic in this vein, see How to rank members in a contest? , @mikeloc!

(The whole thread is worth a read, all my “code” there I wrote on my phone so it’s conceptual rather than strictly correct. I think we came to sort of the the same answer as you’re honing in on Mike.)

2 Likes