Hi, i have a small script, that reads player-ID, name, clubname and player rank from a CSV file:
$csvFilePath = ".\participants.csv"
$names = Import-Csv -Path $csvFilePath
$names is now filled with information from CSV file, then I want these names into groups, with maximun 4 participants, and minimum 3 participants:
$maxNamesPerGroup = 4
$minNamesPerGroup = 3
And from my CSV list, i want participants to random go to different group, so i uses:
$names = $names | Get-Random -Count $names.Count
When i now execute $names, i see that the list is shuffled.
So, now i want to start from the top of the list, and create groups:
$groups = @()
$currentGroup = @()
But from here, I need new eyes to have a look.
this is so far rest of my script to sort participants into different groups based on the random list i created earlier:
foreach ($name in $names) {
$currentGroup += $name
if ($currentGroup.Count -ge $maxNamesPerGroup) {
$groups += $currentGroup
$currentGroup = @()
}
}
# Add any remaining names to the last group
if ($currentGroup.Count -ge $minNamesPerGroup) {
$groups += $currentGroup
}
# Print the names in the groups
for ($i = 0; $i -lt $groups.Count; $i++) {
Write-Host "Group $i :"
$groups[$i]
}
But somehow, this will create one participant per Group, and if i have 12 participants in my CS V list, this script will create 12 groups…
One more thing, i also want the player with highest rank in a group to be player # 1 in that group… But i can figure that out later if someone can help me a bit on my way with getting these participants into groups.
Set of data in CSV file:
Player-ID,Name,Club,Ranking
0001,Player One,Club One,14
0002,Player Two,Club Two,17
0003,Player Three,Club Three,09
0004,Player Four,Club Four,12
0005,Player Five,Club Five,18
0006,Player Six,Club Six,26
0007,Player Seven,Club Seven,24
0008,Player Eight,Club Eight,17
0009,Player Nine,Club Nine,12
0010,Player Ten,Club Ten,19
0011,Player Eleven,Club Eleven,22
0012,Player Twelve,Club Twelve,28
Thanks