Drarig29/brackets-manager.js

Update seeding doesn't not update correctly

yongshun950824 opened this issue · 4 comments

Scenario

Initially, I create a new tournament stage with size: 4 and was able to assign the seedings to the stage.

await window.bracketsManager.update.seeding(0, ['Team 1', 'Team 2', 'Team 3', 'Team 4'])
    .then(() => {
        (async function() {
            let b = await window.bracketsManager.get.stageData(0);
            console.log(b);
    })();
 });
Sample Tournament Data

{
    "participant": [
        {
            "id": 0,
            "tournament_id": 6,
            "name": "Team 1"
        },
        {
            "id": 1,
            "tournament_id": 6,
            "name": "Team 2"
        },
        {
            "id": 2,
            "tournament_id": 6,
            "name": "Team 3"
        },
        {
            "id": 3,
            "tournament_id": 6,
            "name": "Team 4"
        }
    ],
    "stage": [
        {
            "id": 0,
            "tournament_id": 6,
            "name": "Random 2",
            "type": "single_elimination",
            "number": 2,
            "settings": {
                "size": 4,
                "seedOrdering": [
                    "inner_outer"
                ],
                "grandFinal": "single",
                "matchesChildCount": 0,
                "groupCount": null,
                "roundRobinMode": null,
                "skipFirstRound": null,
                "consolationFinal": false
            }
        }
    ],
    "group": [
        {
            "id": 0,
            "stage_id": 0,
            "number": 1
        },
        {
            "id": 1,
            "stage_id": 0,
            "number": 2
        }
    ],
    "round": [
        {
            "id": 0,
            "number": 1,
            "stage_id": 0,
            "group_id": 0
        },
        {
            "id": 1,
            "number": 2,
            "stage_id": 0,
            "group_id": 0
        },
        {
            "id": 2,
            "number": 1,
            "stage_id": 0,
            "group_id": 1
        }
    ],
    "match": [
        {
            "id": 0,
            "number": 1,
            "stage_id": 0,
            "group_id": 0,
            "round_id": 0,
            "child_count": 0,
            "status": 2,
            "opponent1": {
                "id": 0,
                "position": 1
            },
            "opponent2": {
                "id": 3,
                "position": 4
            }
        },
        {
            "id": 1,
            "number": 2,
            "stage_id": 0,
            "group_id": 0,
            "round_id": 0,
            "child_count": 0,
            "status": 2,
            "opponent1": {
                "id": 1,
                "position": 2
            },
            "opponent2": {
                "id": 2,
                "position": 3
            }
        },
        {
            "id": 2,
            "number": 1,
            "stage_id": 0,
            "group_id": 0,
            "round_id": 1,
            "child_count": 0,
            "status": 2,
            "opponent1": {
                "id": 0
            },
            "opponent2": {
                "id": 2
            }
        },
        {
            "id": 3,
            "number": 1,
            "stage_id": 0,
            "group_id": 1,
            "round_id": 2,
            "child_count": 0,
            "status": 0,
            "opponent1": {
                "id": null,
                "position": 1
            },
            "opponent2": {
                "id": null,
                "position": 2
            }
        }
    ],
    "match_game": []
}

image


I was tried to implement the logic that the tournament seeding can be added/removed.

First update: Set Slot 2 & 4 blank

await window.bracketsManager.update.seeding(0, ['Team 1', null, 'Team 3', null])
    .then(() => {
        (async function() {
            let b = await window.bracketsManager.get.stageData(0);
            console.log(b);
    })();
 });

But the returned data was unchanged which suppose the participant, match data should be changed based on seeding.

Sample Tournament Data after first update

