57
Views
5
Comments
Creating Random Teams from a List of Outsystems Users
Question
Application Type
Mobile
Platform Version
11.18.0 (Build 37385)

Hi All, Again,

I couldn't find a concreate answer to this question, only old discussions that didn't really provide what I was looking for, or, advising there is no solution - I'm hoping a few years on there now is.

At a very high-level this is what I am looking to achieve.

I have a football App that players can crate teams (or Groups I call them to avoid confusion), and Users can join each others Groups by scanning a QR code.

Now, lets say for example, I have 20 users (all registered on OS, as they have to register to log in) in a group. There is a Match coming up and from that group of 20 users, they would like to make random teams.

Is there anyway in OutSystems currently, whereby I can use the list of Users (from any given group) and create two random teams (Team 1 and Team 2) from the original list of 20 users?

Once the teams were picked, I'd simply build functionality whereby the user can save the teams and that would in turn upload the generated teams to SharePoint, as well as saving the other information about Match etc.

I just can't get my head around how this should work and what I would need to setup on OutSystems to be able to get this to work. I initially thought I could just have a Database entry for Team 1 and one for Team 2, which could be used to allocate players to as part of the flow, but then I thought that was too messy and there was a more straight forward approach - and then I got lost entirely on how best to do this.

There could be several registered users looking to generate teams at the same time, so although I could write to a new DB entry, I couldn't then wipe it entirely each time, although I could use the Group Id I already store on a different OS database, and use that to highlight which entries to delete once the teams have been picked and saved/ uploaded to SharePoint, this way I can keep my OutSystem database size as small as possible too. Perhaps a two Structures for Team 1 and Teams 2 would be enough, and use them as local variables? Hmmm  

Any advise is very much appreciated as always! 

Thanks in advance.

Warm regards,

Josh

2016-04-22 00-29-45
Nuno Reis
 
MVP

Hello Joshua.

You can use SQL's trick to make random selects. In an Advanced SQL:

SELECT {User}.*
FROM {User}
ORDER BY NEWID()

They will come out in a random order every time.

This applies to the full users entity, but you can use filters and pick people from specific group/teams.

Then, you just have to alternate team1/team2 to have an even distribution between them.

UserImage.jpg
Joshua McQuillan

Hi @Nuno Reis ,

Thank you for the above, I think I follow what you mean, but can't produce what I am looking for. Perhaps I can explain better now I am closer to what I want to achieve.

So using your help I have created the following statement:

  • SELECT {MatchTeams}.*
  • FROM {MatchTeams}
  • WHERE {MatchTeams}.[MatchId] = 104
  • ORDER BY NEWID()

So, so far, this returns what I need perfectly, but it's the actual allocation of 'Team 1' and 'Team 2' I am struggling with.

So how this works so far, is that players click a button called "Get Me In", and this then adds them to the MatchTeams entity/database. It assigns details such as the TeamId they are currently apart of, their userId, the time they clicked/ added themselves and so on.. basically on the info and relationships I need.

The only thing it doesn't populate as part of this flow, on purpose, is the MatchTeams.Teams column. I plan to simply put either a "1" or "2" in this column to represent they are in either "Team 1" or "Team 2".

I only want the allocation of Team 1 (1) or Team 2 (2) to happen after another button is pressed "Generate Teams", which is done by the group admin.

As part of the flow of this action, it runs the above SQL query to return all the players currently in that team, and then my intention, is to have it it randomly allocate '1' or '2', to MatchTeams.Team - this will ensure when teams are generated they are random and fair.

Perhaps I need two SQL queries as part of the flow, the first could select half the players in the list (which could be 10, 12, 14 or 16 depending on team size), and the second SQL query could simply assign '2', for which ever players didn't get assigned '1', as part of the first SQL query.

I've tried to update the MatchTeams.Team coloumn with just a handful of users to test, it still pulls back the right players based on current teamId etc, but it doesn't update the columns, so I'm clearly missing something!

Warm regards,

2016-04-22 00-29-45
Nuno Reis
 
MVP

Hello.

If you already have the randomized list, you just need to do a loop on it, and update each user to be team 1 or team 2 (do a Mod on CurrentRowNumber to alternate).

UserImage.jpg
Joshua McQuillan

Hi @Nuno Reis,

SQL is not my strong point but the logic makes sense, I'll look to see how to do this best and see how I get on!

Thanks for the help so far,

Warm regards,

2016-04-22 00-29-45
Nuno Reis
 
MVP

What I«m saying is not SQL, but in OutSystems.

You do the Get in Advanced SQL, then do a ForEach on OutSystems, an assign with an if inside.


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.