I have a case here to “break ties” between teams in a competition. The criteria are basic, but I’m having trouble finding a solution. The team with the most first-place wins in each position wins. So, if two teams have 10 points, and the first team has 1 first-place win, while the second has none, the first team wins.
I’ve managed to handle this scenario. However, when more than two teams are tied, it becomes more complex, as in the following case:
There are 5 teams with 16 points. Team 10 and Team 9 have the first position, but Team 10 also has 1 second-place win. So, the first two positions in the tiebreaker are Team 10 and Team 9 (that’s working so far).
Now comes the tiebreaker for Team 8, Team 6, and Team 2. All of them have 1 second-place win, and only Team 8 and 6 have a third-place win, so Team 2 ends up as the last. In this example, Team 8 and 6 are tied because their results are the same.
I’ll try to explain what I’ve done so far. Below, I’ve indicated the folder and the two workflows I’m using for this operation.
Basically, I pull a list of “Event Participation” sorted by “Score Total,” which is the sum of all the positions for each score. Then, I define the “Event Anterior,” “Posterior,” and “Atual” (red triangle) to determine whether there is a tie or not (first red arrow for a tie and the second for no tie). This continues for the entire list.
When I finish processing the list, I only take those marked as ties and proceed to the second workflow indicated by the arrow below.
Within the tiebreaker workflow, I loop through the positions. It starts by looking at everyone who has a “Score Total” of 16 (red square), for example, who is in first place, and then it assigns values where the red arrows are.
In the first pass, it looks like this:
Team - Score Total - Tiebreak_position - Tiebreak_score
Team 10 - 16 1 1
Team 9 - 16 1 1
Team 2 - 16 1 0
Team 8 - 16 1 0
Team 6 - 16 1 0
So, Team 10 and 9 have one first-place win each, and the other three teams have none.
Then, it goes back to the first workflow, checking only these 5 teams, and it recognizes that Team 10 and 9 are tied, and Teams 2, 8, and 6 are also tied, and so on.
The second pass would look like this:
Team - Score Total - Tiebreak_position - Tiebreak_score
Team 10 - 16 2 1
Team 9 - 16 2 0
Team 2 - 16 2 1
Team 8 - 16 2 1
Team 6 - 16 2 1
Team 10 and 9 break the tie, and Team 2 gets stuck in third place. (Team 8 and 6 remain tied because the tiebreaker criteria can’t resolve this case, but that’s another issue).
Team - Score Total - Tiebreak_position - Tiebreak_score
Team 10 - 16 2 1
Team 9 - 16 2 0
Team 2 - 16 3 0
Team 8 - 16 5 0
Team 6 - 16 5 0
I’m not sure if my explanation makes it more complicated, but thanks for your attention!
Here is the link for application - https://bubble.io/page?type=api&id=testscoreup&tab=tabs-2
Best regards