Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manager.get.currentRound returns outdated Round with all Matches being Locked or Completed #180

Open
Tandashi opened this issue Jul 11, 2023 · 6 comments
Assignees
Labels
bug Something isn't working

Comments

@Tandashi
Copy link

Tandashi commented Jul 11, 2023

Currently I am running into the problem that manager.get.currentRound returns a round that only has Locked or Completed matches. This only happens if there are BYEs involved.

Probably similar to: #172

Summary

Version: 1.6.3


Example

import { BracketsManager } from 'brackets-manager';
import { JsonDatabase } from 'brackets-json-db';

const storage = new JsonDatabase();
const manager = new BracketsManager(storage);

async function main() {
  const stage = await manager.create({
    name: 'Some Title',
    tournamentId: 0,
    type: 'single_elimination',
    seeding: ['P1', 'P2', 'P3', null],
    settings: {
      grandFinal: 'simple',
      balanceByes: true,
      matchesChildCount: 3,
    },
  });

  console.log(await manager.get.currentRound(stage.id));
  // { id: 0, number: 1, stage_id: 0, group_id: 0 }
  console.log(await manager.get.currentMatches(stage.id));
  // [
  //   {
  //     id: 1,
  //     number: 2,
  //     stage_id: 0,
  //     group_id: 0,
  //     round_id: 0,
  //     child_count: 3,
  //     status: 2,
  //     opponent1: { id: 1, position: 2 },
  //     opponent2: { id: 2, position: 3 }
  //   }
  // ]

  await manager.update.match({ id: 1, opponent1: { result: 'win' } });

  console.log(await manager.get.currentRound(stage.id));
  // { id: 0, number: 1, stage_id: 0, group_id: 0 }
  // This should have been the second round because all the current Matches also are in the second round
  console.log(await manager.get.currentMatches(stage.id));
  // [
  //   {
  //     id: 2,
  //     number: 1,
  //     stage_id: 0,
  //     group_id: 0,
  //     round_id: 1,
  //     child_count: 3,
  //     status: 2,
  //     opponent1: { id: 0, position: undefined },
  //     opponent2: { id: 1, position: undefined },
  //   },
  // ];
}
main();
@Drarig29
Copy link
Owner

Thanks for the reproducible example! This could be a quick fix, but I noticed I have a few other issues related to this.

Like the fact that get.currentRound() should not be a thing anymore, because it's actually possible to have 2 rounds running at the same time: the final and the consolation final of a single elimination match.

And also in double elimination, where a round of the winner bracket can be played a the same time as a round of the loser bracket - although it's not implemented for double elimination yet, but it better be future proof.

@Tandashi
Copy link
Author

Would it maybe be useful to implement it similar to get.currentMatches but just for rounds?
Meaning get.currentRounds returns an array of all the rounds that can be played. Then the consumer can also sort by number if previous rounds want to be played first for example.

This would also work for both single_elimination and double_elimination.

@Drarig29
Copy link
Owner

I don't have the bandwidth to do it currently. PRs are welcome 😉

@Tandashi
Copy link
Author

Will make some room for this later today. Feel free to assign this to me if you'd like 😎

@Tandashi
Copy link
Author

I just implemented the quick fix for now due to time limitations as well :|

@Drarig29
Copy link
Owner

Drarig29 commented Jul 15, 2023

@Tandashi Can you maybe make a local patch on your repo for now?

With https://www.npmjs.com/package/patch-package for example.

Thanks for the PR but I won't have my computer for one week, I took some days off.

Tandashi added a commit to kocxyz/XYZBot that referenced this issue Jul 15, 2023
See:
- Drarig29/brackets-manager.js#180
- Drarig29/brackets-manager.js#181

This is a temporary fix till the official library code has been patched
and a new version 1.6.4 has been released.
@Drarig29 Drarig29 added the bug Something isn't working label Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants