-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Assign some players to fixed tables (#341)
* Refer to games rather than tables for double elim * Add fixed table number column for players * Apply fixed table number * Replace each_with_index with each * Call PairingSorters::Ranked directly * Add frozen_string_literal to DB migration * Fix RoundsController spec * Extract SwissTables module * Add swiss_tables_spec.rb * Remove extra empty line * Test choosing lowest fixed number * Test excluding fixed table numbers for other tables * Remove extra whitespace * Swap fixed table numbers so they need to be reversed * Input fixed table number * Adjust table number input * Adjust manual-seed class name * Adjust colour of unassign table number link * Assign table number when adding player * Test bye before fixed tables * Test bye after fixed tables * Change icon for fixed table number
- Loading branch information
Showing
20 changed files
with
297 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
$(document).on 'turbolinks:load', -> | ||
window.assignTableNumber = (playerId) -> | ||
if playerId | ||
form = $("form#edit_player_#{playerId}") | ||
else | ||
form = $('form.register-player') | ||
form.find('.form-group.table-number').removeClass('d-none') | ||
form.find('.assign-table-number').addClass('d-none') | ||
form.find('.unassign-table-number').removeClass('d-none') | ||
window.unassignTableNumber = (playerId) -> | ||
if playerId | ||
form = $("form#edit_player_#{playerId}") | ||
else | ||
form = $('form.register-player') | ||
form.find('.form-group.table-number input').val(null) | ||
form.find('.form-group.table-number').addClass('d-none') | ||
form.find('.assign-table-number').removeClass('d-none') | ||
form.find('.unassign-table-number').addClass('d-none') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# frozen_string_literal: true | ||
|
||
module SwissTables | ||
def self.assign_table_numbers!(pairings) | ||
PairingOrder.new(pairings).apply_numbers! | ||
end | ||
|
||
class PairingOrder | ||
def initialize(pairings) | ||
@non_byes = [] | ||
@byes = [] | ||
@fixed_tables = [] | ||
pairings.each do |pairing| | ||
if pairing.fixed_table_number? | ||
@fixed_tables << pairing | ||
elsif pairing.bye? | ||
@byes << pairing | ||
else | ||
@non_byes << pairing | ||
end | ||
end | ||
end | ||
|
||
def apply_numbers! | ||
numbers = Numbers.new | ||
@fixed_tables.each do |pairing| | ||
number = pairing.fixed_table_number | ||
numbers.exclude_fixed number | ||
pairing.update(table_number: number) | ||
end | ||
PairingSorters::Ranked.sort(@non_byes).each do |pairing| | ||
pairing.update(table_number: numbers.next) | ||
end | ||
@byes.each do |pairing| | ||
pairing.update(table_number: numbers.next) | ||
end | ||
end | ||
end | ||
|
||
class Numbers | ||
def initialize | ||
@fixed_numbers = Set[] | ||
@next_number = 1 | ||
end | ||
|
||
def exclude_fixed(number) | ||
@fixed_numbers << number | ||
end | ||
|
||
def next | ||
@next_number += 1 while @fixed_numbers.include? @next_number | ||
number = @next_number | ||
@next_number += 1 | ||
number | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class AddFixedTableToPlayers < ActiveRecord::Migration[7.1] | ||
def change | ||
add_column :players, :fixed_table_number, :integer | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.