Need help with database logic

In my app users are able to rate each others work from 1-5. My issue is that I want the user’s personal displayed rating to update after they receive 5 ratings and update again after the receive another 5 ratings (this is to ensure anonymity with ratings).

How would you set this up in the database? I can’t figure out a way to grab the 5 at a time.

So you want it like how in the app store it shows the number of 5 star reviews, 4 star review …

I’m planning to display a decimal rating (ex 3.7 out of 5).

I’ll try to explain to make it a little clearer.

Project 1 rating: 3.0
Project 2 rating: 3.0
Project 3 rating: 3.5
Project 4 rating: 4.0
Project 5 rating: 4.0

Rating displayed to user 3.5

Project 6 rating: 4.0
Project 7 rating: 4.0
Project 8 rating: 4.5
Project 9 rating: 5.0
Project 10 rating: 5.0

After 10th project is rated, user receives an updated rating with the new average 4.5.

So you want it to update every 5 ratings not every rating.

Yeah, exactly. This will make it to where the user doesn’t know how each individual person rated them.

Hi @Michael,

I can’t offer an elegant solution for this… rather “straightforward” one. Here is the logic:

  • you need to have 5 properties for “ratings”, 1 property to address the current rating (“cursor”), and 1 property to store the “public” rating
  • “cursor” will be changing from 1 to 5, and will determine, which “rating” you’ll update
  • to update the rating, you have 5 conditional actions, dependent on cursor value (you update rating1 if cursor = 1, rating2 if cursor = 2, etc)
  • after you update the ratingX, you increase cursor by 1
  • then you have an additional conditional action, when cursor = 6. At this action you calculate the new average rating and put it to “public rating” property
  • and then you have another conditional action, when cursor = 6: you set cursor to 1.

And the next 5 reviews will be updating the ratings again.

As for me, this should work. Not an elegant solution, though…



Sorry for taking so long to reply to this. Thanks Victor. This is super helpful.

1 Like