{
    "stage": [
        {
            "id": 0,
            "tournament_id": 6,
            "name": "Random 2",
            "type": "single_elimination",
            "number": 2,
            "settings": {
                "size": 4,
                "seedOrdering": [
                    "inner_outer"
                ],
                "grandFinal": "single",
                "matchesChildCount": 0,
                "groupCount": null,
                "roundRobinMode": null,
                "skipFirstRound": null,
                "consolationFinal": false
            }
        }
    ],
    "group": [
        {
            "id": 0,
            "stage_id": 0,
            "number": 1
        },
        {
            "id": 1,
            "stage_id": 0,
            "number": 2
        }
    ],
    "round": [
        {
            "id": 0,
            "number": 1,
            "stage_id": 0,
            "group_id": 0
        },
        {
            "id": 1,
            "number": 2,
            "stage_id": 0,
            "group_id": 0
        },
        {
            "id": 2,
            "number": 1,
            "stage_id": 0,
            "group_id": 1
        }
    ],
    "match": [
        {
            "id": 0,
            "number": 1,
            "stage_id": 0,
            "group_id": 0,
            "round_id": 0,
            "child_count": 0,
            "status": 2,
            "opponent1": {
                "id": 0,
                "position": 1
            },
            "opponent2": {
                "id": 3,
                "position": 4
            }
        },
        {
            "id": 1,
            "number": 2,
            "stage_id": 0,
            "group_id": 0,
            "round_id": 0,
            "child_count": 0,
            "status": 2,
            "opponent1": {
                "id": 1,
                "position": 2
            },
            "opponent2": {
                "id": 2,
                "position": 3
            }
        },
        {
            "id": 2,
            "number": 1,
            "stage_id": 0,
            "group_id": 0,
            "round_id": 1,
            "child_count": 0,
            "status": 2,
            "opponent1": {
                "id": 0
            },
            "opponent2": {
                "id": 2
            }
        },
        {
            "id": 3,
            "number": 1,
            "stage_id": 0,
            "group_id": 1,
            "round_id": 2,
            "child_count": 0,
            "status": 0,
            "opponent1": {
                "id": null,
                "position": 1
            },
            "opponent2": {
                "id": null,
                "position": 2
            }
        }
    ],
    "match_game": [],
    "participant": [
        {
            "id": 0,
            "tournament_id": 6,
            "name": "Team 1"
        },
        {
            "id": 1,
            "tournament_id": 6,
            "name": "Team 2"
        },
        {
            "id": 2,
            "tournament_id": 6,
            "name": "Team 3"
        },
        {
            "id": 3,
            "tournament_id": 6,
            "name": "Team 4"
        }
    ]
}


Second update: Reset all slots with new values

await window.bracketsManager.update.seeding(0, ['Team 5', 'Team 6', 'Team 7', 'Team 8'])
    .then(() => {
        (async function() {
            let b = await window.bracketsManager.get.stageData(0);
            console.log(b);
    })();
 });
Sample Tournament Data after second update

