Skip to content

Commit

Permalink
Merge pull request #11 from gitrgoliveira/tree-division-option
Browse files Browse the repository at this point in the history
Tree division option, time estimation and improving round-robin + examples
  • Loading branch information
gitrgoliveira authored Nov 6, 2023
2 parents a0217f5 + 7297f3e commit ba0cf21
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 21 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ go/build:
## Build locally and create the examples
examples: go/build
@echo "building examples"
./bin/bracket-creator create-pools -t 5 -f ./mock_data_small.csv -o ./pools-example-small.xlsx
./bin/bracket-creator create-pools -r -t 5 -f ./mock_data_small.csv -o ./pools-example-small.xlsx
./bin/bracket-creator create-playoffs -t 5 -f ./mock_data_small.csv -o ./playoffs-example-small.xlsx
./bin/bracket-creator create-pools -s -p 3 -w 2 -f ./mock_data_medium.csv -o ./pools-example-medium.xlsx
./bin/bracket-creator create-pools -s -r -p 3 -w 2 -f ./mock_data_medium.csv -o ./pools-example-medium.xlsx
./bin/bracket-creator create-playoffs -s -f ./mock_data_medium.csv -o ./playoffs-example-medium.xlsx
./bin/bracket-creator create-pools -s -p 3 -w 2 -t 5 -f ./mock_data_large.csv -o ./pools-example-large.xlsx
./bin/bracket-creator create-playoffs -s -f ./mock_data_large.csv -o ./playoffs-example-large.xlsx
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ bracket-creator create-playoffs -t 5 -f ./mock_data_small.csv -o ./playoffs-exam
* `-t` / `-team-matches` - Create team matches with x players per team. Default is 0, which means these are not team matches

### Examples
See also the example files:
See also the example files created by the Makefile:
- [playoffs-example-large.xlsx](playoffs-example-large.xlsx)
- [playoffs-example-medium.xlsx](playoffs-example-medium.xlsx)
- [playoffs-example-small.xlsx](playoffs-example-small.xlsx)
Expand Down
1 change: 1 addition & 0 deletions cmd/create-playoffs.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ func (o *createPlayoffOptions) run(cmd *cobra.Command, args []string) error {
helper.CreateNamesToPrint(f, players, o.sanatize)

helper.PrintTeamEliminationMatches(f, matchWinners, eliminationMatchRounds, o.teamMatches)
helper.FillEstimations(f, 0, 0, 0, o.teamMatches, len(names)-1)

// Save the spreadsheet file
if err := f.SaveAs(o.outputPath); err != nil {
Expand Down
1 change: 1 addition & 0 deletions cmd/create-pools.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ func (o *poolOptions) run(cmd *cobra.Command, args []string) error {
helper.CreateNamesWithPoolToPrint(f, pools, o.sanatize)
helper.PrintTeamEliminationMatches(f, matchWinners, eliminationMatchRounds, o.teamMatches)

helper.FillEstimations(f, len(pools), len(pools[2].Matches), 0, o.teamMatches, len(finals)-1)
// Save the spreadsheet file
if err := f.SaveAs(o.outputPath); err != nil {
fmt.Println("Error saving Excel file:", err)
Expand Down
20 changes: 19 additions & 1 deletion internal/helper/excel.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ func CreateNamesToPrint(f *excelize.File, players []Player, sanatized bool) {

row += 2
}

}

func CreateNamesWithPoolToPrint(f *excelize.File, pools []Pool, sanatized bool) {
sheetName := "Names to Print"

Expand Down Expand Up @@ -362,3 +362,21 @@ func CreateNamesWithPoolToPrint(f *excelize.File, pools []Pool, sanatized bool)
}
}
}

func FillEstimations(f *excelize.File, numPools int, numPoolMatches int, extraPools int, teamSize int, numEliminationMatches int) {
sheetName := "Time Estimator"

// Number of pools
f.SetCellInt(sheetName, "A2", numPools)
// Team size
f.SetCellInt(sheetName, "B2", teamSize)

// Matches per pool
f.SetCellInt(sheetName, "C2", numPoolMatches)

// Number of Elimination Matches
f.SetCellInt(sheetName, "A8", numEliminationMatches)
// Team size
f.SetCellInt(sheetName, "B8", teamSize)

}
39 changes: 22 additions & 17 deletions internal/helper/tournament.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,34 +166,39 @@ func CreatePoolRoundRobinMatches(pools []Pool) {
for poolN, pool := range pools {
size := len(pool.Players)

matchIndex := 0
var previousA *Player
var previousB *Player
for i := 0; i < size-1; i++ {
for i := 1; i < size; i++ {
for k, j := i, 0; j < size-i; j, k = j+1, k+1 {
sideA := &pools[poolN].Players[j]
sideB := &pools[poolN].Players[k]

for j := i + 1; j < size; j++ {
matchIndex++
sideA := &pools[poolN].Players[i]
sideB := &pools[poolN].Players[j]

if matchIndex%(size-1) == 0 {
if j%2 != 0 {
sideA, sideB = sideB, sideA
}

// restore if it was not time to change sides. This can happen with pools >4
if previousA == sideB || previousB == sideA {
sideA, sideB = sideB, sideA
}
pools[poolN].Matches = append(pools[poolN].Matches, Match{
SideA: sideA,
SideB: sideB,
})

previousA = sideA
previousB = sideB
}
}

// handle the special case for pools of 4
if size == 4 {
// swap the second last and third last round
secondLastRound := pools[poolN].Matches[len(pools[poolN].Matches)-2]
thirdLastRound := pools[poolN].Matches[len(pools[poolN].Matches)-3]
// swap the sides
secondLastRound.SideA, secondLastRound.SideB = secondLastRound.SideB, secondLastRound.SideA

pools[poolN].Matches[len(pools[poolN].Matches)-2] = thirdLastRound
pools[poolN].Matches[len(pools[poolN].Matches)-3] = secondLastRound

} else {
// last match always needs to swap sides
lastRound := &pools[poolN].Matches[len(pools[poolN].Matches)-1]
lastRound.SideA, lastRound.SideB = lastRound.SideB, lastRound.SideA
}

}

}
Expand Down
Binary file modified playoffs-example-large.xlsx
Binary file not shown.
Binary file modified playoffs-example-medium.xlsx
Binary file not shown.
Binary file modified playoffs-example-small.xlsx
Binary file not shown.
Binary file modified pools-example-large.xlsx
Binary file not shown.
Binary file modified pools-example-medium.xlsx
Binary file not shown.
Binary file modified pools-example-small.xlsx
Binary file not shown.
Binary file modified template.xlsx
Binary file not shown.

0 comments on commit ba0cf21

Please sign in to comment.