{
    "stage": [
        {
            "id": 0,
            "tournament_id": 6,
            "name": "Random 2",
            "type": "single_elimination",
            "number": 2,
            "settings": {
                "size": 4,
                "seedOrdering": [
                    "inner_outer"
                ],
                "grandFinal": "single",
                "matchesChildCount": 0,
                "groupCount": null,
                "roundRobinMode": null,
                "skipFirstRound": null,
                "consolationFinal": false
            }
        }
    ],
    "group": [
        {
            "id": 0,
            "stage_id": 0,
            "number": 1
        },
        {
            "id": 1,
            "stage_id": 0,
            "number": 2
        }
    ],
    "round": [
        {
            "id": 0,
            "number": 1,
            "stage_id": 0,
            "group_id": 0
        },
        {
            "id": 1,
            "number": 2,
            "stage_id": 0,
            "group_id": 0
        },
        {
            "id": 2,
            "number": 1,
            "stage_id": 0,
            "group_id": 1
        }
    ],
    "match": [
        {
            "id": 0,
            "number": 1,
            "stage_id": 0,
            "group_id": 0,
            "round_id": 0,
            "child_count": 0,
            "status": 2,
            "opponent1": {
                "id": 4,
                "position": 1
            },
            "opponent2": {
                "id": 7,
                "position": 4
            }
        },
        {
            "id": 1,
            "number": 2,
            "stage_id": 0,
            "group_id": 0,
            "round_id": 0,
            "child_count": 0,
            "status": 2,
            "opponent1": {
                "id": 5,
                "position": 2
            },
            "opponent2": {
                "id": 6,
                "position": 3
            }
        },
        {
            "id": 2,
            "number": 1,
            "stage_id": 0,
            "group_id": 0,
            "round_id": 1,
            "child_count": 0,
            "status": 2,
            "opponent1": {
                "id": null
            },
            "opponent2": {
                "id": null
            }
        },
        {
            "id": 3,
            "number": 1,
            "stage_id": 0,
            "group_id": 1,
            "round_id": 2,
            "child_count": 0,
            "status": 0,
            "opponent1": {
                "id": null,
                "position": 1
            },
            "opponent2": {
                "id": null,
                "position": 2
            }
        }
    ],
    "match_game": [],
    "participant": [
        {
            "id": 0,
            "tournament_id": 6,
            "name": "Team 1"
        },
        {
            "id": 1,
            "tournament_id": 6,
            "name": "Team 2"
        },
        {
            "id": 2,
            "tournament_id": 6,
            "name": "Team 3"
        },
        {
            "id": 3,
            "tournament_id": 6,
            "name": "Team 4"
        },
        {
            "id": 4,
            "tournament_id": 6,
            "name": "Team 5"
        },
        {
            "id": 5,
            "tournament_id": 6,
            "name": "Team 6"
        },
        {
            "id": 6,
            "tournament_id": 6,
            "name": "Team 7"
        },
        {
            "id": 7,
            "tournament_id": 6,
            "name": "Team 8"
        }
    ]
}

For this time, the participant data is updated with adding ['Team 5', 'Team 6', 'Team 7', 'Team 8']. I think this goes wrong as it failed to fulfill the tournament size (suppose 4, but now 8 participants).

Is it a bug or do I work the wrong way to update seeding?

Expected result:

UpdateSeeding should be able to update tournament participant and respective match.

  1. Input: ['Team 1', 'Team 2', 'Team 3', 'Team 4'], (Result) Participant: ['Team 1', 'Team 2', 'Team 3', 'Team 4']
  2. Input: ['Team 1', null, 'Team 3', null], (Result) Participant: ['Team 1', null, 'Team 3', null]
  3. Input: ['Team 5', 'Team 6', 'Team 7', 'Team 8'], (Result) Participant: ['Team 5', 'Team 6', 'Team 7', 'Team 8']

Actual result:

  1. (Initial) Participant: ['Team 1', 'Team 2', 'Team 3', 'Team 4'] - CORRECT
  2. (First update) Participant: ['Team 1', 'Team 2', 'Team 3', 'Team 4'] - FAILED with Match
  3. (Second update) Participant: ['Team 1', 'Team 2', 'Team 3', 'Team 4', 'Team 5', 'Team 6', 'Team 7', 'Team 8'] - FAILED with Match

UPDATED:
Match data works correctly.

What do you mean by:

FAILED with Match

Is there an error? Why are you mentioning "match"?

Hi, Sorry about that. I re-check the match data is seems correctly, point to new participant.

The mention of FAILED means the actual result doesn't match with the (Result) Participant in Expected Result section.
Let says the participant from

['Team 1', 'Team 2', 'Team 3', 'Team 4']

update to

['Team 5', 'Team 6', 'Team 7', 'Team 8'].

But the actual result come up is with participants:

['Team 1', 'Team 2', 'Team 3', 'Team 4', 'Team 5', 'Team 6', 'Team 7', 'Team 8']

Hi, I added a new test to ensure everything was working as I expected.

But the actual result coming up is with the following:

['Team 1', 'Team 2', 'Team 3', 'Team 4', 'Team 5', 'Team 6', 'Team 7', 'Team 8']

This is a wanted behavior. I don't want to take the responsability to automatically remove participants. Created participants will stay as leftovers (or tombstones) and can be reused in the future in the same bracket or another stage from the same tournament (cf. docs).

Closing, feel free to reopen if needed.