mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Compare commits
30 Commits
64man
...
940f7b1d00
| Author | SHA1 | Date | |
|---|---|---|---|
| 940f7b1d00 | |||
| 52df73d14f | |||
| 8b03a74b1e | |||
| b4bca8f10a | |||
| af1f8df4b6 | |||
| 3576445a1c | |||
| 8c2ddf55ed | |||
| cfd3e7aecd | |||
| 608999cb51 | |||
| 6b5308360e | |||
| 9ca6572d9b | |||
| 61dc5e3cdd | |||
| af2fc3feba | |||
| 793a9e3ecc | |||
| f73e9bfc4e | |||
| 92bd06fe3c | |||
| 6e9554be55 | |||
| 34f1783031 | |||
| bbd2bd9b44 | |||
| 6ecebba70d | |||
| e64751e471 | |||
| d0f19e855f | |||
| 3e1ae22b6b | |||
| 15f85e439c | |||
| c5b9783853 | |||
| cd77268070 | |||
| d61ed80287 | |||
| dd5ce9bd60 | |||
| 9a4e6f6597 | |||
| 782baedcfe |
@@ -4,7 +4,8 @@
|
||||
- Do not add unnecessary comments to the code where you remove things.
|
||||
- Cypress tests are created for js tests. They can be found in cypress-tests/cypress
|
||||
- Cypress tests can be run with docker: bash cypress-tests/run-cypress-tests.sh
|
||||
- Rails tests can be run with docker: docker run -it -v $(pwd):/rails wrestlingdev-dev rake test
|
||||
- Write as little code as possible. I do not want crazy non standard rails implementations.
|
||||
- This project is using propshaft and importmap.
|
||||
- Stimulus is used for javascript.
|
||||
- Use the context7 mcp server for context.
|
||||
- use context7
|
||||
|
||||
8
.gitignore
vendored
8
.gitignore
vendored
@@ -27,4 +27,10 @@ frontend/node_modules
|
||||
cypress-tests/cypress/screenshots
|
||||
cypress-tests/cypress/videos
|
||||
|
||||
.DS_Store
|
||||
.DS_Store
|
||||
|
||||
# generated with npx repomix
|
||||
# repomix-output.xml
|
||||
|
||||
# generated by cine mcp settings
|
||||
~/
|
||||
11
Gemfile
11
Gemfile
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
|
||||
|
||||
ruby '3.2.0'
|
||||
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
||||
gem 'rails', '8.0.2'
|
||||
gem 'rails', '8.0.3'
|
||||
|
||||
# Added in rails 7.1
|
||||
gem 'rails-html-sanitizer'
|
||||
@@ -74,17 +74,16 @@ gem 'solid_cable'
|
||||
gem 'puma'
|
||||
gem 'tzinfo-data'
|
||||
gem 'daemons'
|
||||
# Interface for viewing and managing background jobs
|
||||
# gem 'delayed_job_web'
|
||||
# Note: solid_queue-ui is not compatible with Rails 8.0 yet
|
||||
# We'll create a custom UI or wait for compatibility updates
|
||||
# gem 'solid_queue_ui', '~> 0.1.1'
|
||||
# Solid Queue UI
|
||||
gem "mission_control-jobs"
|
||||
|
||||
|
||||
group :development do
|
||||
# gem 'rubocop'
|
||||
gem 'bullet'
|
||||
gem 'brakeman'
|
||||
gem 'bundler-audit'
|
||||
gem 'rubocop'
|
||||
end
|
||||
|
||||
group :development, :test do
|
||||
|
||||
262
Gemfile.lock
262
Gemfile.lock
@@ -1,29 +1,29 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
actioncable (8.0.2)
|
||||
actionpack (= 8.0.2)
|
||||
activesupport (= 8.0.2)
|
||||
actioncable (8.0.3)
|
||||
actionpack (= 8.0.3)
|
||||
activesupport (= 8.0.3)
|
||||
nio4r (~> 2.0)
|
||||
websocket-driver (>= 0.6.1)
|
||||
zeitwerk (~> 2.6)
|
||||
actionmailbox (8.0.2)
|
||||
actionpack (= 8.0.2)
|
||||
activejob (= 8.0.2)
|
||||
activerecord (= 8.0.2)
|
||||
activestorage (= 8.0.2)
|
||||
activesupport (= 8.0.2)
|
||||
actionmailbox (8.0.3)
|
||||
actionpack (= 8.0.3)
|
||||
activejob (= 8.0.3)
|
||||
activerecord (= 8.0.3)
|
||||
activestorage (= 8.0.3)
|
||||
activesupport (= 8.0.3)
|
||||
mail (>= 2.8.0)
|
||||
actionmailer (8.0.2)
|
||||
actionpack (= 8.0.2)
|
||||
actionview (= 8.0.2)
|
||||
activejob (= 8.0.2)
|
||||
activesupport (= 8.0.2)
|
||||
actionmailer (8.0.3)
|
||||
actionpack (= 8.0.3)
|
||||
actionview (= 8.0.3)
|
||||
activejob (= 8.0.3)
|
||||
activesupport (= 8.0.3)
|
||||
mail (>= 2.8.0)
|
||||
rails-dom-testing (~> 2.2)
|
||||
actionpack (8.0.2)
|
||||
actionview (= 8.0.2)
|
||||
activesupport (= 8.0.2)
|
||||
actionpack (8.0.3)
|
||||
actionview (= 8.0.3)
|
||||
activesupport (= 8.0.3)
|
||||
nokogiri (>= 1.8.5)
|
||||
rack (>= 2.2.4)
|
||||
rack-session (>= 1.0.1)
|
||||
@@ -31,35 +31,35 @@ GEM
|
||||
rails-dom-testing (~> 2.2)
|
||||
rails-html-sanitizer (~> 1.6)
|
||||
useragent (~> 0.16)
|
||||
actiontext (8.0.2)
|
||||
actionpack (= 8.0.2)
|
||||
activerecord (= 8.0.2)
|
||||
activestorage (= 8.0.2)
|
||||
activesupport (= 8.0.2)
|
||||
actiontext (8.0.3)
|
||||
actionpack (= 8.0.3)
|
||||
activerecord (= 8.0.3)
|
||||
activestorage (= 8.0.3)
|
||||
activesupport (= 8.0.3)
|
||||
globalid (>= 0.6.0)
|
||||
nokogiri (>= 1.8.5)
|
||||
actionview (8.0.2)
|
||||
activesupport (= 8.0.2)
|
||||
actionview (8.0.3)
|
||||
activesupport (= 8.0.3)
|
||||
builder (~> 3.1)
|
||||
erubi (~> 1.11)
|
||||
rails-dom-testing (~> 2.2)
|
||||
rails-html-sanitizer (~> 1.6)
|
||||
activejob (8.0.2)
|
||||
activesupport (= 8.0.2)
|
||||
activejob (8.0.3)
|
||||
activesupport (= 8.0.3)
|
||||
globalid (>= 0.3.6)
|
||||
activemodel (8.0.2)
|
||||
activesupport (= 8.0.2)
|
||||
activerecord (8.0.2)
|
||||
activemodel (= 8.0.2)
|
||||
activesupport (= 8.0.2)
|
||||
activemodel (8.0.3)
|
||||
activesupport (= 8.0.3)
|
||||
activerecord (8.0.3)
|
||||
activemodel (= 8.0.3)
|
||||
activesupport (= 8.0.3)
|
||||
timeout (>= 0.4.0)
|
||||
activestorage (8.0.2)
|
||||
actionpack (= 8.0.2)
|
||||
activejob (= 8.0.2)
|
||||
activerecord (= 8.0.2)
|
||||
activesupport (= 8.0.2)
|
||||
activestorage (8.0.3)
|
||||
actionpack (= 8.0.3)
|
||||
activejob (= 8.0.3)
|
||||
activerecord (= 8.0.3)
|
||||
activesupport (= 8.0.3)
|
||||
marcel (~> 1.0)
|
||||
activesupport (8.0.2)
|
||||
activesupport (8.0.3)
|
||||
base64
|
||||
benchmark (>= 0.3)
|
||||
bigdecimal
|
||||
@@ -72,16 +72,17 @@ GEM
|
||||
securerandom (>= 0.3)
|
||||
tzinfo (~> 2.0, >= 2.0.5)
|
||||
uri (>= 0.13.1)
|
||||
base64 (0.2.0)
|
||||
ast (2.4.3)
|
||||
base64 (0.3.0)
|
||||
bcrypt (3.1.20)
|
||||
benchmark (0.4.0)
|
||||
bigdecimal (3.1.9)
|
||||
benchmark (0.4.1)
|
||||
bigdecimal (3.3.0)
|
||||
bootsnap (1.18.6)
|
||||
msgpack (~> 1.2)
|
||||
brakeman (7.0.2)
|
||||
brakeman (7.1.0)
|
||||
racc
|
||||
builder (3.3.0)
|
||||
bullet (8.0.7)
|
||||
bullet (8.0.8)
|
||||
activesupport (>= 3.0.0)
|
||||
uniform_notifier (~> 1.11)
|
||||
bundler-audit (0.9.2)
|
||||
@@ -89,22 +90,23 @@ GEM
|
||||
thor (~> 1.0)
|
||||
cancancan (3.6.1)
|
||||
concurrent-ruby (1.3.5)
|
||||
connection_pool (2.5.3)
|
||||
connection_pool (2.5.4)
|
||||
crass (1.0.6)
|
||||
daemons (1.4.1)
|
||||
date (3.4.1)
|
||||
drb (2.2.1)
|
||||
drb (2.2.3)
|
||||
erb (5.0.3)
|
||||
erubi (1.13.1)
|
||||
et-orbi (1.2.11)
|
||||
et-orbi (1.4.0)
|
||||
tzinfo
|
||||
fugit (1.11.1)
|
||||
fugit (1.11.2)
|
||||
et-orbi (~> 1, >= 1.2.11)
|
||||
raabro (~> 1.4)
|
||||
globalid (1.2.1)
|
||||
globalid (1.3.0)
|
||||
activesupport (>= 6.1)
|
||||
i18n (1.14.7)
|
||||
concurrent-ruby (~> 1.0)
|
||||
importmap-rails (2.1.0)
|
||||
importmap-rails (2.2.2)
|
||||
actionpack (>= 6.0.0)
|
||||
activesupport (>= 6.0.0)
|
||||
railties (>= 6.0.0)
|
||||
@@ -112,18 +114,21 @@ GEM
|
||||
influxdb-rails (1.0.3)
|
||||
influxdb (~> 0.6, >= 0.6.4)
|
||||
railties (>= 5.0)
|
||||
io-console (0.8.0)
|
||||
io-console (0.8.1)
|
||||
irb (1.15.2)
|
||||
pp (>= 0.6.0)
|
||||
rdoc (>= 4.0.0)
|
||||
reline (>= 0.4.2)
|
||||
jbuilder (2.13.0)
|
||||
actionview (>= 5.0.0)
|
||||
activesupport (>= 5.0.0)
|
||||
jbuilder (2.14.1)
|
||||
actionview (>= 7.0.0)
|
||||
activesupport (>= 7.0.0)
|
||||
jquery-rails (4.6.0)
|
||||
rails-dom-testing (>= 1, < 3)
|
||||
railties (>= 4.2.0)
|
||||
thor (>= 0.14, < 2.0)
|
||||
json (2.15.1)
|
||||
language_server-protocol (3.17.0.5)
|
||||
lint_roller (1.1.0)
|
||||
logger (1.7.0)
|
||||
loofah (2.24.1)
|
||||
crass (~> 1.0.2)
|
||||
@@ -133,14 +138,25 @@ GEM
|
||||
net-imap
|
||||
net-pop
|
||||
net-smtp
|
||||
marcel (1.0.4)
|
||||
marcel (1.1.0)
|
||||
mini_mime (1.1.5)
|
||||
minitest (5.25.5)
|
||||
mission_control-jobs (1.1.0)
|
||||
actioncable (>= 7.1)
|
||||
actionpack (>= 7.1)
|
||||
activejob (>= 7.1)
|
||||
activerecord (>= 7.1)
|
||||
importmap-rails (>= 1.2.1)
|
||||
irb (~> 1.13)
|
||||
railties (>= 7.1)
|
||||
stimulus-rails
|
||||
turbo-rails
|
||||
mocha (2.7.1)
|
||||
ruby2_keywords (>= 0.0.5)
|
||||
msgpack (1.8.0)
|
||||
mysql2 (0.5.6)
|
||||
net-imap (0.5.8)
|
||||
mysql2 (0.5.7)
|
||||
bigdecimal
|
||||
net-imap (0.5.12)
|
||||
date
|
||||
net-protocol
|
||||
net-pop (0.1.2)
|
||||
@@ -150,38 +166,42 @@ GEM
|
||||
net-smtp (0.5.1)
|
||||
net-protocol
|
||||
nio4r (2.7.4)
|
||||
nokogiri (1.18.8-aarch64-linux-gnu)
|
||||
nokogiri (1.18.10-aarch64-linux-gnu)
|
||||
racc (~> 1.4)
|
||||
nokogiri (1.18.8-aarch64-linux-musl)
|
||||
nokogiri (1.18.10-aarch64-linux-musl)
|
||||
racc (~> 1.4)
|
||||
nokogiri (1.18.8-arm-linux-gnu)
|
||||
nokogiri (1.18.10-arm-linux-gnu)
|
||||
racc (~> 1.4)
|
||||
nokogiri (1.18.8-arm-linux-musl)
|
||||
nokogiri (1.18.10-arm-linux-musl)
|
||||
racc (~> 1.4)
|
||||
nokogiri (1.18.8-arm64-darwin)
|
||||
nokogiri (1.18.10-arm64-darwin)
|
||||
racc (~> 1.4)
|
||||
nokogiri (1.18.8-x86_64-darwin)
|
||||
nokogiri (1.18.10-x86_64-darwin)
|
||||
racc (~> 1.4)
|
||||
nokogiri (1.18.8-x86_64-linux-gnu)
|
||||
nokogiri (1.18.10-x86_64-linux-gnu)
|
||||
racc (~> 1.4)
|
||||
nokogiri (1.18.8-x86_64-linux-musl)
|
||||
nokogiri (1.18.10-x86_64-linux-musl)
|
||||
racc (~> 1.4)
|
||||
pp (0.6.2)
|
||||
parallel (1.27.0)
|
||||
parser (3.3.9.0)
|
||||
ast (~> 2.4.1)
|
||||
racc
|
||||
pp (0.6.3)
|
||||
prettyprint
|
||||
prettyprint (0.2.0)
|
||||
propshaft (1.1.0)
|
||||
prism (1.5.1)
|
||||
propshaft (1.3.1)
|
||||
actionpack (>= 7.0.0)
|
||||
activesupport (>= 7.0.0)
|
||||
rack
|
||||
railties (>= 7.0.0)
|
||||
psych (5.2.6)
|
||||
date
|
||||
stringio
|
||||
puma (6.6.0)
|
||||
puma (7.0.4)
|
||||
nio4r (~> 2.0)
|
||||
raabro (1.4.0)
|
||||
racc (1.8.1)
|
||||
rack (3.1.14)
|
||||
rack (3.2.2)
|
||||
rack-session (2.1.1)
|
||||
base64 (>= 0.1.0)
|
||||
rack (>= 3.0.0)
|
||||
@@ -189,25 +209,25 @@ GEM
|
||||
rack (>= 1.3)
|
||||
rackup (2.2.1)
|
||||
rack (>= 3)
|
||||
rails (8.0.2)
|
||||
actioncable (= 8.0.2)
|
||||
actionmailbox (= 8.0.2)
|
||||
actionmailer (= 8.0.2)
|
||||
actionpack (= 8.0.2)
|
||||
actiontext (= 8.0.2)
|
||||
actionview (= 8.0.2)
|
||||
activejob (= 8.0.2)
|
||||
activemodel (= 8.0.2)
|
||||
activerecord (= 8.0.2)
|
||||
activestorage (= 8.0.2)
|
||||
activesupport (= 8.0.2)
|
||||
rails (8.0.3)
|
||||
actioncable (= 8.0.3)
|
||||
actionmailbox (= 8.0.3)
|
||||
actionmailer (= 8.0.3)
|
||||
actionpack (= 8.0.3)
|
||||
actiontext (= 8.0.3)
|
||||
actionview (= 8.0.3)
|
||||
activejob (= 8.0.3)
|
||||
activemodel (= 8.0.3)
|
||||
activerecord (= 8.0.3)
|
||||
activestorage (= 8.0.3)
|
||||
activesupport (= 8.0.3)
|
||||
bundler (>= 1.15.0)
|
||||
railties (= 8.0.2)
|
||||
railties (= 8.0.3)
|
||||
rails-controller-testing (1.0.5)
|
||||
actionpack (>= 5.0.1.rc1)
|
||||
actionview (>= 5.0.1.rc1)
|
||||
activesupport (>= 5.0.1.rc1)
|
||||
rails-dom-testing (2.2.0)
|
||||
rails-dom-testing (2.3.0)
|
||||
activesupport (>= 5.0.0)
|
||||
minitest
|
||||
nokogiri (>= 1.6)
|
||||
@@ -219,26 +239,46 @@ GEM
|
||||
rails_stdout_logging
|
||||
rails_serve_static_assets (0.0.5)
|
||||
rails_stdout_logging (0.0.5)
|
||||
railties (8.0.2)
|
||||
actionpack (= 8.0.2)
|
||||
activesupport (= 8.0.2)
|
||||
railties (8.0.3)
|
||||
actionpack (= 8.0.3)
|
||||
activesupport (= 8.0.3)
|
||||
irb (~> 1.13)
|
||||
rackup (>= 1.0.0)
|
||||
rake (>= 12.2)
|
||||
thor (~> 1.0, >= 1.2.2)
|
||||
tsort (>= 0.2)
|
||||
zeitwerk (~> 2.6)
|
||||
rake (13.2.1)
|
||||
rainbow (3.1.1)
|
||||
rake (13.3.0)
|
||||
rb-readline (0.5.5)
|
||||
rdoc (6.13.1)
|
||||
rdoc (6.15.0)
|
||||
erb
|
||||
psych (>= 4.0.0)
|
||||
reline (0.6.1)
|
||||
tsort
|
||||
regexp_parser (2.11.3)
|
||||
reline (0.6.2)
|
||||
io-console (~> 0.5)
|
||||
round_robin_tournament (0.1.2)
|
||||
rubocop (1.81.1)
|
||||
json (~> 2.3)
|
||||
language_server-protocol (~> 3.17.0.2)
|
||||
lint_roller (~> 1.1.0)
|
||||
parallel (~> 1.10)
|
||||
parser (>= 3.3.0.2)
|
||||
rainbow (>= 2.2.2, < 4.0)
|
||||
regexp_parser (>= 2.9.3, < 3.0)
|
||||
rubocop-ast (>= 1.47.1, < 2.0)
|
||||
ruby-progressbar (~> 1.7)
|
||||
unicode-display_width (>= 2.4.0, < 4.0)
|
||||
rubocop-ast (1.47.1)
|
||||
parser (>= 3.3.7.2)
|
||||
prism (~> 1.4)
|
||||
ruby-progressbar (1.13.0)
|
||||
ruby2_keywords (0.0.5)
|
||||
sdoc (2.6.1)
|
||||
sdoc (2.6.4)
|
||||
rdoc (>= 5.0)
|
||||
securerandom (0.4.1)
|
||||
solid_cable (3.0.8)
|
||||
solid_cable (3.0.12)
|
||||
actioncable (>= 7.2)
|
||||
activejob (>= 7.2)
|
||||
activerecord (>= 7.2)
|
||||
@@ -247,42 +287,46 @@ GEM
|
||||
activejob (>= 7.2)
|
||||
activerecord (>= 7.2)
|
||||
railties (>= 7.2)
|
||||
solid_queue (1.1.5)
|
||||
solid_queue (1.2.1)
|
||||
activejob (>= 7.1)
|
||||
activerecord (>= 7.1)
|
||||
concurrent-ruby (>= 1.3.1)
|
||||
fugit (~> 1.11.0)
|
||||
railties (>= 7.1)
|
||||
thor (~> 1.3.1)
|
||||
spring (4.3.0)
|
||||
sqlite3 (2.6.0-aarch64-linux-gnu)
|
||||
sqlite3 (2.6.0-aarch64-linux-musl)
|
||||
sqlite3 (2.6.0-arm-linux-gnu)
|
||||
sqlite3 (2.6.0-arm-linux-musl)
|
||||
sqlite3 (2.6.0-arm64-darwin)
|
||||
sqlite3 (2.6.0-x86_64-darwin)
|
||||
sqlite3 (2.6.0-x86_64-linux-gnu)
|
||||
sqlite3 (2.6.0-x86_64-linux-musl)
|
||||
thor (>= 1.3.1)
|
||||
spring (4.4.0)
|
||||
sqlite3 (2.7.4-aarch64-linux-gnu)
|
||||
sqlite3 (2.7.4-aarch64-linux-musl)
|
||||
sqlite3 (2.7.4-arm-linux-gnu)
|
||||
sqlite3 (2.7.4-arm-linux-musl)
|
||||
sqlite3 (2.7.4-arm64-darwin)
|
||||
sqlite3 (2.7.4-x86_64-darwin)
|
||||
sqlite3 (2.7.4-x86_64-linux-gnu)
|
||||
sqlite3 (2.7.4-x86_64-linux-musl)
|
||||
stimulus-rails (1.3.4)
|
||||
railties (>= 6.0.0)
|
||||
stringio (3.1.7)
|
||||
thor (1.3.2)
|
||||
thor (1.4.0)
|
||||
timeout (0.4.3)
|
||||
turbo-rails (2.0.13)
|
||||
tsort (0.2.0)
|
||||
turbo-rails (2.0.17)
|
||||
actionpack (>= 7.1.0)
|
||||
railties (>= 7.1.0)
|
||||
tzinfo (2.0.6)
|
||||
concurrent-ruby (~> 1.0)
|
||||
tzinfo-data (1.2025.2)
|
||||
tzinfo (>= 1.0.0)
|
||||
uniform_notifier (1.17.0)
|
||||
uri (1.0.3)
|
||||
unicode-display_width (3.2.0)
|
||||
unicode-emoji (~> 4.1)
|
||||
unicode-emoji (4.1.0)
|
||||
uniform_notifier (1.18.0)
|
||||
uri (1.0.4)
|
||||
useragent (0.16.11)
|
||||
websocket-driver (0.7.7)
|
||||
websocket-driver (0.8.0)
|
||||
base64
|
||||
websocket-extensions (>= 0.1.0)
|
||||
websocket-extensions (0.1.5)
|
||||
zeitwerk (2.7.2)
|
||||
zeitwerk (2.7.3)
|
||||
|
||||
PLATFORMS
|
||||
aarch64-linux-gnu
|
||||
@@ -306,16 +350,18 @@ DEPENDENCIES
|
||||
influxdb-rails
|
||||
jbuilder
|
||||
jquery-rails
|
||||
mission_control-jobs
|
||||
mocha
|
||||
mysql2
|
||||
propshaft
|
||||
puma
|
||||
rails (= 8.0.2)
|
||||
rails (= 8.0.3)
|
||||
rails-controller-testing
|
||||
rails-html-sanitizer
|
||||
rails_12factor
|
||||
rb-readline
|
||||
round_robin_tournament
|
||||
rubocop
|
||||
sdoc
|
||||
solid_cable
|
||||
solid_cache
|
||||
|
||||
10
README.md
10
README.md
@@ -148,6 +148,9 @@ Available system resources: X CPU(s), YMMMB RAM
|
||||
SolidQueue plugin enabled in Puma
|
||||
```
|
||||
|
||||
I have deployed Mission Control as a UI for SolidQueue. The uri for mission control is `/jobs`.
|
||||
For the development environment, the user/password is dev/secret. For the production environment, it is defined by environment variables WRESTLINGDEV_MISSION_CONTROL_USER/WRESTLINGDEV_MISSION_CONTROL_PASSWORD. You can see this in `config/environments/production.rb` and `config/environments/development.rb`.
|
||||
|
||||
## Environment Variables
|
||||
|
||||
### Required Environment Variables
|
||||
@@ -160,6 +163,8 @@ SolidQueue plugin enabled in Puma
|
||||
* `WRESTLINGDEV_SECRET_KEY_BASE` - Rails application secret key (can be generated with `rake secret`)
|
||||
* `WRESTLINGDEV_EMAIL` - Email address (currently must be a Gmail account)
|
||||
* `WRESTLINGDEV_EMAIL_PWD` - Email password
|
||||
* `WRESTLINGDEV_MISSION_CONTROL_USER` - mission control username
|
||||
* `WRESTLINGDEV_MISSION_CONTROL_PASSWORD` - mission control password
|
||||
|
||||
### Optional Environment Variables
|
||||
* `SOLID_QUEUE_IN_PUMA` - Set to "true" to run Solid Queue workers inside Puma (default in development)
|
||||
@@ -206,4 +211,7 @@ The application has been migrated from using vanilla JavaScript to Hotwired Stim
|
||||
- `app/assets/javascripts/controllers/` - Contains all Stimulus controllers
|
||||
- `app/assets/javascripts/application.js` - Registers and loads all controllers
|
||||
|
||||
The importmap configuration in `config/importmap.rb` handles the loading of all JavaScript dependencies including Stimulus controllers.
|
||||
The importmap configuration in `config/importmap.rb` handles the loading of all JavaScript dependencies including Stimulus controllers.
|
||||
|
||||
# Using Repomix with LLMs
|
||||
`npx repomix app test`
|
||||
|
||||
@@ -221,12 +221,26 @@ class TournamentsController < ApplicationController
|
||||
end
|
||||
|
||||
def index
|
||||
if params[:search]
|
||||
# @tournaments = Tournament.limit(200).search(params[:search]).order("date DESC")
|
||||
@tournaments = Tournament.limit(200).search_date_name(params[:search]).order("date DESC")
|
||||
# Simple manual pagination to avoid introducing a gem.
|
||||
per_page = 20
|
||||
page = params[:page].to_i > 0 ? params[:page].to_i : 1
|
||||
offset = (page - 1) * per_page
|
||||
|
||||
if params[:search].present?
|
||||
tournaments = Tournament.search_date_name(params[:search]).to_a
|
||||
else
|
||||
@tournaments = Tournament.all.sort_by{|t| t.days_until_start}.first(20)
|
||||
tournaments = Tournament.all.to_a
|
||||
end
|
||||
|
||||
# Sort by distance from today (closest first)
|
||||
today = Date.today
|
||||
tournaments.sort_by! { |t| (t.date - today).abs }
|
||||
|
||||
@total_count = tournaments.size
|
||||
@total_pages = (@total_count / per_page.to_f).ceil
|
||||
@page = page
|
||||
@per_page = per_page
|
||||
@tournaments = tournaments.slice(offset, per_page) || []
|
||||
end
|
||||
|
||||
def show
|
||||
@@ -286,7 +300,7 @@ class TournamentsController < ApplicationController
|
||||
|
||||
def reset_bout_board
|
||||
@tournament.reset_and_fill_bout_board
|
||||
redirect_to tournament_path(@tournament), notice: "Successfully reset the bout board."
|
||||
redirect_to tournament_path(@tournament), notice: "Successfully reset the bout board. Please have all mat table workers refresh their page."
|
||||
end
|
||||
|
||||
def generate_school_keys
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
class AdvanceWrestlerJob < ApplicationJob
|
||||
queue_as :default
|
||||
# associations are not available here so we had to pass tournament_id when creating the job
|
||||
limits_concurrency to: 1, key: ->(_wrestler, _match, tournament_id) { "tournament:#{tournament_id}" }
|
||||
|
||||
def perform(wrestler, match)
|
||||
# Add a small delay to increase chance of transaction commit
|
||||
# without this some matches were getting a deserialization error when running the rake task
|
||||
# to finish tournaments
|
||||
sleep(0.5) unless Rails.env.test?
|
||||
|
||||
def perform(wrestler, match, tournament_id)
|
||||
# Get tournament from wrestler
|
||||
tournament = wrestler.tournament
|
||||
|
||||
@@ -34,4 +31,4 @@ class AdvanceWrestlerJob < ApplicationJob
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class CalculateSchoolScoreJob < ApplicationJob
|
||||
queue_as :default
|
||||
limits_concurrency to: 1, key: ->(school) { "tournament:#{school.tournament_id}" }
|
||||
|
||||
# Need for TournamentJobStatusIntegrationTest
|
||||
def self.perform_sync(school)
|
||||
@@ -35,4 +36,4 @@ class CalculateSchoolScoreJob < ApplicationJob
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class GenerateTournamentMatchesJob < ApplicationJob
|
||||
queue_as :default
|
||||
limits_concurrency to: 1, key: ->(tournament) { "tournament:#{tournament.id}" }
|
||||
|
||||
def perform(tournament)
|
||||
# Log information about the job
|
||||
@@ -17,4 +18,4 @@ class GenerateTournamentMatchesJob < ApplicationJob
|
||||
raise # Re-raise the error so it's properly recorded
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class TournamentBackupJob < ApplicationJob
|
||||
queue_as :default
|
||||
limits_concurrency to: 1, key: ->(tournament) { "tournament:#{tournament.id}" }
|
||||
|
||||
def perform(tournament, reason = nil)
|
||||
# Log information about the job
|
||||
@@ -29,4 +30,4 @@ class TournamentBackupJob < ApplicationJob
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -17,7 +17,8 @@ class TournamentCleanupJob < ApplicationJob
|
||||
has_real_matches = tournament.matches.where(finished: 1).where.not(win_type: 'BYE').exists?
|
||||
|
||||
if has_real_matches
|
||||
|
||||
tournament.tournament_backups.destroy_all
|
||||
|
||||
# 1. Remove all school delegates
|
||||
tournament.schools.each do |school|
|
||||
school.delegates.destroy_all
|
||||
@@ -33,4 +34,4 @@ class TournamentCleanupJob < ApplicationJob
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class WrestlingdevImportJob < ApplicationJob
|
||||
queue_as :default
|
||||
limits_concurrency to: 1, key: ->(tournament) { "tournament:#{tournament.id}" }
|
||||
|
||||
def perform(tournament, import_data = nil)
|
||||
# Log information about the job
|
||||
@@ -30,4 +31,4 @@ class WrestlingdevImportJob < ApplicationJob
|
||||
raise e
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,20 @@
|
||||
class Ability
|
||||
include CanCan::Ability
|
||||
|
||||
def school_permission_key_check(school_permission_key)
|
||||
# Can read school if tournament is public or a valid school permission key is provided
|
||||
can :read, School do |school|
|
||||
school.tournament.is_public ||
|
||||
(school_permission_key.present? && school.permission_key == school_permission_key)
|
||||
end
|
||||
|
||||
# Can manage school if a valid school permission key is provided
|
||||
# school_permission_key comes from app/controllers/application_controller.rb
|
||||
can :manage, School do |school|
|
||||
(school_permission_key.present? && school.permission_key == school_permission_key)
|
||||
end
|
||||
end
|
||||
|
||||
def initialize(user, school_permission_key = nil)
|
||||
if user
|
||||
# LOGGED IN USER PERMISSIONS
|
||||
@@ -46,6 +60,8 @@ class Ability
|
||||
school.tournament.delegates.map(&:user_id).include?(user.id) ||
|
||||
school.tournament.user_id == user.id
|
||||
end
|
||||
|
||||
school_permission_key_check(school_permission_key)
|
||||
else
|
||||
# NON LOGGED IN USER PERMISSIONS
|
||||
|
||||
@@ -58,18 +74,7 @@ class Ability
|
||||
|
||||
# SCHOOL PERMISSIONS
|
||||
# wrestler permissions are included with school permissions
|
||||
|
||||
# Can read school if tournament is public or a valid school permission key is provided
|
||||
can :read, School do |school|
|
||||
school.tournament.is_public ||
|
||||
(school_permission_key.present? && school.permission_key == school_permission_key)
|
||||
end
|
||||
|
||||
# Can read school if a valid school permission key is provided
|
||||
# school_permission_key comes from app/controllers/application_controller.rb
|
||||
can :manage, School do |school|
|
||||
(school_permission_key.present? && school.permission_key == school_permission_key)
|
||||
end
|
||||
school_permission_key_check(school_permission_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Mat < ApplicationRecord
|
||||
belongs_to :tournament
|
||||
has_many :matches, dependent: :destroy
|
||||
has_many :matches, dependent: :nullify
|
||||
has_many :mat_assignment_rules, dependent: :destroy
|
||||
|
||||
validates :name, presence: true
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
class Match < ApplicationRecord
|
||||
include ActionView::RecordIdentifier
|
||||
|
||||
belongs_to :tournament, touch: true
|
||||
belongs_to :weight, touch: true
|
||||
belongs_to :mat, touch: true, optional: true
|
||||
@@ -10,12 +12,21 @@ class Match < ApplicationRecord
|
||||
# Callback to update finished_at when a match is finished
|
||||
before_save :update_finished_at
|
||||
|
||||
after_update :after_finished_actions, if: -> {
|
||||
saved_change_to_finished? ||
|
||||
saved_change_to_winner_id? ||
|
||||
saved_change_to_win_type? ||
|
||||
saved_change_to_score? ||
|
||||
saved_change_to_overtime_type?
|
||||
# update mat show with correct match if bout board is reset
|
||||
# this is done with a turbo stream
|
||||
after_commit :broadcast_mat_assignment_change, if: :saved_change_to_mat_id?, on: [:create, :update]
|
||||
|
||||
# Enqueue advancement and related actions after the DB transaction has committed.
|
||||
# Using after_commit ensures any background jobs enqueued inside these callbacks
|
||||
# will see the committed state of the match (e.g. finished == 1). Enqueuing
|
||||
# jobs from after_update can cause jobs to run before the transaction commits,
|
||||
# which leads to jobs observing stale data and not performing advancement.
|
||||
after_commit :after_finished_actions, on: :update, if: -> {
|
||||
saved_change_to_finished? ||
|
||||
saved_change_to_winner_id? ||
|
||||
saved_change_to_win_type? ||
|
||||
saved_change_to_score? ||
|
||||
saved_change_to_overtime_type?
|
||||
}
|
||||
|
||||
def after_finished_actions
|
||||
@@ -30,7 +41,8 @@ class Match < ApplicationRecord
|
||||
self.mat.assign_next_match
|
||||
end
|
||||
advance_wrestlers
|
||||
calculate_school_points
|
||||
# School point calculation has move to the end of advance wrestler
|
||||
# calculate_school_points
|
||||
end
|
||||
end
|
||||
|
||||
@@ -44,7 +56,7 @@ class Match < ApplicationRecord
|
||||
errors.add(:winner_id, "cannot be blank")
|
||||
end
|
||||
if win_type == "Pin" and ! score.match(/^[0-5]?[0-9]:[0-5][0-9]/)
|
||||
errors.add(:score, "needs to be in time format MM:SS when win type is Pin example: 1:23 or 10:03")
|
||||
errors.add(:score, "needs to be in time format MM:SS when win type is Pin example: 2:23, 0:25, 10:03")
|
||||
end
|
||||
if win_type == "Decision" or win_type == "Tech Fall" or win_type == "Major" and ! score.match(/^[0-9]?[0-9]-[0-9]?[0-9]/)
|
||||
errors.add(:score, "needs to be in Number-Number format when win type is Decision, Tech Fall, and Major example: 10-2")
|
||||
@@ -328,4 +340,26 @@ class Match < ApplicationRecord
|
||||
self.finished_at = Time.current.utc
|
||||
end
|
||||
end
|
||||
|
||||
def broadcast_mat_assignment_change
|
||||
old_mat_id, new_mat_id = saved_change_to_mat_id || previous_changes["mat_id"]
|
||||
return unless old_mat_id || new_mat_id
|
||||
|
||||
[old_mat_id, new_mat_id].compact.uniq.each do |mat_id|
|
||||
mat = Mat.find_by(id: mat_id)
|
||||
next unless mat
|
||||
|
||||
Turbo::StreamsChannel.broadcast_update_to(
|
||||
mat,
|
||||
target: dom_id(mat, :current_match),
|
||||
partial: "mats/current_match",
|
||||
locals: {
|
||||
mat: mat,
|
||||
match: mat.unfinished_matches.first,
|
||||
next_match: mat.unfinished_matches.second,
|
||||
show_next_bout_button: true
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -157,10 +157,10 @@ class Tournament < ApplicationRecord
|
||||
def double_elim_number_of_wrestlers_error
|
||||
error_string = ""
|
||||
if self.tournament_type == "Double Elimination 1-6" or self.tournament_type == "Double Elimination 1-8"
|
||||
weights_with_too_many_wrestlers = weights.select{|w| w.wrestlers.size > 32}
|
||||
weights_with_too_many_wrestlers = weights.select{|w| w.wrestlers.size > 64}
|
||||
weight_with_too_few_wrestlers = weights.select{|w| w.wrestlers.size < 4}
|
||||
weights_with_too_many_wrestlers.each do |weight|
|
||||
error_string = error_string + " The weight class #{weight.max} has more than 16 wrestlers."
|
||||
error_string = error_string + " The weight class #{weight.max} has more than 64 wrestlers."
|
||||
end
|
||||
weight_with_too_few_wrestlers.each do |weight|
|
||||
error_string = error_string + " The weight class #{weight.max} has less than 4 wrestlers."
|
||||
|
||||
@@ -2,9 +2,13 @@ class Wrestler < ApplicationRecord
|
||||
belongs_to :school, touch: true
|
||||
belongs_to :weight, touch: true
|
||||
has_one :tournament, through: :weight
|
||||
has_many :deductedPoints, class_name: "Teampointadjust", dependent: :destroy
|
||||
## Matches association
|
||||
# Rails associations expect only a single column so we cannot do a w1 OR w2
|
||||
# So we have to create two associations and combine them with the all_matches method
|
||||
has_many :matches_as_w1, ->(wrestler){ where(weight_id: wrestler.weight_id) }, class_name: 'Match', foreign_key: 'w1'
|
||||
has_many :matches_as_w2, ->(wrestler){ where(weight_id: wrestler.weight_id) }, class_name: 'Match', foreign_key: 'w2'
|
||||
has_many :deductedPoints, class_name: "Teampointadjust", dependent: :destroy
|
||||
##
|
||||
attr_accessor :poolAdvancePoints, :originalId, :swapId
|
||||
|
||||
validates :name, :weight_id, :school_id, presence: true
|
||||
|
||||
@@ -8,16 +8,18 @@ class AdvanceWrestler
|
||||
def advance
|
||||
# Use perform_later which will execute based on centralized adapter config
|
||||
# This will be converted to inline execution in test environment by ActiveJob
|
||||
AdvanceWrestlerJob.perform_later(@wrestler, @last_match)
|
||||
AdvanceWrestlerJob.perform_later(@wrestler, @last_match, @tournament.id)
|
||||
end
|
||||
|
||||
def advance_raw
|
||||
|
||||
@last_match.reload
|
||||
@wrestler.reload
|
||||
if @last_match && @last_match.finished?
|
||||
pool_to_bracket_advancement if @tournament.tournament_type == "Pool to bracket"
|
||||
ModifiedDoubleEliminationAdvance.new(@wrestler, @last_match).bracket_advancement if @tournament.tournament_type.include? "Modified 16 Man Double Elimination"
|
||||
DoubleEliminationAdvance.new(@wrestler, @last_match).bracket_advancement if @tournament.tournament_type.include? "Regular Double Elimination"
|
||||
end
|
||||
@wrestler.school.calculate_score
|
||||
end
|
||||
|
||||
def pool_to_bracket_advancement
|
||||
@@ -27,4 +29,4 @@ class AdvanceWrestler
|
||||
PoolAdvance.new(@wrestler).advanceWrestler
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,130 +3,203 @@ class DoubleEliminationGenerateLoserNames
|
||||
@tournament = tournament
|
||||
end
|
||||
|
||||
# Entry point: assign loser placeholders and advance any byes
|
||||
def assign_loser_names
|
||||
@tournament.weights.each do |weight|
|
||||
assign_loser_names_for_weight(weight)
|
||||
advance_bye_matches_championship(weight.matches.reload)
|
||||
advance_bye_matches_championship(weight)
|
||||
advance_bye_matches_consolation(weight)
|
||||
end
|
||||
end
|
||||
|
||||
def define_losername_championship_mappings(bracket_size)
|
||||
# Use hashes instead of arrays for mappings
|
||||
case bracket_size
|
||||
when 4
|
||||
[
|
||||
{ conso_bracket_position: "3/4", championship_bracket_position: "Semis", cross_bracket: false, both_wrestlers: true }
|
||||
]
|
||||
when 8
|
||||
[
|
||||
{ conso_bracket_position: "Conso Quarter", championship_bracket_position: "Quarter", cross_bracket: false, both_wrestlers: true },
|
||||
{ conso_bracket_position: "Conso Semis", championship_bracket_position: "Semis", cross_bracket: true, both_wrestlers: false }
|
||||
]
|
||||
when 16
|
||||
[
|
||||
{ conso_bracket_position: "Conso Round of 8.1", championship_bracket_position: "Bracket Round of 16", cross_bracket: false, both_wrestlers: true },
|
||||
{ conso_bracket_position: "Conso Round of 8.2", championship_bracket_position: "Quarter", cross_bracket: true, both_wrestlers: false },
|
||||
{ conso_bracket_position: "Conso Semis", championship_bracket_position: "Semis", cross_bracket: false, both_wrestlers: false }
|
||||
]
|
||||
when 32
|
||||
[
|
||||
{ conso_bracket_position: "Conso Round of 16.1", championship_bracket_position: "Bracket Round of 32", cross_bracket: false, both_wrestlers: true },
|
||||
{ conso_bracket_position: "Conso Round of 16.2", championship_bracket_position: "Bracket Round of 16", cross_bracket: true, both_wrestlers: false },
|
||||
{ conso_bracket_position: "Conso Round of 8.2", championship_bracket_position: "Quarter", cross_bracket: false, both_wrestlers: false },
|
||||
{ conso_bracket_position: "Conso Semis", championship_bracket_position: "Semis", cross_bracket: true, both_wrestlers: false },
|
||||
|
||||
]
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
private
|
||||
|
||||
# Assign loser names for a single weight bracket
|
||||
def assign_loser_names_for_weight(weight)
|
||||
number_of_placers = @tournament.number_of_placers
|
||||
bracket_size = weight.calculate_bracket_size
|
||||
matches_by_weight = weight.matches.reload
|
||||
matches = weight.matches.reload
|
||||
num_placers = @tournament.number_of_placers
|
||||
|
||||
loser_name_championship_mappings = define_losername_championship_mappings(bracket_size)
|
||||
# Build dynamic round definitions
|
||||
champ_rounds = dynamic_championship_rounds(bracket_size)
|
||||
conso_rounds = dynamic_consolation_rounds(bracket_size)
|
||||
first_round = { bracket_position: first_round_label(bracket_size) }
|
||||
champ_full = [first_round] + champ_rounds
|
||||
|
||||
loser_name_championship_mappings.each do |mapping|
|
||||
conso_bracket_position = mapping[:conso_bracket_position]
|
||||
championship_bracket_position = mapping[:championship_bracket_position]
|
||||
cross_bracket = mapping[:cross_bracket]
|
||||
both_wrestlers = mapping[:both_wrestlers]
|
||||
# Map championship losers into consolation slots
|
||||
mappings = []
|
||||
champ_full[0...-1].each_with_index do |champ_info, i|
|
||||
map_idx = i.zero? ? 0 : (2 * i - 1)
|
||||
next if map_idx < 0 || map_idx >= conso_rounds.size
|
||||
|
||||
conso_matches = matches_by_weight.select do |match|
|
||||
match.bracket_position == conso_bracket_position && match.bracket_position == conso_bracket_position
|
||||
end.sort_by(&:bracket_position_number)
|
||||
mappings << {
|
||||
championship_bracket_position: champ_info[:bracket_position],
|
||||
consolation_bracket_position: conso_rounds[map_idx][:bracket_position],
|
||||
both_wrestlers: i.zero?,
|
||||
champ_round_index: i
|
||||
}
|
||||
end
|
||||
|
||||
championship_matches = matches_by_weight.select do |match|
|
||||
match.bracket_position == championship_bracket_position && match.bracket_position == championship_bracket_position
|
||||
end.sort_by(&:bracket_position_number)
|
||||
# Apply loser-name mappings
|
||||
mappings.each do |map|
|
||||
champ = matches.select { |m| m.bracket_position == map[:championship_bracket_position] }
|
||||
.sort_by(&:bracket_position_number)
|
||||
conso = matches.select { |m| m.bracket_position == map[:consolation_bracket_position] }
|
||||
.sort_by(&:bracket_position_number)
|
||||
|
||||
current_champ_round_index = map[:champ_round_index]
|
||||
if current_champ_round_index.odd?
|
||||
conso.reverse!
|
||||
end
|
||||
|
||||
conso_matches.reverse! if cross_bracket
|
||||
idx = 0
|
||||
# Determine if this mapping is for losers from the first championship round
|
||||
is_first_champ_round_feed = map[:champ_round_index].zero?
|
||||
|
||||
championship_bracket_position_number = 1
|
||||
conso_matches.each do |match|
|
||||
bout_number1 = championship_matches.find do |bout_match|
|
||||
bout_match.bracket_position_number == championship_bracket_position_number
|
||||
end.bout_number
|
||||
|
||||
match.loser1_name = "Loser of #{bout_number1}"
|
||||
if both_wrestlers
|
||||
championship_bracket_position_number += 1
|
||||
bout_number2 = championship_matches.find do |bout_match|
|
||||
bout_match.bracket_position_number == championship_bracket_position_number
|
||||
end.bout_number
|
||||
match.loser2_name = "Loser of #{bout_number2}"
|
||||
conso.each do |cm|
|
||||
champ_match1 = champ[idx]
|
||||
if champ_match1
|
||||
if is_first_champ_round_feed && ((champ_match1.w1 && champ_match1.w2.nil?) || (champ_match1.w1.nil? && champ_match1.w2))
|
||||
cm.loser1_name = "BYE"
|
||||
else
|
||||
cm.loser1_name = "Loser of #{champ_match1.bout_number}"
|
||||
end
|
||||
else
|
||||
cm.loser1_name = nil # Should not happen if bracket generation is correct
|
||||
end
|
||||
championship_bracket_position_number += 1
|
||||
|
||||
if map[:both_wrestlers] # This is true only if is_first_champ_round_feed
|
||||
idx += 1 # Increment for the second championship match
|
||||
champ_match2 = champ[idx]
|
||||
if champ_match2
|
||||
# BYE check is only relevant for the first championship round feed
|
||||
if is_first_champ_round_feed && ((champ_match2.w1 && champ_match2.w2.nil?) || (champ_match2.w1.nil? && champ_match2.w2))
|
||||
cm.loser2_name = "BYE"
|
||||
else
|
||||
cm.loser2_name = "Loser of #{champ_match2.bout_number}"
|
||||
end
|
||||
else
|
||||
cm.loser2_name = nil # Should not happen
|
||||
end
|
||||
end
|
||||
idx += 1 # Increment for the next consolation match or next pair from championship
|
||||
end
|
||||
end
|
||||
|
||||
conso_semi_matches = matches_by_weight.select { |match| match.bracket_position == "Conso Semis" }
|
||||
conso_quarter_matches = matches_by_weight.select { |match| match.bracket_position == "Conso Quarter" }
|
||||
|
||||
if number_of_placers >= 6 && weight.wrestlers.size >= 5
|
||||
five_six_match = matches_by_weight.find { |match| match.bracket_position == "5/6" }
|
||||
bout_number1 = conso_semi_matches.find { |match| match.bracket_position_number == 1 }.bout_number
|
||||
bout_number2 = conso_semi_matches.find { |match| match.bracket_position_number == 2 }.bout_number
|
||||
five_six_match.loser1_name = "Loser of #{bout_number1}"
|
||||
five_six_match.loser2_name = "Loser of #{bout_number2}"
|
||||
# 5th/6th place
|
||||
if bracket_size >= 5 && num_placers >= 6
|
||||
conso_semis = matches.select { |m| m.bracket_position == "Conso Semis" }
|
||||
.sort_by(&:bracket_position_number)
|
||||
if conso_semis.size >= 2
|
||||
m56 = matches.find { |m| m.bracket_position == "5/6" }
|
||||
m56.loser1_name = "Loser of #{conso_semis[0].bout_number}"
|
||||
m56.loser2_name = "Loser of #{conso_semis[1].bout_number}" if m56
|
||||
end
|
||||
end
|
||||
|
||||
if number_of_placers >= 8 && weight.wrestlers.size >= 7
|
||||
seven_eight_match = matches_by_weight.find { |match| match.bracket_position == "7/8" }
|
||||
bout_number1 = conso_quarter_matches.find { |match| match.bracket_position_number == 1 }.bout_number
|
||||
bout_number2 = conso_quarter_matches.find { |match| match.bracket_position_number == 2 }.bout_number
|
||||
seven_eight_match.loser1_name = "Loser of #{bout_number1}"
|
||||
seven_eight_match.loser2_name = "Loser of #{bout_number2}"
|
||||
# 7th/8th place
|
||||
if bracket_size >= 7 && num_placers >= 8
|
||||
conso_quarters = matches.select { |m| m.bracket_position == "Conso Quarter" }
|
||||
.sort_by(&:bracket_position_number)
|
||||
if conso_quarters.size >= 2
|
||||
m78 = matches.find { |m| m.bracket_position == "7/8" }
|
||||
m78.loser1_name = "Loser of #{conso_quarters[0].bout_number}"
|
||||
m78.loser2_name = "Loser of #{conso_quarters[1].bout_number}" if m78
|
||||
end
|
||||
end
|
||||
|
||||
save_matches(matches_by_weight)
|
||||
end
|
||||
|
||||
def save_matches(matches)
|
||||
matches.each(&:save!)
|
||||
end
|
||||
|
||||
def advance_bye_matches_championship(matches)
|
||||
first_round = matches.sort_by{|m| m.round}.first.round
|
||||
matches.select do |m|
|
||||
m.round == first_round
|
||||
end.sort_by(&:bracket_position_number).each do |match|
|
||||
next unless match.w1.nil? || match.w2.nil?
|
||||
# Advance first-round byes in championship bracket
|
||||
def advance_bye_matches_championship(weight)
|
||||
matches = weight.matches.reload
|
||||
first_round = matches.map(&:round).min
|
||||
matches.select { |m| m.round == first_round }
|
||||
.sort_by(&:bracket_position_number)
|
||||
.each { |m| handle_bye(m) }
|
||||
end
|
||||
|
||||
# Advance first-round byes in consolation bracket
|
||||
def advance_bye_matches_consolation(weight)
|
||||
matches = weight.matches.reload
|
||||
bracket_size = weight.calculate_bracket_size
|
||||
first_conso = dynamic_consolation_rounds(bracket_size).first
|
||||
|
||||
matches.select { |m| m.round == first_conso[:round] && m.bracket_position == first_conso[:bracket_position] }
|
||||
.sort_by(&:bracket_position_number)
|
||||
.each { |m| handle_bye(m) }
|
||||
end
|
||||
|
||||
# Mark bye match, set finished, and advance
|
||||
def handle_bye(match)
|
||||
if [match.w1, match.w2].compact.size == 1
|
||||
match.finished = 1
|
||||
match.win_type = "BYE"
|
||||
match.win_type = 'BYE'
|
||||
if match.w1
|
||||
match.winner_id = match.w1
|
||||
match.loser2_name = "BYE"
|
||||
elsif match.w2
|
||||
match.winner_id = match.w2
|
||||
match.loser1_name = "BYE"
|
||||
match.winner_id = match.w1
|
||||
match.loser2_name = 'BYE'
|
||||
else
|
||||
match.winner_id = match.w2
|
||||
match.loser1_name = 'BYE'
|
||||
end
|
||||
match.score = ""
|
||||
match.save
|
||||
match.score = ''
|
||||
match.save!
|
||||
match.advance_wrestlers
|
||||
end
|
||||
end
|
||||
|
||||
# Helpers for dynamic bracket labels
|
||||
def first_round_label(size)
|
||||
case size
|
||||
when 2 then 'Final'
|
||||
when 4 then 'Semis'
|
||||
when 8 then 'Quarter'
|
||||
else "Bracket Round of #{size}"
|
||||
end
|
||||
end
|
||||
|
||||
def dynamic_championship_rounds(size)
|
||||
total = Math.log2(size).to_i
|
||||
(1...total).map do |i|
|
||||
participants = size / (2**i)
|
||||
{ bracket_position: bracket_label(participants), round: i + 1 }
|
||||
end
|
||||
end
|
||||
|
||||
def dynamic_consolation_rounds(size)
|
||||
total_log2 = Math.log2(size).to_i
|
||||
return [] if total_log2 <= 1
|
||||
|
||||
max_j_val = (2 * (total_log2 - 1) - 1)
|
||||
(1..max_j_val).map do |j|
|
||||
current_participants = size / (2**((j.to_f / 2).ceil))
|
||||
{
|
||||
bracket_position: consolation_label(current_participants, j, size),
|
||||
round: j
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def bracket_label(participants)
|
||||
case participants
|
||||
when 2 then '1/2'
|
||||
when 4 then 'Semis'
|
||||
when 8 then 'Quarter'
|
||||
else "Bracket Round of #{participants}"
|
||||
end
|
||||
end
|
||||
|
||||
def consolation_label(participants, j, bracket_size)
|
||||
max_j_for_bracket = (2 * (Math.log2(bracket_size).to_i - 1) - 1)
|
||||
|
||||
if participants == 2 && j == max_j_for_bracket
|
||||
return '3/4'
|
||||
elsif participants == 4
|
||||
return j.odd? ? 'Conso Quarter' : 'Conso Semis'
|
||||
else
|
||||
suffix = j.odd? ? ".1" : ".2"
|
||||
return "Conso Round of #{participants}#{suffix}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,10 +27,10 @@ class DoubleEliminationMatchGeneration
|
||||
|
||||
# 1) Round one matchups
|
||||
bracket_info[:round_one_matchups].each_with_index do |matchup, idx|
|
||||
seed1, seed2 = matchup[:seeds]
|
||||
bracket_position = matchup[:bracket_position]
|
||||
bracket_pos_number = idx + 1
|
||||
round_number = matchup[:round] # Use the round from our definition
|
||||
seed1, seed2 = matchup[:seeds]
|
||||
bracket_position = matchup[:bracket_position]
|
||||
bracket_pos_number = idx + 1
|
||||
round_number = matchup[:round]
|
||||
|
||||
create_matchup_from_seed(
|
||||
seed1,
|
||||
@@ -77,167 +77,112 @@ class DoubleEliminationMatchGeneration
|
||||
)
|
||||
end
|
||||
|
||||
#
|
||||
# 5/6, 7/8 placing logic
|
||||
#
|
||||
if weight.wrestlers.size >= 5
|
||||
if @tournament.number_of_placers >= 6 && matches_this_round == 1
|
||||
create_matchup(nil, nil, "5/6", 1, round_number, weight)
|
||||
end
|
||||
if weight.wrestlers.size >= 5 && @tournament.number_of_placers >= 6 && matches_this_round == 1
|
||||
create_matchup(nil, nil, "5/6", 1, round_number, weight)
|
||||
end
|
||||
if weight.wrestlers.size >= 7
|
||||
if @tournament.number_of_placers >= 8 && matches_this_round == 1
|
||||
create_matchup(nil, nil, "7/8", 1, round_number, weight)
|
||||
end
|
||||
if weight.wrestlers.size >= 7 && @tournament.number_of_placers >= 8 && matches_this_round == 1
|
||||
create_matchup(nil, nil, "7/8", 1, round_number, weight)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#
|
||||
# Single bracket definition that includes both bracket_position and round.
|
||||
# If you later decide to tweak round numbering, you do it in ONE place.
|
||||
#
|
||||
# Single bracket definition dynamically generated for any power-of-two bracket size.
|
||||
# Returns a hash with :round_one_matchups, :championship_rounds, and :consolation_rounds.
|
||||
def define_bracket_matches(bracket_size)
|
||||
case bracket_size
|
||||
when 4
|
||||
{
|
||||
round_one_matchups: [
|
||||
# First round is Semis => round=1
|
||||
{ seeds: [1, 4], bracket_position: "Semis", round: 1 },
|
||||
{ seeds: [2, 3], bracket_position: "Semis", round: 1 }
|
||||
],
|
||||
championship_rounds: [
|
||||
# Final => round=2
|
||||
{ bracket_position: "1/2", number_of_matches: 1, round: 2 }
|
||||
],
|
||||
consolation_rounds: [
|
||||
# 3rd place => round=2
|
||||
{ bracket_position: "3/4", number_of_matches: 1, round: 2 }
|
||||
]
|
||||
}
|
||||
# Only support brackets that are powers of two
|
||||
return nil unless (bracket_size & (bracket_size - 1)).zero?
|
||||
|
||||
when 8
|
||||
{
|
||||
round_one_matchups: [
|
||||
# Quarter => round=1
|
||||
{ seeds: [1, 8], bracket_position: "Quarter", round: 1 },
|
||||
{ seeds: [4, 5], bracket_position: "Quarter", round: 1 },
|
||||
{ seeds: [3, 6], bracket_position: "Quarter", round: 1 },
|
||||
{ seeds: [2, 7], bracket_position: "Quarter", round: 1 }
|
||||
],
|
||||
championship_rounds: [
|
||||
# Semis => round=2, Final => round=4
|
||||
{ bracket_position: "Semis", number_of_matches: 2, round: 2 },
|
||||
{ bracket_position: "1/2", number_of_matches: 1, round: 4 }
|
||||
],
|
||||
consolation_rounds: [
|
||||
# Conso Quarter => round=2, Conso Semis => round=3, 3/4 => round=4
|
||||
{ bracket_position: "Conso Quarter", number_of_matches: 2, round: 2 },
|
||||
{ bracket_position: "Conso Semis", number_of_matches: 2, round: 3 },
|
||||
{ bracket_position: "3/4", number_of_matches: 1, round: 4 }
|
||||
]
|
||||
}
|
||||
# 1) Generate the seed sequence (e.g., [1,8,5,4,...] for size=8)
|
||||
seeds = generate_seed_sequence(bracket_size)
|
||||
|
||||
when 16
|
||||
# 2) Pair seeds into first-round matchups, sorting so lower seed is w1
|
||||
round_one = seeds.each_slice(2).map.with_index do |(s1, s2), idx|
|
||||
a, b = [s1, s2].sort
|
||||
{
|
||||
round_one_matchups: [
|
||||
{ seeds: [1,16], bracket_position: "Bracket Round of 16", round: 1 },
|
||||
{ seeds: [8,9], bracket_position: "Bracket Round of 16", round: 1 },
|
||||
{ seeds: [5,12], bracket_position: "Bracket Round of 16", round: 1 },
|
||||
{ seeds: [4,13], bracket_position: "Bracket Round of 16", round: 1 },
|
||||
{ seeds: [3,14], bracket_position: "Bracket Round of 16", round: 1 },
|
||||
{ seeds: [6,11], bracket_position: "Bracket Round of 16", round: 1 },
|
||||
{ seeds: [7,10], bracket_position: "Bracket Round of 16", round: 1 },
|
||||
{ seeds: [2,15], bracket_position: "Bracket Round of 16", round: 1 }
|
||||
],
|
||||
championship_rounds: [
|
||||
# Quarter => round=2, Semis => round=4, Final => round=6
|
||||
{ bracket_position: "Quarter", number_of_matches: 4, round: 2 },
|
||||
{ bracket_position: "Semis", number_of_matches: 2, round: 4 },
|
||||
{ bracket_position: "1/2", number_of_matches: 1, round: 6 }
|
||||
],
|
||||
consolation_rounds: [
|
||||
# Just carry over your standard numbering
|
||||
{ bracket_position: "Conso Round of 8.1", number_of_matches: 4, round: 2 },
|
||||
{ bracket_position: "Conso Round of 8.2", number_of_matches: 4, round: 3 },
|
||||
{ bracket_position: "Conso Quarter", number_of_matches: 2, round: 4 },
|
||||
{ bracket_position: "Conso Semis", number_of_matches: 2, round: 5 },
|
||||
{ bracket_position: "3/4", number_of_matches: 1, round: 6 }
|
||||
]
|
||||
seeds: [a, b],
|
||||
bracket_position: first_round_label(bracket_size),
|
||||
round: 1
|
||||
}
|
||||
|
||||
when 32
|
||||
{
|
||||
round_one_matchups: [
|
||||
{ seeds: [1,32], bracket_position: "Bracket Round of 32", round: 1 },
|
||||
{ seeds: [16,17], bracket_position: "Bracket Round of 32", round: 1 },
|
||||
{ seeds: [9,24], bracket_position: "Bracket Round of 32", round: 1 },
|
||||
{ seeds: [8,25], bracket_position: "Bracket Round of 32", round: 1 },
|
||||
{ seeds: [5,28], bracket_position: "Bracket Round of 32", round: 1 },
|
||||
{ seeds: [12,21], bracket_position: "Bracket Round of 32", round: 1 },
|
||||
{ seeds: [13,20], bracket_position: "Bracket Round of 32", round: 1 },
|
||||
{ seeds: [4,29], bracket_position: "Bracket Round of 32", round: 1 },
|
||||
{ seeds: [3,30], bracket_position: "Bracket Round of 32", round: 1 },
|
||||
{ seeds: [14,19], bracket_position: "Bracket Round of 32", round: 1 },
|
||||
{ seeds: [11,22], bracket_position: "Bracket Round of 32", round: 1 },
|
||||
{ seeds: [6,27], bracket_position: "Bracket Round of 32", round: 1 },
|
||||
{ seeds: [7,26], bracket_position: "Bracket Round of 32", round: 1 },
|
||||
{ seeds: [10,23], bracket_position: "Bracket Round of 32", round: 1 },
|
||||
{ seeds: [15,18], bracket_position: "Bracket Round of 32", round: 1 },
|
||||
{ seeds: [2,31], bracket_position: "Bracket Round of 32", round: 1 }
|
||||
],
|
||||
championship_rounds: [
|
||||
{ bracket_position: "Bracket Round of 16", number_of_matches: 8, round: 2 },
|
||||
{ bracket_position: "Quarter", number_of_matches: 4, round: 4 },
|
||||
{ bracket_position: "Semis", number_of_matches: 2, round: 6 },
|
||||
{ bracket_position: "1/2", number_of_matches: 1, round: 8 }
|
||||
],
|
||||
consolation_rounds: [
|
||||
{ bracket_position: "Conso Round of 16.1", number_of_matches: 8, round: 2 },
|
||||
{ bracket_position: "Conso Round of 16.2", number_of_matches: 8, round: 3 },
|
||||
{ bracket_position: "Conso Round of 8.1", number_of_matches: 4, round: 4 },
|
||||
{ bracket_position: "Conso Round of 8.2", number_of_matches: 4, round: 5 },
|
||||
{ bracket_position: "Conso Quarter", number_of_matches: 2, round: 6 },
|
||||
{ bracket_position: "Conso Semis", number_of_matches: 2, round: 7 },
|
||||
{ bracket_position: "3/4", number_of_matches: 1, round: 8 }
|
||||
]
|
||||
}
|
||||
else
|
||||
nil
|
||||
end
|
||||
|
||||
# 3) Build full structure, including dynamic championship & consolation rounds
|
||||
{
|
||||
round_one_matchups: round_one,
|
||||
championship_rounds: dynamic_championship_rounds(bracket_size),
|
||||
consolation_rounds: dynamic_consolation_rounds(bracket_size)
|
||||
}
|
||||
end
|
||||
|
||||
# Returns a human-readable label for the first round based on bracket size.
|
||||
def first_round_label(bracket_size)
|
||||
case bracket_size
|
||||
when 2 then "1/2"
|
||||
when 4 then "Semis"
|
||||
when 8 then "Quarter"
|
||||
else "Bracket Round of #{bracket_size}"
|
||||
end
|
||||
end
|
||||
|
||||
# Dynamically generate championship rounds for any power-of-two bracket size.
|
||||
def dynamic_championship_rounds(bracket_size)
|
||||
rounds = []
|
||||
num_rounds = Math.log2(bracket_size).to_i
|
||||
# i: 1 -> first post-initial round, up to num_rounds-1 (final)
|
||||
(1...num_rounds).each do |i|
|
||||
participants = bracket_size / (2**i)
|
||||
number_of_matches = participants / 2
|
||||
bracket_position = case participants
|
||||
when 2 then "1/2"
|
||||
when 4 then "Semis"
|
||||
when 8 then "Quarter"
|
||||
else "Bracket Round of #{participants}"
|
||||
end
|
||||
round_number = i * 2
|
||||
rounds << { bracket_position: bracket_position,
|
||||
number_of_matches: number_of_matches,
|
||||
round: round_number }
|
||||
end
|
||||
rounds
|
||||
end
|
||||
|
||||
# Dynamically generate consolation rounds for any power-of-two bracket size.
|
||||
def dynamic_consolation_rounds(bracket_size)
|
||||
rounds = []
|
||||
num_rounds = Math.log2(bracket_size).to_i
|
||||
total_conso = 2 * (num_rounds - 1) - 1
|
||||
(1..total_conso).each do |j|
|
||||
participants = bracket_size / (2**((j.to_f / 2).ceil))
|
||||
number_of_matches = participants / 2
|
||||
bracket_position = case participants
|
||||
when 2 then "3/4"
|
||||
when 4
|
||||
j.odd? ? "Conso Quarter" : "Conso Semis"
|
||||
else
|
||||
suffix = j.odd? ? ".1" : ".2"
|
||||
"Conso Round of #{participants}#{suffix}"
|
||||
end
|
||||
round_number = j + 1
|
||||
rounds << { bracket_position: bracket_position,
|
||||
number_of_matches: number_of_matches,
|
||||
round: round_number }
|
||||
end
|
||||
rounds
|
||||
end
|
||||
|
||||
###########################################################################
|
||||
# PHASE 2: Overwrite rounds in all smaller brackets to match the largest one.
|
||||
###########################################################################
|
||||
def align_all_rounds_to_largest_bracket
|
||||
#
|
||||
# 1) Find the bracket size that is largest
|
||||
#
|
||||
largest_weight = @tournament.weights.max_by { |w| w.calculate_bracket_size }
|
||||
return unless largest_weight
|
||||
|
||||
#
|
||||
# 2) Gather all matches for that bracket. Build a map from bracket_position => round
|
||||
#
|
||||
# We assume "largest bracket" is the single weight with the largest bracket_size.
|
||||
#
|
||||
largest_bracket_size = largest_weight.calculate_bracket_size
|
||||
largest_matches = largest_weight.tournament.matches.where(weight_id: largest_weight.id)
|
||||
|
||||
position_to_round = {}
|
||||
largest_matches.each do |m|
|
||||
# In case multiple matches have the same bracket_position but different rounds
|
||||
# (like "3/4" might appear more than once), you can pick the first or max.
|
||||
position_to_round[m.bracket_position] ||= m.round
|
||||
largest_weight.tournament.matches.where(weight_id: largest_weight.id).each do |m|
|
||||
position_to_round[m.bracket_position] ||= m.round
|
||||
end
|
||||
|
||||
#
|
||||
# 3) For every other match in the entire tournament (including possibly the largest bracket, if you want),
|
||||
# overwrite the round to match this map.
|
||||
#
|
||||
@tournament.matches.find_each do |match|
|
||||
# If there's a known round for this bracket_position, use it
|
||||
if position_to_round.key?(match.bracket_position)
|
||||
match.update(round: position_to_round[match.bracket_position])
|
||||
end
|
||||
@@ -272,4 +217,23 @@ class DoubleEliminationMatchGeneration
|
||||
bracket_position_number: bracket_position_number
|
||||
)
|
||||
end
|
||||
|
||||
# Calculates the sequence of seeds for the first round of a power-of-two bracket.
|
||||
def generate_seed_sequence(n)
|
||||
raise ArgumentError, "Bracket size must be a power of two" unless (n & (n - 1)).zero?
|
||||
return [1, 2] if n == 2
|
||||
|
||||
half = n / 2
|
||||
prev = generate_seed_sequence(half)
|
||||
comp = prev.map { |s| n + 1 - s }
|
||||
|
||||
result = []
|
||||
(0...prev.size).step(2) do |k|
|
||||
result << prev[k]
|
||||
result << comp[k]
|
||||
result << comp[k + 1]
|
||||
result << prev[k + 1]
|
||||
end
|
||||
result
|
||||
end
|
||||
end
|
||||
|
||||
@@ -41,7 +41,11 @@ class TournamentBackupService
|
||||
mat_assignment_rules: @tournament.mat_assignment_rules.map do |rule|
|
||||
rule.attributes.merge(
|
||||
mat: Mat.find_by(id: rule.mat_id)&.attributes.slice("name"),
|
||||
weight_classes: rule.weight_classes.map do |weight_id|
|
||||
# Emit the human-readable max values under a distinct key to avoid
|
||||
# colliding with the raw DB-backed "weight_classes" attribute (which
|
||||
# is stored as a comma-separated string). Using a different key
|
||||
# prevents duplicate JSON keys when symbols and strings are both present.
|
||||
"weight_class_maxes" => rule.weight_classes.map do |weight_id|
|
||||
Weight.find_by(id: weight_id)&.max
|
||||
end
|
||||
)
|
||||
|
||||
@@ -19,14 +19,19 @@ class TournamentSeeding
|
||||
half_of_bracket = bracket_size / 2
|
||||
available_bracket_lines = (1..bracket_size).to_a
|
||||
first_half_available_bracket_lines = (1..half_of_bracket).to_a
|
||||
first_line_of_second_half_of_bracket = half_of_bracket + 1
|
||||
second_half_available_bracket_lines = (first_line_of_second_half_of_bracket..bracket_size).to_a
|
||||
|
||||
# remove bracket lines that are taken from available_bracket_lines
|
||||
wrestlers_with_bracket_lines = wrestlers.select{|w| w.bracket_line != nil }
|
||||
wrestlers_with_bracket_lines.each do |wrestler|
|
||||
available_bracket_lines.delete(wrestler.bracket_line)
|
||||
first_half_available_bracket_lines.delete(wrestler.bracket_line)
|
||||
second_half_available_bracket_lines.delete(wrestler.bracket_line)
|
||||
end
|
||||
|
||||
available_bracket_lines_to_use = set_random_seeding_bracket_line_order(first_half_available_bracket_lines, second_half_available_bracket_lines)
|
||||
|
||||
wrestlers_without_bracket_lines = wrestlers.select{|w| w.bracket_line == nil }
|
||||
if @tournament.tournament_type == "Pool to bracket"
|
||||
wrestlers_without_bracket_lines.shuffle.each do |wrestler|
|
||||
@@ -38,15 +43,10 @@ class TournamentSeeding
|
||||
else
|
||||
# Iterrate over the list randomly
|
||||
wrestlers_without_bracket_lines.shuffle.each do |wrestler|
|
||||
if first_half_available_bracket_lines.size > 0
|
||||
random_available_bracket_line = first_half_available_bracket_lines.sample
|
||||
wrestler.bracket_line = random_available_bracket_line
|
||||
available_bracket_lines.delete(random_available_bracket_line)
|
||||
first_half_available_bracket_lines.delete(random_available_bracket_line)
|
||||
else
|
||||
random_available_bracket_line = available_bracket_lines.sample
|
||||
wrestler.bracket_line = random_available_bracket_line
|
||||
available_bracket_lines.delete(random_available_bracket_line)
|
||||
if available_bracket_lines_to_use.size > 0
|
||||
bracket_line_to_use = available_bracket_lines_to_use.first
|
||||
wrestler.bracket_line = bracket_line_to_use
|
||||
available_bracket_lines_to_use.delete(bracket_line_to_use)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -81,4 +81,35 @@ class TournamentSeeding
|
||||
end
|
||||
return wrestlers
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_random_seeding_bracket_line_order(first_half_lines, second_half_lines)
|
||||
# This method prevents double BYEs in round 1
|
||||
# It also evenly distributes matches from the top half of the bracket to the bottom half
|
||||
# It does both of these while keeping the randomness of the line assignment
|
||||
odd_or_even = [0, 1]
|
||||
odd_or_even_sample = odd_or_even.sample
|
||||
|
||||
# sort by odd or even based on the sample above
|
||||
if odd_or_even_sample == 1
|
||||
# odd numbers first
|
||||
sorted_first_half_lines = first_half_lines.sort_by { |n| n.even? ? 1 : 0 }
|
||||
sorted_second_half_lines = second_half_lines.sort_by { |n| n.even? ? 1 : 0 }
|
||||
else
|
||||
# even numbers first
|
||||
sorted_first_half_lines = first_half_lines.sort_by { |n| n.odd? ? 1 : 0 }
|
||||
sorted_second_half_lines = second_half_lines.sort_by { |n| n.odd? ? 1 : 0 }
|
||||
end
|
||||
|
||||
# zip requires either even arrays or the receiver to be the bigger list
|
||||
if first_half_lines.size >= second_half_lines.size
|
||||
result = sorted_first_half_lines.zip(sorted_second_half_lines).flatten
|
||||
else
|
||||
result = sorted_second_half_lines.zip(sorted_first_half_lines).flatten
|
||||
end
|
||||
result.compact
|
||||
result.delete(nil)
|
||||
result
|
||||
end
|
||||
end
|
||||
@@ -41,7 +41,6 @@ class WrestlingdevImporter
|
||||
@tournament.matches.destroy_all
|
||||
@tournament.mat_assignment_rules.destroy_all # Explicitly destroy rules (might be redundant if Mat cascades)
|
||||
@tournament.delegates.destroy_all
|
||||
@tournament.tournament_backups.destroy_all
|
||||
@tournament.tournament_job_statuses.destroy_all
|
||||
# Note: Teampointadjusts are deleted via School/Wrestler cascade
|
||||
end
|
||||
@@ -86,17 +85,30 @@ class WrestlingdevImporter
|
||||
mat_assignment_rules.each do |rule_attributes|
|
||||
mat_name = rule_attributes.dig("mat", "name")
|
||||
mat = Mat.find_by(name: mat_name, tournament_id: @tournament.id)
|
||||
|
||||
# Map max values of weight_classes to their new IDs
|
||||
new_weight_classes = rule_attributes["weight_classes"].map do |max_value|
|
||||
Weight.find_by(max: max_value, tournament_id: @tournament.id)&.id
|
||||
end.compact
|
||||
|
||||
# Extract bracket_positions and rounds
|
||||
|
||||
# Prefer the new "weight_class_maxes" key emitted by backups (human-readable
|
||||
# max values). If not present, fall back to the legacy "weight_classes"
|
||||
# value which may be a comma-separated string or an array of IDs.
|
||||
if rule_attributes.key?("weight_class_maxes") && rule_attributes["weight_class_maxes"].respond_to?(:map)
|
||||
new_weight_classes = rule_attributes["weight_class_maxes"].map do |max_value|
|
||||
Weight.find_by(max: max_value, tournament_id: @tournament.id)&.id
|
||||
end.compact
|
||||
elsif rule_attributes["weight_classes"].is_a?(Array)
|
||||
# Already an array of IDs
|
||||
new_weight_classes = rule_attributes["weight_classes"].map(&:to_i)
|
||||
elsif rule_attributes["weight_classes"].is_a?(String)
|
||||
# Comma-separated IDs stored in the DB column; split into integers.
|
||||
new_weight_classes = rule_attributes["weight_classes"].to_s.split(",").map(&:strip).reject(&:empty?).map(&:to_i)
|
||||
else
|
||||
new_weight_classes = []
|
||||
end
|
||||
|
||||
# Extract bracket_positions and rounds (leave as-is; model will coerce if needed)
|
||||
bracket_positions = rule_attributes["bracket_positions"]
|
||||
rounds = rule_attributes["rounds"]
|
||||
|
||||
rule_attributes.except!("id", "mat", "tournament_id", "weight_classes")
|
||||
|
||||
# Remove any keys we don't want to mass-assign (including both old/new weight keys)
|
||||
rule_attributes.except!("id", "mat", "tournament_id", "weight_classes", "weight_class_maxes")
|
||||
|
||||
MatAssignmentRule.create(
|
||||
rule_attributes.merge(
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#"><%= current_user.email %>
|
||||
<span class="caret"></span></a>
|
||||
<ul class="dropdown-menu">
|
||||
<li><%= link_to "Log out", logout_path, method: :delete %></li>
|
||||
<li><%= button_to "Log out", logout_path, method: :delete, class: 'btn btn-link', form: { class: 'navbar-logout-form' } %></li>
|
||||
<li><%= link_to "Edit profile", edit_user_path(current_user) %></li>
|
||||
<li><%= link_to "My tournaments and schools", "/static_pages/my_tournaments" %></li>
|
||||
<li><%= link_to "My tournaments and schools", "/static_pages/my_tournaments" %></li>
|
||||
</ul>
|
||||
</li>
|
||||
<% else %>
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
<li><%= link_to "Deduct Team Points" , "/tournaments/#{@tournament.id}/teampointadjust" %></li>
|
||||
<li><%= link_to "View All Mat Assignment Rules", tournament_mat_assignment_rules_path(@tournament) %></li>
|
||||
<li><%= link_to 'Manage Backups', tournament_tournament_backups_path(@tournament) %></li>
|
||||
<li><%= link_to "Reset Bout Board", reset_bout_board_tournament_path(@tournament), method: :post, data: { confirm: "Are you sure you want to reset the bout board?" } %></li>
|
||||
<li><%= link_to "Reset Bout Board", reset_bout_board_tournament_path(@tournament), data: { turbo_method: :post, turbo_confirm: "Are you sure you want to reset the bout board?" } %></li>
|
||||
<% if can? :destroy, @tournament %>
|
||||
<li><%= link_to "Tournament Delegation" , "/tournaments/#{@tournament.id}/delegate" %></li>
|
||||
<% end %>
|
||||
@@ -55,13 +55,13 @@
|
||||
<% end %>
|
||||
<% end %>
|
||||
<li><strong>Time Savers</strong></li>
|
||||
<li><%= link_to "Create Boys High School Weights (106-285)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=#{Weight::HS_WEIGHT_CLASSES}",data: { confirm: 'Are you sure? This will delete all current weights.' } %></li>
|
||||
<li><%= link_to "Create Girls High School Weights (100-235)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=#{Weight::HS_GIRLS_WEIGHT_CLASSES}",data: { confirm: 'Are you sure? This will delete all current weights.' } %></li>
|
||||
<li><%= link_to "Create Boys Middle School Weights (80-245)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=#{Weight::MS_WEIGHT_CLASSES}",data: { confirm: 'Are you sure? This will delete all current weights.' } %></li>
|
||||
<li><%= link_to "Create Girls Middle School Weights (72-235)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=#{Weight::MS_GIRLS_WEIGHT_CLASSES}",data: { confirm: 'Are you sure? This will delete all current weights.' } %></li>
|
||||
<li><%= link_to "Create Boys High School Weights (106-285)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=#{Weight::HS_WEIGHT_CLASSES}",data: { turbo_method: :get, turbo_confirm: 'Are you sure? This will delete all current weights.' } %></li>
|
||||
<li><%= link_to "Create Girls High School Weights (100-235)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=#{Weight::HS_GIRLS_WEIGHT_CLASSES}",data: { turbo_method: :get, turbo_confirm: 'Are you sure? This will delete all current weights.' } %></li>
|
||||
<li><%= link_to "Create Boys Middle School Weights (80-245)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=#{Weight::MS_WEIGHT_CLASSES}",data: { turbo_method: :get, turbo_confirm: 'Are you sure? This will delete all current weights.' } %></li>
|
||||
<li><%= link_to "Create Girls Middle School Weights (72-235)" , "/tournaments/#{@tournament.id}/create_custom_weights?customValue=#{Weight::MS_GIRLS_WEIGHT_CLASSES}",data: { turbo_method: :get, turbo_confirm: 'Are you sure? This will delete all current weights.' } %></li>
|
||||
<li><strong>Tournament Actions</strong></li>
|
||||
<li><%= link_to "Calculate Team Scores" , "/tournaments/#{@tournament.id}/calculate_team_scores", :method => :put %></li>
|
||||
<li><%= link_to "Generate Brackets" , "/tournaments/#{@tournament.id}/generate_matches", data: { confirm: 'Are you sure? This will delete all current matches.' } %></li>
|
||||
<li><%= link_to "Calculate Team Scores" , "/tournaments/#{@tournament.id}/calculate_team_scores", data: { turbo_method: :put } %></li>
|
||||
<li><%= link_to "Generate Brackets" , "/tournaments/#{@tournament.id}/generate_matches", data: { turbo_method: :get, turbo_confirm: 'Are you sure? This will delete all current matches.' } %></li>
|
||||
<li><%= link_to "Export Data" , "/tournaments/#{@tournament.id}/export?print=true", target: :_blank %></li>
|
||||
</ul>
|
||||
<% end %>
|
||||
@@ -69,4 +69,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
<td><%= Array(rule.rounds).join(", ") %></td>
|
||||
<td>
|
||||
<%= link_to '', edit_tournament_mat_assignment_rule_path(@tournament, rule), class: "fas fa-edit" %>
|
||||
<%= link_to '', tournament_mat_assignment_rule_path(@tournament, rule), method: :delete, data: { confirm: "Are you sure?" }, class: "fas fa-trash-alt" %>
|
||||
<%= link_to '', tournament_mat_assignment_rule_path(@tournament, rule), data: { turbo_method: :delete, turbo_confirm: "Are you sure?" }, class: "fas fa-trash-alt" %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
||||
37
app/views/mats/_current_match.html.erb
Normal file
37
app/views/mats/_current_match.html.erb
Normal file
@@ -0,0 +1,37 @@
|
||||
<% @mat = mat %>
|
||||
<% @match = local_assigns[:match] || mat.unfinished_matches.first %>
|
||||
<% @next_match = local_assigns[:next_match] || mat.unfinished_matches.second %>
|
||||
<% @show_next_bout_button = local_assigns.key?(:show_next_bout_button) ? local_assigns[:show_next_bout_button] : true %>
|
||||
|
||||
<% @wrestlers = [] %>
|
||||
<% if @match %>
|
||||
<% if @match.w1 %>
|
||||
<% @wrestler1_name = @match.wrestler1.name %>
|
||||
<% @wrestler1_school_name = @match.wrestler1.school.name %>
|
||||
<% @wrestler1_last_match = @match.wrestler1.last_match %>
|
||||
<% @wrestlers.push(@match.wrestler1) %>
|
||||
<% else %>
|
||||
<% @wrestler1_name = "Not assigned" %>
|
||||
<% @wrestler1_school_name = "N/A" %>
|
||||
<% @wrestler1_last_match = nil %>
|
||||
<% end %>
|
||||
|
||||
<% if @match.w2 %>
|
||||
<% @wrestler2_name = @match.wrestler2.name %>
|
||||
<% @wrestler2_school_name = @match.wrestler2.school.name %>
|
||||
<% @wrestler2_last_match = @match.wrestler2.last_match %>
|
||||
<% @wrestlers.push(@match.wrestler2) %>
|
||||
<% else %>
|
||||
<% @wrestler2_name = "Not assigned" %>
|
||||
<% @wrestler2_school_name = "N/A" %>
|
||||
<% @wrestler2_last_match = nil %>
|
||||
<% end %>
|
||||
|
||||
<% @tournament = @match.tournament %>
|
||||
<% end %>
|
||||
|
||||
<% if @match %>
|
||||
<%= render "matches/matchstats" %>
|
||||
<% else %>
|
||||
<p>No matches assigned to this mat.</p>
|
||||
<% end %>
|
||||
@@ -1,9 +1,12 @@
|
||||
<h3>Mat <%= @mat.name %></h3>
|
||||
<h3>Tournament: <%= @mat.tournament.name %></h3>
|
||||
|
||||
<% if @match %>
|
||||
<%= render 'matches/matchstats' %>
|
||||
<% else %>
|
||||
<p>No matches assigned to this mat.</p>
|
||||
<% end %>
|
||||
<%= turbo_stream_from @mat %>
|
||||
|
||||
<%= turbo_frame_tag dom_id(@mat, :current_match) do %>
|
||||
<%= render "mats/current_match",
|
||||
mat: @mat,
|
||||
match: @match,
|
||||
next_match: @next_match,
|
||||
show_next_bout_button: @show_next_bout_button %>
|
||||
<% end %>
|
||||
|
||||
@@ -76,8 +76,12 @@
|
||||
<% delete_wrestler_path_with_key = wrestler_path(wrestler) %>
|
||||
<% delete_wrestler_path_with_key += "?school_permission_key=#{params[:school_permission_key]}" if params[:school_permission_key].present? %>
|
||||
|
||||
<%= link_to '', edit_wrestler_path_with_key, class: "fas fa-edit" %>
|
||||
<%= link_to '', delete_wrestler_path_with_key, method: :delete, data: { confirm: "Are you sure you want to delete #{wrestler.name}? This will delete all of his matches." }, class: "fas fa-trash-alt" %>
|
||||
<%= link_to edit_wrestler_path_with_key, class: "text-decoration-none" do %>
|
||||
<span class="fas fa-edit" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
<%= link_to delete_wrestler_path_with_key, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{wrestler.name}? This will delete all of his matches." }, class: "text-decoration-none" do %>
|
||||
<span class="fas fa-trash-alt" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
@@ -101,8 +105,12 @@
|
||||
<% delete_wrestler_path_with_key = wrestler_path(wrestler) %>
|
||||
<% delete_wrestler_path_with_key += "?school_permission_key=#{params[:school_permission_key]}" if params[:school_permission_key].present? %>
|
||||
|
||||
<%= link_to '', edit_wrestler_path_with_key, class: "fas fa-edit" %>
|
||||
<%= link_to '', delete_wrestler_path_with_key, method: :delete, data: { confirm: "Are you sure you want to delete #{wrestler.name}? This will delete all of his matches." }, class: "fas fa-trash-alt" %>
|
||||
<%= link_to edit_wrestler_path_with_key, class: "text-decoration-none" do %>
|
||||
<span class="fas fa-edit" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
<%= link_to delete_wrestler_path_with_key, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{wrestler.name}? This will delete all of his matches." }, class: "text-decoration-none" do %>
|
||||
<span class="fas fa-trash-alt" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
@@ -111,6 +119,6 @@
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<% if can? :manage, @school %>
|
||||
<%= render 'baums_roster_import' %>
|
||||
<% end %>
|
||||
<%# if can? :manage, @school %>
|
||||
<%#= render 'baums_roster_import' %>
|
||||
<%# end %>
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<td>
|
||||
<%= link_to '', edit_tournament_path(tournament), :class=>"fas fa-edit" %>
|
||||
<% if can? :destroy, tournament %>
|
||||
<%= link_to '', tournament, method: :delete, data: { confirm: "Are you sure you want to delete #{tournament.name}?" }, :class=>"fas fa-trash-alt" %>
|
||||
<%= link_to '', tournament, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{tournament.name}?" }, :class=>"fas fa-trash-alt" %>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
@@ -55,4 +55,4 @@
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -8,7 +8,7 @@ and will also delete all of your current data. It's best to use the create backu
|
||||
<tr>
|
||||
<th>Backup Created At</th>
|
||||
<th>Backup Reason</th>
|
||||
<th><%= link_to ' Create New Backup', tournament_tournament_backups_path(@tournament), method: :post, class: 'fas fa-plus'%></th>
|
||||
<th><%= link_to ' Create New Backup', tournament_tournament_backups_path(@tournament), data: { turbo_method: :post }, class: 'fas fa-plus'%></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -19,20 +19,11 @@ and will also delete all of your current data. It's best to use the create backu
|
||||
</td>
|
||||
<td><%= backup.backup_reason.presence || 'No reason provided' %></td>
|
||||
<td>
|
||||
<%= link_to '', restore_tournament_tournament_backup_path(@tournament, backup), method: :post, data: { confirm: "This will restore the backup from #{backup.created_at.strftime('%Y-%m-%d %H:%M:%S')}. It will delete all current data from the tournament in order to restore the backup." }, class: 'fas fa-undo-alt text-warning', title: 'Restore Backup' %>
|
||||
<%= link_to '', tournament_tournament_backup_path(@tournament, backup), method: :delete, data: { confirm: 'Are you sure you want to delete this backup?' }, class: 'fas fa-trash-alt', title: 'Delete Backup' %>
|
||||
<%= link_to '', restore_tournament_tournament_backup_path(@tournament, backup), data: { turbo_method: :post, turbo_confirm: "This will restore the backup from #{backup.created_at.strftime('%Y-%m-%d %H:%M:%S')}. It will delete all current data from the tournament in order to restore the backup." }, class: 'fas fa-undo-alt text-warning', title: 'Restore Backup' %>
|
||||
<%= link_to '', tournament_tournament_backup_path(@tournament, backup), data: { turbo_method: :delete, turbo_confirm: 'Are you sure you want to delete this backup?' }, class: 'fas fa-trash-alt', title: 'Delete Backup' %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<br><br>
|
||||
<h3>Import Manual Backup</h3>
|
||||
<p>Paste the backup text here. Note, if this is formatted wrong, you'll need to restore a backup from above to fix it and you'll see an error in your background jobs.</p>
|
||||
<%= form_for(:tournament, url: import_manual_tournament_tournament_backups_path(@tournament)) do |f| %>
|
||||
<div class="field">
|
||||
<%= f.label 'Import text' %><br>
|
||||
<%= f.text_area :import_text, cols: "30", rows: "20" %>
|
||||
</div>
|
||||
<%= submit_tag "Import", class: "btn btn-success", data: { confirm: 'Are you sure? This will delete everything for the current tournament and restore it with the backup text pasted below.' } %>
|
||||
<% end %>
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
<div class="round">
|
||||
<div class="game">
|
||||
<div class="game-top "><%= match.w1_bracket_name.html_safe %> <span></span></div>
|
||||
<div class="bout-number"><p><%= link_to match.bout_number, spectate_match_path(match) %> <%= match.bracket_score_string %></p><p><%= @winner_place %> Place Winner</p></div>
|
||||
<% if params[:print] %>
|
||||
<div class="bout-number"><p><%= match.bout_number %> <%= match.bracket_score_string %></p><p><%= @winner_place %> Place Winner</p></div>
|
||||
<% else %>
|
||||
<div class="bout-number"><p><%= link_to match.bout_number, spectate_match_path(match) %> <%= match.bracket_score_string %></p><p><%= @winner_place %> Place Winner</p></div>
|
||||
<% end %>
|
||||
<div class="game-bottom "><%= match.w2_bracket_name.html_safe %><span></span></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -11,7 +11,7 @@ table.smallText tr td { font-size: 10px; }
|
||||
min-width: 150px;
|
||||
min-height: 50px;
|
||||
/*background-color: #ddd;*/
|
||||
border: 1px solid #ddd;
|
||||
border: 1px solid #000; /* Dark border so boxes stay visible when printed */
|
||||
margin: 5px;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ table.smallText tr td { font-size: 10px; }
|
||||
}
|
||||
|
||||
.game-top {
|
||||
border-bottom:1px solid #ddd;
|
||||
border-bottom:1px solid #000;
|
||||
padding: 2px;
|
||||
min-height: 12px;
|
||||
}
|
||||
@@ -77,13 +77,13 @@ table.smallText tr td { font-size: 10px; }
|
||||
}
|
||||
|
||||
.bracket-winner {
|
||||
border-bottom:1px solid #ddd;
|
||||
border-bottom:1px solid #000;
|
||||
padding: 2px;
|
||||
min-height: 12px;
|
||||
}
|
||||
|
||||
.game-bottom {
|
||||
border-top:1px solid #ddd;
|
||||
border-top:1px solid #000;
|
||||
padding: 2px;
|
||||
min-height: 12px;
|
||||
}
|
||||
@@ -131,4 +131,4 @@ table.smallText tr td { font-size: 10px; }
|
||||
<% elsif @tournament.tournament_type.include? "Regular Double Elimination" %>
|
||||
<%= render 'double_elimination_bracket' %>
|
||||
<% end %>
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,11 @@
|
||||
<% @round_matches.sort_by{|m| m.bracket_position_number}.each do |match| %>
|
||||
<div class="game">
|
||||
<div class="game-top "><%= match.w1_bracket_name.html_safe %> <span></span></div>
|
||||
<div class="bout-number"><%= link_to match.bout_number, spectate_match_path(match) %> <%= match.bracket_score_string %> </div>
|
||||
<% if params[:print] %>
|
||||
<div class="bout-number"><%= match.bout_number %> <%= match.bracket_score_string %> </div>
|
||||
<% else %>
|
||||
<div class="bout-number"><%= link_to match.bout_number, spectate_match_path(match) %> <%= match.bracket_score_string %> </div>
|
||||
<% end %>
|
||||
<div class="game-bottom "><%= match.w2_bracket_name.html_safe %><span></span></div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -42,10 +42,10 @@
|
||||
<% @users_delegates.each do |delegate| %>
|
||||
<tr>
|
||||
<td><%= delegate.user.email %></td>
|
||||
<td><%= link_to 'Remove permissions', "/tournaments/#{@tournament.id}/#{delegate.id}/remove_delegate", method: :delete, confirm: 'Are you sure?', :class=>"btn btn-danger btn-sm" %></td>
|
||||
<td><%= link_to 'Remove permissions', "/tournaments/#{@tournament.id}/#{delegate.id}/remove_delegate", data: { turbo_method: :delete, turbo_confirm: 'Are you sure?' }, :class=>"btn btn-danger btn-sm" %></td>
|
||||
</tr>
|
||||
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -1,42 +1,85 @@
|
||||
<h1>Upcoming Tournaments</h1> <%= form_tag(tournaments_path, :method => "get", id: "search-form") do %>
|
||||
<%= text_field_tag :search, params[:search], placeholder: "Search Tournaments" %>
|
||||
<%= submit_tag "Search" %>
|
||||
<% end %>
|
||||
<p>Search by name or date YYYY-MM-DD</p>
|
||||
<script>
|
||||
// $(document).ready(function() {
|
||||
// $('#tournamentList').dataTable();
|
||||
// pagingType: "bootstrap";
|
||||
// } );
|
||||
</script>
|
||||
<h1>Upcoming Tournaments</h1>
|
||||
<%= form_tag(tournaments_path, :method => "get", id: "search-form") do %>
|
||||
<%= text_field_tag :search, params[:search], placeholder: "Search Tournaments" %>
|
||||
<%= submit_tag "Search" %>
|
||||
<% end %>
|
||||
<p>Search by name or date YYYY-MM-DD</p>
|
||||
|
||||
<br>
|
||||
|
||||
<table class="table table-hover table-condensed" id="tournamentList">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Date</th>
|
||||
<th><% if user_signed_in? %><%= link_to ' New Tournament', new_tournament_path, :class=>"fas fa-plus" %></th><% end %>
|
||||
<th>
|
||||
<% if user_signed_in? %>
|
||||
<%= link_to ' New Tournament', new_tournament_path, :class=>"fas fa-plus" %>
|
||||
<% end %>
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
<% @tournaments.each do |tournament| %>
|
||||
<tr>
|
||||
<td><%= link_to "#{tournament.name}", tournament %></td>
|
||||
<td><%= link_to tournament.name, tournament %></td>
|
||||
<td><%= tournament.date %></td>
|
||||
<td>
|
||||
<% if can? :manage, tournament %>
|
||||
<%= link_to '', edit_tournament_path(tournament), :class=>"fas fa-edit" %>
|
||||
<% if can? :destroy, tournament %>
|
||||
<%= link_to '', tournament, method: :delete, data: { confirm: "Are you sure you want to delete #{tournament.name}?" }, :class=>"fas fa-trash-alt" %>
|
||||
<%= link_to '', tournament, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{tournament.name}?" }, :class=>"fas fa-trash-alt" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<br>
|
||||
<%# Pagination controls %>
|
||||
<% if @total_pages.present? && @total_pages > 1 %>
|
||||
<nav aria-label="Tournaments pagination">
|
||||
<ul class="pagination">
|
||||
<%# Previous link %>
|
||||
<% if @page > 1 %>
|
||||
<li class="page-item">
|
||||
<%= link_to 'Previous', tournaments_path(page: @page - 1, search: params[:search]), class: "page-link" %>
|
||||
</li>
|
||||
<% else %>
|
||||
<li class="page-item disabled"><span class="page-link">Previous</span></li>
|
||||
<% end %>
|
||||
|
||||
<%# Page number links (limit displayed pages for large counts) %>
|
||||
<% window = 5
|
||||
left = [1, @page - window/2].max
|
||||
right = [@total_pages, left + window - 1].min
|
||||
left = [1, right - window + 1].max
|
||||
%>
|
||||
<% (left..right).each do |p| %>
|
||||
<% if p == @page %>
|
||||
<li class="page-item active"><span class="page-link"><%= p %></span></li>
|
||||
<% else %>
|
||||
<li class="page-item"><%= link_to p, tournaments_path(page: p, search: params[:search]), class: "page-link" %></li>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<%# Next link %>
|
||||
<% if @page < @total_pages %>
|
||||
<li class="page-item">
|
||||
<%= link_to 'Next', tournaments_path(page: @page + 1, search: params[:search]), class: "page-link" %>
|
||||
</li>
|
||||
<% else %>
|
||||
<li class="page-item disabled"><span class="page-link">Next</span></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<p class="text-muted">
|
||||
<% start_index = ((@page - 1) * @per_page) + 1
|
||||
end_index = [@page * @per_page, @total_count].min
|
||||
%>
|
||||
Showing <%= start_index %> - <%= end_index %> of <%= @total_count %> tournaments
|
||||
</p>
|
||||
<% end %>
|
||||
|
||||
@@ -33,4 +33,7 @@
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</table>
|
||||
<br>
|
||||
<p>Total matches without byes: <%= @matches.select{|m| m.loser1_name != 'BYE' and m.loser2_name != 'BYE'}.size %></p>
|
||||
<p>Unfinished matches: <%= @matches.select{|m| m.finished != 1 and m.loser1_name != 'BYE' and m.loser2_name != 'BYE'}.size %></p>
|
||||
@@ -78,7 +78,7 @@
|
||||
<tr>
|
||||
<td><%= delegate.user.email %></td>
|
||||
<td><%= delegate.school.name %></td>
|
||||
<td><%= link_to 'Remove permissions', "/tournaments/#{@tournament.id}/#{delegate.id}/remove_school_delegate", method: :delete, confirm: 'Are you sure?', :class=>"btn btn-danger btn-sm" %></td>
|
||||
<td><%= link_to 'Remove permissions', "/tournaments/#{@tournament.id}/#{delegate.id}/remove_school_delegate", data: { turbo_method: :delete, turbo_confirm: 'Are you sure?' }, :class=>"btn btn-danger btn-sm" %></td>
|
||||
</tr>
|
||||
|
||||
<% end %>
|
||||
|
||||
@@ -70,9 +70,13 @@
|
||||
</td>
|
||||
<td>
|
||||
<% if can? :manage, school %>
|
||||
<%= link_to '', edit_school_path(school), :class=>"fas fa-edit" %>
|
||||
<%= link_to edit_school_path(school), class: "text-decoration-none" do %>
|
||||
<span class="fas fa-edit" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
<% if can? :manage, @tournament %>
|
||||
<%= link_to '', school, method: :delete, data: { confirm: "Are you sure you want to delete #{school.name}?" }, :class=>"fas fa-trash-alt" %>
|
||||
<%= link_to school, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{school.name}?" }, class: "text-decoration-none" do %>
|
||||
<span class="fas fa-trash-alt" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</td>
|
||||
@@ -105,8 +109,12 @@
|
||||
<td><%= weight.bracket_size %></td>
|
||||
<% if can? :manage, @tournament %>
|
||||
<td>
|
||||
<%= link_to '', edit_weight_path(weight), :class=>"fas fa-edit" %>
|
||||
<%= link_to '', weight, method: :delete, data: { confirm: "Are you sure you want to delete the #{weight.max} weight class?" }, :class=>"fas fa-trash-alt" %>
|
||||
<%= link_to edit_weight_path(weight), class: "text-decoration-none" do %>
|
||||
<span class="fas fa-edit" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
<%= link_to weight, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete the #{weight.max} weight class?" }, class: "text-decoration-none" do %>
|
||||
<span class="fas fa-trash-alt" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
@@ -130,8 +138,10 @@
|
||||
<td><%= link_to "Mat #{mat.name}", mat %></td>
|
||||
<% if can? :manage, @tournament %>
|
||||
<td>
|
||||
<%= link_to '', mat, method: :delete, data: { confirm: "Are you sure you want to delete Mat #{mat.name}?" }, :class=>"fas fa-trash-alt" %>
|
||||
<%= link_to '', "/mats/#{mat.id}/assign_next_match", method: :post, :class=>"fas fa-solid fa-arrow-right" %>
|
||||
<%= link_to mat, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete Mat #{mat.name}?" }, class: "text-decoration-none" do %>
|
||||
<span class="fas fa-trash-alt" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
<%= link_to '', "/mats/#{mat.id}/assign_next_match", data: { turbo_method: :post }, :class=>"fas fa-solid fa-arrow-right" %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
|
||||
@@ -47,10 +47,10 @@
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= point_adjustment.points %></td>
|
||||
<td><%= link_to 'Remove Point Adjustment', "/tournaments/#{@tournament.id}/#{point_adjustment.id}/remove_teampointadjust", method: :delete, confirm: 'Are you sure?', :class=>"btn btn-danger btn-sm" %></td>
|
||||
<td><%= link_to 'Remove Point Adjustment', "/tournaments/#{@tournament.id}/#{point_adjustment.id}/remove_teampointadjust", data: { turbo_method: :delete, turbo_confirm: 'Are you sure?' }, :class=>"btn btn-danger btn-sm" %></td>
|
||||
</tr>
|
||||
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -5,7 +5,23 @@
|
||||
// } );
|
||||
</script>
|
||||
<script>
|
||||
setTimeout("location.reload(true);",30000);
|
||||
const setUpMatchesRefresh = () => {
|
||||
if (window.__upMatchesRefreshTimeout) {
|
||||
clearTimeout(window.__upMatchesRefreshTimeout);
|
||||
}
|
||||
window.__upMatchesRefreshTimeout = setTimeout(() => {
|
||||
window.location.reload(true);
|
||||
}, 30000);
|
||||
};
|
||||
|
||||
document.addEventListener("turbo:load", setUpMatchesRefresh);
|
||||
// turbo:before-cache stops the timer refresh from occurring if you navigate away from up_matches
|
||||
document.addEventListener("turbo:before-cache", () => {
|
||||
if (window.__upMatchesRefreshTimeout) {
|
||||
clearTimeout(window.__upMatchesRefreshTimeout);
|
||||
window.__upMatchesRefreshTimeout = null;
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<br>
|
||||
<br>
|
||||
@@ -28,10 +44,34 @@
|
||||
<% @mats.each.map do |m| %>
|
||||
<tr>
|
||||
<td><%= m.name %></td>
|
||||
<td><% if m.unfinished_matches.first %><strong><%=m.unfinished_matches.first.bout_number%></strong> - <%= m.unfinished_matches.first.weight_max %><br><%= m.unfinished_matches.first.w1_bracket_name %> vs. <%= m.unfinished_matches.first.w2_bracket_name %><% end %></td>
|
||||
<td><% if m.unfinished_matches.second %><strong><%=m.unfinished_matches.second.bout_number%></strong> - <%= m.unfinished_matches.second.weight_max %><br><%= m.unfinished_matches.second.w1_bracket_name %> vs. <%= m.unfinished_matches.second.w2_bracket_name %><% end %></td>
|
||||
<td><% if m.unfinished_matches.third %><strong><%=m.unfinished_matches.third.bout_number%></strong> - <%= m.unfinished_matches.third.weight_max %><br><%= m.unfinished_matches.third.w1_bracket_name %> vs. <%= m.unfinished_matches.third.w2_bracket_name %><% end %></td>
|
||||
<td><% if m.unfinished_matches.fourth %><strong><%=m.unfinished_matches.fourth.bout_number%></strong> - <%= m.unfinished_matches.fourth.weight_max %><br><%= m.unfinished_matches.fourth.w1_bracket_name %> vs. <%= m.unfinished_matches.fourth.w2_bracket_name %><% end %></td>
|
||||
<td>
|
||||
<% if m.unfinished_matches.first %><strong><%=m.unfinished_matches.first.bout_number%></strong> (<%= m.unfinished_matches.first.bracket_position %>)<br>
|
||||
<%= m.unfinished_matches.first.weight_max %> lbs
|
||||
<br><%= m.unfinished_matches.first.w1_bracket_name %> vs. <br>
|
||||
<%= m.unfinished_matches.first.w2_bracket_name %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<% if m.unfinished_matches.second %><strong><%=m.unfinished_matches.second.bout_number%></strong> (<%= m.unfinished_matches.second.bracket_position %>)<br>
|
||||
<%= m.unfinished_matches.second.weight_max %> lbs
|
||||
<br><%= m.unfinished_matches.second.w1_bracket_name %> vs. <br>
|
||||
<%= m.unfinished_matches.second.w2_bracket_name %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<% if m.unfinished_matches.third %><strong><%=m.unfinished_matches.third.bout_number%></strong> (<%= m.unfinished_matches.third.bracket_position %>)<br>
|
||||
<%= m.unfinished_matches.third.weight_max %> lbs
|
||||
<br><%= m.unfinished_matches.third.w1_bracket_name %> vs. <br>
|
||||
<%= m.unfinished_matches.third.w2_bracket_name %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td>
|
||||
<% if m.unfinished_matches.fourth %><strong><%=m.unfinished_matches.fourth.bout_number%></strong> (<%= m.unfinished_matches.fourth.bracket_position %>)<br>
|
||||
<%= m.unfinished_matches.fourth.weight_max %> lbs
|
||||
<br><%= m.unfinished_matches.fourth.w1_bracket_name %> vs. <br>
|
||||
<%= m.unfinished_matches.fourth.w2_bracket_name %>
|
||||
<% end %>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
|
||||
@@ -1,48 +1,50 @@
|
||||
<h3>Weight Class:<%= @weight.max %> <% if can? :manage, @tournament %><%= link_to " Edit", edit_weight_path(@weight), :class=>"fas fa-edit" %><% end %></h3>
|
||||
<h3>Weight Class:<%= @weight.max %> <% if can? :manage, @tournament %><%= link_to edit_weight_path(@weight), class: "text-decoration-none" do %><span class="fas fa-edit" aria-hidden="true"></span><% end %><% end %></h3>
|
||||
<br>
|
||||
<br>
|
||||
<table class="table table-hover table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>School</th>
|
||||
<th>Seed</th>
|
||||
<th>Record</th>
|
||||
<th>Seed Criteria</th>
|
||||
<th>Extra?</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<%= form_tag @wrestlers_update_path do %>
|
||||
<% @wrestlers.sort_by{|w| [w.original_seed ? 0 : 1, w.original_seed || 0]}.each do |wrestler| %>
|
||||
<% if wrestler.weight_id == @weight.id %>
|
||||
<tr>
|
||||
<td><%= link_to "#{wrestler.name}", wrestler %></td>
|
||||
<td><%= wrestler.school.name %></td>
|
||||
<td>
|
||||
<% if can? :manage, @tournament %>
|
||||
<%= fields_for "wrestler[]", wrestler do |w| %>
|
||||
<%= w.text_field :original_seed %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= wrestler.original_seed %>
|
||||
<% end %>
|
||||
</td>
|
||||
<td><%= wrestler.season_win %>-<%= wrestler.season_loss %></td>
|
||||
<td><%= wrestler.criteria %> Win <%= wrestler.season_win_percentage %>%</td>
|
||||
<td><% if wrestler.extra? == true %>
|
||||
Yes
|
||||
<% end %></td>
|
||||
<% if can? :manage, @tournament %>
|
||||
<td>
|
||||
<%= link_to '', wrestler, method: :delete, data: { confirm: "Are you sure you want to delete #{wrestler.name}? THIS WILL DELETE ALL MATCHES." } , :class=>"fas fa-trash-alt" %>
|
||||
<%= form_tag @wrestlers_update_path do %>
|
||||
<table class="table table-hover table-condensed">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>School</th>
|
||||
<th>Seed</th>
|
||||
<th>Record</th>
|
||||
<th>Seed Criteria</th>
|
||||
<th>Extra?</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @wrestlers.sort_by{|w| [w.original_seed ? 0 : 1, w.original_seed || 0]}.each do |wrestler| %>
|
||||
<% if wrestler.weight_id == @weight.id %>
|
||||
<tr>
|
||||
<td><%= link_to "#{wrestler.name}", wrestler %></td>
|
||||
<td><%= wrestler.school.name %></td>
|
||||
<td>
|
||||
<% if can? :manage, @tournament %>
|
||||
<%= fields_for "wrestler[]", wrestler do |w| %>
|
||||
<%= w.text_field :original_seed %>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= wrestler.original_seed %>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<td><%= wrestler.season_win %>-<%= wrestler.season_loss %></td>
|
||||
<td><%= wrestler.criteria %> Win <%= wrestler.season_win_percentage %>%</td>
|
||||
<td><% if wrestler.extra? == true %>
|
||||
Yes
|
||||
<% end %></td>
|
||||
<% if can? :manage, @tournament %>
|
||||
<td>
|
||||
<%= link_to wrestler, data: { turbo_method: :delete, turbo_confirm: "Are you sure you want to delete #{wrestler.name}? THIS WILL DELETE ALL MATCHES." }, class: "text-decoration-none" do %>
|
||||
<span class="fas fa-trash-alt" aria-hidden="true"></span>
|
||||
<% end %>
|
||||
</td>
|
||||
<% end %>
|
||||
</tr>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
<br><p>*All wrestlers without a seed (determined by tournament director) will be assigned a random bracket line.</p>
|
||||
<% if can? :manage, @tournament %>
|
||||
<br>
|
||||
@@ -81,4 +83,4 @@
|
||||
</ul>
|
||||
</li>
|
||||
</div>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
4
bin/dev
4
bin/dev
@@ -1,4 +1,2 @@
|
||||
#!/usr/bin/env ruby
|
||||
|
||||
# Start Rails server with defaults
|
||||
exec "bin/rails", "server", *ARGV
|
||||
exec "./bin/rails", "server", *ARGV
|
||||
|
||||
@@ -55,5 +55,7 @@ module Wrestling
|
||||
# Set cache format version to a value supported by Rails 8.0
|
||||
# Valid values are 7.0 or 7.1
|
||||
config.active_support.cache_format_version = 7.1
|
||||
|
||||
config.load_defaults 8.0
|
||||
end
|
||||
end
|
||||
|
||||
@@ -99,4 +99,7 @@ Rails.application.configure do
|
||||
|
||||
# Nobuild in development
|
||||
config.assets.build_assets = false
|
||||
|
||||
MissionControl::Jobs.http_basic_auth_user = "dev"
|
||||
MissionControl::Jobs.http_basic_auth_password = "secret"
|
||||
end
|
||||
|
||||
@@ -120,4 +120,7 @@ Rails.application.configure do
|
||||
config.assets.compile = true
|
||||
# Generate digests for assets URLs.
|
||||
config.assets.digest = true
|
||||
|
||||
MissionControl::Jobs.http_basic_auth_user = ENV["WRESTLINGDEV_MISSION_CONTROL_USER"]
|
||||
MissionControl::Jobs.http_basic_auth_password =ENV["WRESTLINGDEV_MISSION_CONTROL_PASSWORD"]
|
||||
end
|
||||
|
||||
7
config/initializers/assets.rb
Normal file
7
config/initializers/assets.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
# Be sure to restart your server when you modify this file.
|
||||
|
||||
# Version of your assets, change this if you want to expire all your assets.
|
||||
Rails.application.config.assets.version = "1.0"
|
||||
|
||||
# Add additional assets to the asset load path.
|
||||
# Rails.application.config.assets.paths << Emoji.images_path
|
||||
@@ -1,6 +1,7 @@
|
||||
Wrestling::Application.routes.draw do
|
||||
# Mount Action Cable server
|
||||
mount ActionCable.server => '/cable'
|
||||
mount MissionControl::Jobs::Engine, at: "/jobs"
|
||||
|
||||
resources :mats
|
||||
post "mats/:id/assign_next_match" => "mats#assign_next_match", :as => :assign_next_match
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
class IncreaseSolidQueueJobArgumentsLimit < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
# Allow large payloads (e.g., pasted import text) to be enqueued without blowing up MySQL's TEXT limit (~64KB).
|
||||
change_column :solid_queue_jobs, :arguments, :text, limit: 16.megabytes - 1
|
||||
end
|
||||
|
||||
def down
|
||||
change_column :solid_queue_jobs, :arguments, :text
|
||||
end
|
||||
end
|
||||
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_04_04_153529) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2025_05_04_190000) do
|
||||
create_table "solid_queue_blocked_executions", force: :cascade do |t|
|
||||
t.bigint "job_id", null: false
|
||||
t.string "queue_name", null: false
|
||||
@@ -41,7 +41,7 @@ ActiveRecord::Schema[8.0].define(version: 2025_04_04_153529) do
|
||||
create_table "solid_queue_jobs", force: :cascade do |t|
|
||||
t.string "queue_name", null: false
|
||||
t.string "class_name", null: false
|
||||
t.text "arguments"
|
||||
t.text "arguments", limit: 16777215
|
||||
t.integer "priority", default: 0, null: false
|
||||
t.string "active_job_id"
|
||||
t.datetime "scheduled_at"
|
||||
|
||||
@@ -113,7 +113,7 @@
|
||||
|
||||
# Regular Double Elimination 1-8
|
||||
tournament = Tournament.create(id: 204, name: 'Regular Double Elimination 1-8', address: 'some place', director: 'some guy', director_email: 'their@email.com', tournament_type: 'Regular Double Elimination 1-8', user_id: 1, date: future_date, is_public: true)
|
||||
create_schools(tournament, 32)
|
||||
create_schools(tournament, 64)
|
||||
weight_classes=Weight::HS_WEIGHT_CLASSES.split(",")
|
||||
tournament.create_pre_defined_weights(weight_classes)
|
||||
wrestler_name_number = 1
|
||||
@@ -126,6 +126,8 @@
|
||||
number_of_wrestlers = 32
|
||||
elsif index == 3
|
||||
number_of_wrestlers = 17
|
||||
elsif index == 4
|
||||
number_of_wrestlers = 62
|
||||
else
|
||||
number_of_wrestlers = 16
|
||||
end
|
||||
|
||||
@@ -25,9 +25,11 @@ docker-compose -f ${project_dir}/deploy/docker-compose-test.yml run --rm app bin
|
||||
docker-compose -f ${project_dir}/deploy/docker-compose-test.yml run --rm app bin/rails db:migrate:queue
|
||||
docker-compose -f ${project_dir}/deploy/docker-compose-test.yml run --rm app bin/rails db:migrate:cable
|
||||
|
||||
# Start all services (will start app and others, db is already running)
|
||||
echo "Stopping all services..."
|
||||
docker-compose -f ${project_dir}/deploy/docker-compose-test.yml down
|
||||
|
||||
echo "Starting application services..."
|
||||
docker-compose -f ${project_dir}/deploy/docker-compose-test.yml up -d
|
||||
docker-compose -f ${project_dir}/deploy/docker-compose-test.yml up --force-recreate --remove-orphans -d
|
||||
|
||||
# DISABLE_DATABASE_ENVIRONMENT_CHECK=1 is needed because this is "destructive" action on production
|
||||
echo Resetting the db with seed data
|
||||
|
||||
@@ -26,6 +26,8 @@ services:
|
||||
- WRESTLINGDEV_INFLUXDB_HOST=influxdb
|
||||
- WRESTLINGDEV_INFLUXDB_PORT=8086
|
||||
- SOLID_QUEUE_IN_PUMA=true
|
||||
- WRESTLINGDEV_MISSION_CONTROL_USER=dev
|
||||
- WRESTLINGDEV_MISSION_CONTROL_PASSWORD=secret
|
||||
networks:
|
||||
database:
|
||||
caching:
|
||||
|
||||
160
deploy/kubernetes/manifests/mariadb-replica-watcher.yaml
Normal file
160
deploy/kubernetes/manifests/mariadb-replica-watcher.yaml
Normal file
@@ -0,0 +1,160 @@
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: mariadb-replica-watcher
|
||||
labels:
|
||||
app: wrestlingdev
|
||||
component: mariadb-watcher
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: wrestlingdev
|
||||
component: mariadb-watcher
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: wrestlingdev
|
||||
component: mariadb-watcher
|
||||
spec:
|
||||
containers:
|
||||
- name: replica-watcher
|
||||
image: mariadb:10.3
|
||||
env:
|
||||
- name: MARIADB_ROOT_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: wrestlingdev-secrets
|
||||
key: dbpassword
|
||||
- name: MYSQL_REPLICATION_USER
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: wrestlingdev-secrets
|
||||
key: replication_user
|
||||
- name: MYSQL_REPLICATION_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: wrestlingdev-secrets
|
||||
key: replication_password
|
||||
- name: MASTER_SERVICE_HOST
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: wrestlingdev-secrets
|
||||
key: replication_host
|
||||
- name: REPLICA_SERVICE_HOST
|
||||
value: "wrestlingdev-mariadb"
|
||||
- name: DB_NAME
|
||||
value: "wrestlingdev"
|
||||
command:
|
||||
- bash
|
||||
- -c
|
||||
- |
|
||||
set -euo pipefail
|
||||
LOG=/var/log/replica-watcher.log
|
||||
echo "replica-watcher starting: $(date -u)" >>"$LOG"
|
||||
|
||||
trim() { sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'; }
|
||||
get_val() {
|
||||
grep -m1 -E "^[[:space:]]*$1[[:space:]]*:" \
|
||||
| sed -E "s/^[[:space:]]*$1[[:space:]]*:[[:space:]]*(.*)$/\1/" \
|
||||
| tr -d '\r' \
|
||||
| xargs
|
||||
}
|
||||
|
||||
# initial wait
|
||||
sleep 120
|
||||
while true; do
|
||||
echo "$(date -u) Checking SHOW SLAVE STATUS" | tee -a "$LOG"
|
||||
SLAVE_RAW=$(mysql --protocol=TCP -h "$REPLICA_SERVICE_HOST" -uroot -p"$MARIADB_ROOT_PASSWORD" -e "SHOW SLAVE STATUS\\G" 2>>"$LOG" || true)
|
||||
|
||||
NEED=0
|
||||
if [ -z "$SLAVE_RAW" ]; then
|
||||
echo "SHOW SLAVE STATUS is empty (replication not configured / not running) -> will rebootstrap" | tee -a "$LOG"
|
||||
NEED=1
|
||||
else
|
||||
SLAVE_IO=$(echo "$SLAVE_RAW" | get_val "Slave_IO_Running")
|
||||
SLAVE_SQL=$(echo "$SLAVE_RAW" | get_val "Slave_SQL_Running")
|
||||
LAST_IO_ERRNO=$(echo "$SLAVE_RAW" | get_val "Last_IO_Errno")
|
||||
LAST_SQL_ERRNO=$(echo "$SLAVE_RAW" | get_val "Last_SQL_Errno")
|
||||
LAST_IO_ERR=$(echo "$SLAVE_RAW" | get_val "Last_IO_Error")
|
||||
LAST_SQL_ERR=$(echo "$SLAVE_RAW" | get_val "Last_SQL_Error")
|
||||
|
||||
echo "Slave IO='${SLAVE_IO:-}' Slave SQL='${SLAVE_SQL:-}'" | tee -a "$LOG"
|
||||
echo "Last_IO_Errno='${LAST_IO_ERRNO:-}' Last_SQL_Errno='${LAST_SQL_ERRNO:-}'" | tee -a "$LOG"
|
||||
echo "Last_IO_Error='${LAST_IO_ERR:-}' Last_SQL_Error='${LAST_SQL_ERR:-}'" | tee -a "$LOG"
|
||||
|
||||
if [ "${SLAVE_IO:-}" = "Yes" ] && [ "${SLAVE_SQL:-}" = "Yes" ] \
|
||||
&& { [ -z "${LAST_IO_ERR:-}" ] || [ "${LAST_IO_ERR,,}" = "no error" ]; } \
|
||||
&& { [ -z "${LAST_SQL_ERR:-}" ] || [ "${LAST_SQL_ERR,,}" = "no error" ]; } \
|
||||
&& { [ -z "${LAST_IO_ERRNO:-}" ] || [ "${LAST_IO_ERRNO:-0}" = "0" ]; } \
|
||||
&& { [ -z "${LAST_SQL_ERRNO:-}" ] || [ "${LAST_SQL_ERRNO:-0}" = "0" ]; }; then
|
||||
echo "Both slave threads running and no replication errors -> no action" | tee -a "$LOG"
|
||||
else
|
||||
NOT_RUNNING=0
|
||||
[ "${SLAVE_IO:-No}" != "Yes" ] && NOT_RUNNING=1
|
||||
[ "${SLAVE_SQL:-No}" != "Yes" ] && NOT_RUNNING=1
|
||||
HAS_ERROR=0
|
||||
[ -n "${LAST_IO_ERRNO:-}" ] && [ "${LAST_IO_ERRNO:-0}" != "0" ] && HAS_ERROR=1
|
||||
[ -n "${LAST_SQL_ERRNO:-}" ] && [ "${LAST_SQL_ERRNO:-0}" != "0" ] && HAS_ERROR=1
|
||||
ERR_TEXT="$(printf '%s %s' "${LAST_IO_ERR:-}" "${LAST_SQL_ERR:-}" | tr '[:upper:]' '[:lower:]' | trim)"
|
||||
[ -n "$ERR_TEXT" ] && [ "$ERR_TEXT" != "no error" ] && HAS_ERROR=1
|
||||
|
||||
echo "Decision: NOT_RUNNING=$NOT_RUNNING HAS_ERROR=$HAS_ERROR" | tee -a "$LOG"
|
||||
[ $NOT_RUNNING -eq 1 ] || [ $HAS_ERROR -eq 1 ] && NEED=1 || echo "Threads healthy -> no action" | tee -a "$LOG"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $NEED -eq 1 ]; then
|
||||
echo "$(date -u) Starting rebootstrap flow" | tee -a "$LOG"
|
||||
|
||||
MASTER_STATUS=$(mysql --protocol=TCP -h "$MASTER_SERVICE_HOST" -uroot -p"$MARIADB_ROOT_PASSWORD" -sse "SHOW MASTER STATUS;" 2>>"$LOG" || true)
|
||||
MASTER_LOG_FILE=$(echo "$MASTER_STATUS" | awk '{print $1}' | trim || true)
|
||||
MASTER_LOG_POS=$(echo "$MASTER_STATUS" | awk '{print $2}' | trim || true)
|
||||
if [ -z "$MASTER_LOG_FILE" ] || [ -z "$MASTER_LOG_POS" ]; then
|
||||
echo "Failed to get master position from $MASTER_SERVICE_HOST" | tee -a "$LOG"
|
||||
sleep 120; continue
|
||||
fi
|
||||
echo "Master position: ${MASTER_LOG_FILE}:${MASTER_LOG_POS}" | tee -a "$LOG"
|
||||
|
||||
echo "Stopping slave on replica host" | tee -a "$LOG"
|
||||
mysql --protocol=TCP -h "$REPLICA_SERVICE_HOST" -uroot -p"$MARIADB_ROOT_PASSWORD" -e "STOP SLAVE;" >>"$LOG" 2>&1 || true
|
||||
|
||||
DUMP_FILE="/tmp/${DB_NAME}_backup.sql"
|
||||
echo "Dumping ${DB_NAME} from master ${MASTER_SERVICE_HOST}" | tee -a "$LOG"
|
||||
if command -v timeout >/dev/null 2>&1; then
|
||||
if ! timeout 300 mysqldump --protocol=TCP -h "$MASTER_SERVICE_HOST" -uroot -p"$MARIADB_ROOT_PASSWORD" --single-transaction "$DB_NAME" \
|
||||
| tee "$DUMP_FILE" >/dev/null 2>>"$LOG"; then
|
||||
echo "Dump FAILED; aborting this cycle" | tee -a "$LOG"; sleep 120; continue
|
||||
fi
|
||||
else
|
||||
if ! mysqldump --protocol=TCP -h "$MASTER_SERVICE_HOST" -uroot -p"$MARIADB_ROOT_PASSWORD" --single-transaction "$DB_NAME" \
|
||||
| tee "$DUMP_FILE" >/dev/null 2>>"$LOG"; then
|
||||
echo "Dump FAILED; aborting this cycle" | tee -a "$LOG"; sleep 120; continue
|
||||
fi
|
||||
fi
|
||||
|
||||
ls -lh $DUMP_FILE
|
||||
|
||||
echo "Ensuring database '$DB_NAME' exists on replica" | tee -a "$LOG"
|
||||
mysql --protocol=TCP -h "$REPLICA_SERVICE_HOST" -uroot -p"$MARIADB_ROOT_PASSWORD" \
|
||||
-e "CREATE DATABASE IF NOT EXISTS \`$DB_NAME\`;" >>"$LOG" 2>&1
|
||||
|
||||
echo "Importing dump into replica host" | tee -a "$LOG"
|
||||
if ! cat "$DUMP_FILE" | mysql --protocol=TCP -h "$REPLICA_SERVICE_HOST" -uroot -p"$MARIADB_ROOT_PASSWORD" "$DB_NAME" >>"$LOG" 2>&1; then
|
||||
echo "Import FAILED; aborting this cycle (replication will not be reconfigured)" | tee -a "$LOG"
|
||||
sleep 120; continue
|
||||
fi
|
||||
echo "Import completed successfully" | tee -a "$LOG"
|
||||
|
||||
echo "Reconfiguring replication to ${MASTER_SERVICE_HOST}:${MASTER_LOG_FILE}:${MASTER_LOG_POS}" | tee -a "$LOG"
|
||||
mysql --protocol=TCP -h "$REPLICA_SERVICE_HOST" -uroot -p"$MARIADB_ROOT_PASSWORD" -e "RESET SLAVE ALL;" >>"$LOG" 2>&1 || true
|
||||
mysql --protocol=TCP -h "$REPLICA_SERVICE_HOST" -uroot -p"$MARIADB_ROOT_PASSWORD" -e "CHANGE MASTER TO MASTER_HOST='${MASTER_SERVICE_HOST}', MASTER_USER='${MYSQL_REPLICATION_USER}', MASTER_PASSWORD='${MYSQL_REPLICATION_PASSWORD}', MASTER_LOG_FILE='${MASTER_LOG_FILE}', MASTER_LOG_POS=${MASTER_LOG_POS}; START SLAVE;" >>"$LOG" 2>&1 || true
|
||||
|
||||
echo "SHOW SLAVE STATUS after rebootstrap:" | tee -a "$LOG"
|
||||
mysql --protocol=TCP -h "$REPLICA_SERVICE_HOST" -uroot -p"$MARIADB_ROOT_PASSWORD" -e "SHOW SLAVE STATUS\\G" >>"$LOG" 2>&1 || true
|
||||
fi
|
||||
|
||||
echo "Sleeping 120s before next check" | tee -a "$LOG"
|
||||
sleep 120
|
||||
done
|
||||
restartPolicy: Always
|
||||
@@ -214,6 +214,6 @@ data:
|
||||
# if you want to ignore dbs to replicate
|
||||
# replicate-ignore-db=wrestlingtourney-queue
|
||||
# if you only want to replicate certain dbs
|
||||
replicate-do-db=wrestlingtourney
|
||||
replicate-do-db=wrestlingdev
|
||||
|
||||
# /etc/mysql/mariadb.conf.d/70-mysettings.cnf
|
||||
|
||||
@@ -56,6 +56,16 @@ spec:
|
||||
secretKeyRef:
|
||||
name: wrestlingdev-secrets
|
||||
key: dbpassword
|
||||
- name: REPLICATION_USER
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: wrestlingdev-secrets
|
||||
key: replication_user
|
||||
- name: REPLICATION_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: wrestlingdev-secrets
|
||||
key: replication_password
|
||||
ports:
|
||||
- containerPort: 3306
|
||||
name: mariadb
|
||||
@@ -64,12 +74,36 @@ spec:
|
||||
mountPath: /var/lib/mysql
|
||||
- name: mysettings-config-volume
|
||||
mountPath: /etc/mysql/mariadb.conf.d
|
||||
# lifecycle: create replication user with proper privileges if it doesn't exist
|
||||
lifecycle:
|
||||
postStart:
|
||||
exec:
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
# Wait up to 60s for mysqld to be available
|
||||
for i in $(seq 1 60); do
|
||||
if mysqladmin ping -uroot -p"$MARIADB_ROOT_PASSWORD" --silent; then
|
||||
echo "mysqld is up"
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo "Ensuring replication user ${REPLICATION_USER} exists and has REPLICATION SLAVE privileges"
|
||||
|
||||
# Create the replication user if it doesn't exist and grant replication privileges.
|
||||
# Use CREATE USER IF NOT EXISTS so the command is idempotent.
|
||||
mysql -uroot -p"$MARIADB_ROOT_PASSWORD" -e "CREATE USER IF NOT EXISTS '${REPLICATION_USER}'@'%' IDENTIFIED BY '${REPLICATION_PASSWORD}';" 2>/dev/null || true
|
||||
mysql -uroot -p"$MARIADB_ROOT_PASSWORD" -e "GRANT REPLICATION SLAVE ON *.* TO '${REPLICATION_USER}'@'%';" 2>/dev/null || true
|
||||
mysql -uroot -p"$MARIADB_ROOT_PASSWORD" -e "FLUSH PRIVILEGES;" 2>/dev/null || true
|
||||
echo "Replication user ready (errors ignored to avoid blocking startup)"
|
||||
# resources:
|
||||
# limits:
|
||||
# memory: "512Mi"
|
||||
# requests:
|
||||
# memory: "256Mi"
|
||||
# cpu: "0.2"
|
||||
- image: jcwimer/mariadb-rclone-backup-docker:10.3
|
||||
name: mariadb-backup
|
||||
env:
|
||||
@@ -204,5 +238,14 @@ data:
|
||||
performance_schema=ON
|
||||
innodb_log_file_size=32M
|
||||
table_open_cache=4000
|
||||
expire_logs_days=7
|
||||
|
||||
# master slave
|
||||
server_id=1 # Unique server ID for the master
|
||||
log_bin=mysql-bin # Enable binary logging
|
||||
binlog_format=ROW # Recommended format for replication (ROW, STATEMENT, or MIXED)
|
||||
log_slave_updates=ON # Ensure any changes replicated to the master are also logged to the binary log (useful for multi-source replication)
|
||||
sync_binlog=1 # Ensures binary logs are synchronized with disk after each transaction for data safety
|
||||
expire_logs_days=7 # Optional: Number of days to retain binary logs (helps with cleanup)
|
||||
|
||||
# /etc/mysql/mariadb.conf.d/70-mysettings.cnf
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: wrestlingdev-memcached
|
||||
labels:
|
||||
app: wrestlingdev
|
||||
spec:
|
||||
ports:
|
||||
- port: 11211
|
||||
selector:
|
||||
app: wrestlingdev
|
||||
tier: memcached
|
||||
clusterIP: None
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: wrestlingdev-memcached-deployment
|
||||
labels:
|
||||
app: wrestlingdev
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: wrestlingdev
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: wrestlingdev
|
||||
tier: memcached
|
||||
spec:
|
||||
containers:
|
||||
- name: wrestlingdev-memcached
|
||||
image: memcached
|
||||
ports:
|
||||
- containerPort: 11211
|
||||
resources:
|
||||
limits:
|
||||
memory: "64Mi"
|
||||
# requests:
|
||||
# memory: "64Mi"
|
||||
# cpu: "0.1"
|
||||
@@ -109,6 +109,16 @@ spec:
|
||||
secretKeyRef:
|
||||
name: wrestlingdev-secrets
|
||||
key: influxdb_port
|
||||
- name: WRESTLINGDEV_MISSION_CONTROL_USER
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: wrestlingdev-secrets
|
||||
key: mission_control_user
|
||||
- name: WRESTLINGDEV_MISSION_CONTROL_PASSWORD
|
||||
valueFrom:
|
||||
secretKeyRef:
|
||||
name: wrestlingdev-secrets
|
||||
key: mission_control_password
|
||||
# resources:
|
||||
# limits:
|
||||
# memory: "768Mi"
|
||||
@@ -122,25 +132,27 @@ spec:
|
||||
initialDelaySeconds: 180
|
||||
periodSeconds: 20
|
||||
timeoutSeconds: 10
|
||||
# ---
|
||||
# apiVersion: autoscaling/v2beta1
|
||||
# kind: HorizontalPodAutoscaler
|
||||
# metadata:
|
||||
# name: wrestlingdev-app-deployment-autoscale
|
||||
# spec:
|
||||
# scaleTargetRef:
|
||||
# apiVersion: apps/v1
|
||||
# kind: Deployment
|
||||
# name: wrestlingdev-app-deployment
|
||||
# minReplicas: 2
|
||||
# maxReplicas: 5
|
||||
# metrics:
|
||||
# - type: Resource
|
||||
# resource:
|
||||
# name: cpu
|
||||
# targetAverageUtilization: 75
|
||||
# - type: Resource
|
||||
# resource:
|
||||
# name: memory
|
||||
# targetAverageValue: 100Mi
|
||||
---
|
||||
apiVersion: autoscaling/v2beta1
|
||||
kind: HorizontalPodAutoscaler
|
||||
metadata:
|
||||
name: wrestlingdev-app-autoscale
|
||||
spec:
|
||||
scaleTargetRef:
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
name: wrestlingdev-app
|
||||
minReplicas: 2
|
||||
maxReplicas: 5
|
||||
metrics:
|
||||
- type: Resource
|
||||
resource:
|
||||
name: cpu
|
||||
targetAverageUtilization: 75
|
||||
- type: Resource
|
||||
resource:
|
||||
name: memory
|
||||
target:
|
||||
type: Utilization
|
||||
averageUtilization: 80
|
||||
|
||||
|
||||
@@ -14,6 +14,14 @@ stringData:
|
||||
gmailpassword: PUT_EMAIL_PASSWORD_HERE # gmail password
|
||||
gmailemail: PUT EMAIL ADDRESS HERE
|
||||
passenger_pool_size: "2"
|
||||
# Replication credentials (create a dedicated user for replication)
|
||||
replication_user: replica_user_here
|
||||
replication_password: PUT_REPLICATION_PASSWORD_HERE
|
||||
# Replication host used by the replica to connect to the master
|
||||
replication_host: wrestlingdev-mariadb
|
||||
# Mission Control Credentials
|
||||
mission_control_user: PUT_MISSION_CONTROL_USERNAME_HERE
|
||||
mission_control_password: PUT_MISSION_CONTROL_PASSWORD_HERE
|
||||
# OPTIONAL
|
||||
# DELETE THESE LINES IF YOU'RE NOT USING THEM
|
||||
influxdb_database: PUT INFLUXDB DATABASE NAME HERE
|
||||
|
||||
@@ -4,7 +4,7 @@ FROM ruby:3.2.0
|
||||
ARG USER_ID=1000
|
||||
ARG GROUP_ID=1000
|
||||
|
||||
RUN apt-get -qq update \
|
||||
RUN apt-get -qq update --fix-missing \
|
||||
&& apt-get -qq install -y \
|
||||
build-essential \
|
||||
sqlite3 \
|
||||
|
||||
@@ -6,7 +6,7 @@ ENV TINI_VERSION v0.19.0
|
||||
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
|
||||
RUN chmod +x /tini
|
||||
|
||||
RUN apt-get -qq update \
|
||||
RUN apt-get -qq update --fix-missing \
|
||||
&& DEBIAN_FRONTEND=noninteractive apt-get -qq install -y \
|
||||
build-essential \
|
||||
openssl \
|
||||
|
||||
@@ -27,18 +27,19 @@ namespace :tournament do
|
||||
)
|
||||
|
||||
GenerateTournamentMatches.new(@tournament).generate
|
||||
sleep(10)
|
||||
sleep(60)
|
||||
while @tournament.reload.curently_generating_matches == 1
|
||||
puts "Waiting for tournament to finish generating matches..."
|
||||
sleep(5)
|
||||
@tournament.reload
|
||||
end
|
||||
|
||||
sleep(10)
|
||||
@tournament.reload # Ensure matches association is fresh before iterating
|
||||
@tournament.matches.sort_by(&:bout_number).each do |match|
|
||||
match.reload
|
||||
if match.loser1_name != "BYE" and match.loser2_name != "BYE"
|
||||
@tournament.matches.reload.sort_by(&:bout_number).each do |match|
|
||||
if match.reload.loser1_name != "BYE" and match.reload.loser2_name != "BYE" and match.reload.finished != 1
|
||||
# Wait until both wrestlers are assigned
|
||||
while match.w1.nil? || match.w2.nil?
|
||||
while (match.w1.nil? || match.w2.nil?)
|
||||
puts "Waiting for wrestlers in match #{match.bout_number}..."
|
||||
sleep(5) # Wait for 5 seconds before checking again
|
||||
match.reload
|
||||
@@ -77,6 +78,8 @@ namespace :tournament do
|
||||
# Mark match as finished
|
||||
match.finished = 1
|
||||
match.save!
|
||||
# sleep to prevent mysql locks when assign_next_match to a mat runs
|
||||
sleep(0.5)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
1
public/ads.txt
Normal file
1
public/ads.txt
Normal file
@@ -0,0 +1 @@
|
||||
google.com, pub-6845455733812572, DIRECT, f08c47fec0942fa0
|
||||
@@ -357,7 +357,7 @@ Some Guy
|
||||
|
||||
@school.wrestlers.each do |wrestler|
|
||||
# Check only for the DELETE link, specifying 'data-method="delete"' to exclude profile links
|
||||
assert_select "a[href=?][data-method=delete]", wrestler_path(wrestler), count: 1
|
||||
assert_select "a[href=?][data-turbo-method=delete]", wrestler_path(wrestler), count: 1
|
||||
|
||||
# Check edit link
|
||||
assert_select "a[href=?]", edit_wrestler_path(wrestler), count: 1
|
||||
@@ -373,12 +373,26 @@ Some Guy
|
||||
success
|
||||
end
|
||||
|
||||
test "logged in user without delegation can get show page when using valid school_permission_key" do
|
||||
sign_in_non_owner
|
||||
@tournament.update(is_public: false)
|
||||
get_show(school_permission_key: @school_permission_key)
|
||||
success
|
||||
end
|
||||
|
||||
test "non logged in user cannot get show page when using invalid school_permission_key" do
|
||||
@tournament.update(is_public: false)
|
||||
get_show(school_permission_key: "invalid-key")
|
||||
redirect
|
||||
end
|
||||
|
||||
test "logged in user without delegation can edit school with valid school_permission_key" do
|
||||
sign_in_non_owner
|
||||
@tournament.update(is_public: false)
|
||||
get_edit(school_permission_key: @school_permission_key)
|
||||
success
|
||||
end
|
||||
|
||||
test "non logged in user can edit school with valid school_permission_key" do
|
||||
@tournament.update(is_public: false)
|
||||
get_edit(school_permission_key: @school_permission_key)
|
||||
|
||||
@@ -1084,4 +1084,55 @@ class TournamentsControllerTest < ActionController::TestCase
|
||||
assert_match(/#{match.bout_number}/, response.body, "Bout number #{match.bout_number} is missing from the bracket page")
|
||||
end
|
||||
end
|
||||
test "index sorts tournaments by date closest to today" do
|
||||
today = Date.today
|
||||
t_today = Tournament.create!(name: "Closest Today", address: "123 Test St", director: "Director", director_email: "today@example.com", date: today, tournament_type: "Pool to bracket", is_public: true)
|
||||
t_minus1 = Tournament.create!(name: "Minus 1", address: "123 Test St", director: "Director", director_email: "m1@example.com", date: today - 1, tournament_type: "Pool to bracket", is_public: true)
|
||||
t_plus1 = Tournament.create!(name: "Plus 1", address: "123 Test St", director: "Director", director_email: "p1@example.com", date: today + 1, tournament_type: "Pool to bracket", is_public: true)
|
||||
t_plus2 = Tournament.create!(name: "Plus 2", address: "123 Test St", director: "Director", director_email: "p2@example.com", date: today + 2, tournament_type: "Pool to bracket", is_public: true)
|
||||
t_minus3 = Tournament.create!(name: "Minus 3", address: "123 Test St", director: "Director", director_email: "m3@example.com", date: today - 3, tournament_type: "Pool to bracket", is_public: true)
|
||||
t_plus10 = Tournament.create!(name: "Plus 10", address: "123 Test St", director: "Director", director_email: "p10@example.com", date: today + 10, tournament_type: "Pool to bracket", is_public: true)
|
||||
|
||||
created = [t_today, t_minus1, t_plus1, t_plus2, t_minus3, t_plus10]
|
||||
# Hit index
|
||||
get :index
|
||||
assert_response :success
|
||||
|
||||
# From the controller result, select only the tournaments we just created and verify their relative order
|
||||
results = assigns(:tournaments).select { |t| created.map(&:id).include?(t.id) }
|
||||
expected_order = created.sort_by { |t| (t.date - today).abs }.map(&:id)
|
||||
|
||||
# Basic ordering assertions
|
||||
assert_equal expected_order, results.map(&:id), "Created tournaments should be ordered by distance from today"
|
||||
assert_equal t_today.id, results.first.id, "The tournament dated today should be first (closest)"
|
||||
assert_equal t_plus10.id, results.last.id, "The farthest tournament should appear last"
|
||||
|
||||
# Relative order checks (smaller distance should appear before larger distance)
|
||||
assert results.index { |r| r.id == t_minus1.id } < results.index { |r| r.id == t_plus2.id }, "t_minus1 (distance 1) should appear before t_plus2 (distance 2)"
|
||||
assert results.index { |r| r.id == t_plus2.id } < results.index { |r| r.id == t_minus3.id }, "t_plus2 (distance 2) should appear before t_minus3 (distance 3)"
|
||||
end
|
||||
|
||||
test "index paginates tournaments with page param and exposes total_count" do
|
||||
initial_count = Tournament.count
|
||||
# Create 25 tournaments to ensure we exceed the per_page (20)
|
||||
25.times do |i|
|
||||
Tournament.create!(name: "Paginate Test #{i}", address: "1 Paginate Rd", director: "Dir", director_email: "paginate#{i}@example.com", date: Date.today + i, tournament_type: "Pool to bracket", is_public: true)
|
||||
end
|
||||
expected_total = initial_count + 25
|
||||
|
||||
# Page 1
|
||||
get :index, params: { page: 1 }
|
||||
assert_response :success
|
||||
assert_equal expected_total, assigns(:total_count), "total_count should reflect all tournaments"
|
||||
assert_equal 20, assigns(:tournaments).size, "first page should contain 20 tournaments"
|
||||
|
||||
# Page 2
|
||||
get :index, params: { page: 2 }
|
||||
assert_response :success
|
||||
assert_equal expected_total, assigns(:total_count), "total_count should remain the same on subsequent pages"
|
||||
expected_page2_size = expected_total - 20
|
||||
# If there are more than 20 initial fixtures, expected_page2_size might be > 20; clamp to per_page logic:
|
||||
expected_page2_display = [expected_page2_size, 20].min
|
||||
assert_equal expected_page2_display, assigns(:tournaments).size, "second page should contain the remaining tournaments (or up to per_page)"
|
||||
end
|
||||
end
|
||||
|
||||
22
test/fixtures/tournament_job_statuses.yml
vendored
22
test/fixtures/tournament_job_statuses.yml
vendored
@@ -2,26 +2,4 @@
|
||||
|
||||
# This model requires tournament, job_name, and status fields
|
||||
|
||||
queued_job:
|
||||
tournament: one
|
||||
job_name: "Test Queued Job"
|
||||
status: "Queued"
|
||||
details: "Test job details"
|
||||
|
||||
running_job:
|
||||
tournament: one
|
||||
job_name: "Test Running Job"
|
||||
status: "Running"
|
||||
details: "Test running job details"
|
||||
|
||||
errored_job:
|
||||
tournament: one
|
||||
job_name: "Test Errored Job"
|
||||
status: "Errored"
|
||||
details: "Test error message"
|
||||
|
||||
another_tournament_job:
|
||||
tournament: two
|
||||
job_name: "Another Tournament Job"
|
||||
status: "Running"
|
||||
details: "Different tournament test"
|
||||
|
||||
@@ -209,17 +209,17 @@ class DoubleEliminationThirtyTwoManEightPlacesMatchGeneration < ActionDispatch::
|
||||
assert wrestler3.reload.placement_points == 1
|
||||
end
|
||||
|
||||
test "Run through all matches works" do
|
||||
@tournament.matches.sort_by{ |match| match.bout_number }.each do |match|
|
||||
match.reload
|
||||
if match.finished != 1 and match.w1 and match.w2
|
||||
match.winner_id = match.w1
|
||||
match.win_type = "Decision"
|
||||
match.score = "0-0"
|
||||
match.finished = 1
|
||||
match.save
|
||||
end
|
||||
end
|
||||
assert @tournament.matches.reload.select{|m| m.finished == 0}.count == 0
|
||||
end
|
||||
# test "Run through all matches works" do
|
||||
# @tournament.matches.sort_by{ |match| match.bout_number }.each do |match|
|
||||
# match.reload
|
||||
# if match.finished != 1 and match.w1 and match.w2
|
||||
# match.winner_id = match.w1
|
||||
# match.win_type = "Decision"
|
||||
# match.score = "0-0"
|
||||
# match.finished = 1
|
||||
# match.save
|
||||
# end
|
||||
# end
|
||||
# assert @tournament.matches.reload.select{|m| m.finished == 0}.count == 0
|
||||
# end
|
||||
end
|
||||
@@ -0,0 +1,410 @@
|
||||
require 'test_helper'
|
||||
|
||||
class DoubleEliminationSixtyFourManEightPlacesMatchGeneration < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
# Create a 64‐slot double‐elimination bracket with 62 actual wrestlers (two byes for seeds 1 and 2)
|
||||
create_double_elim_tournament_single_weight(62, "Regular Double Elimination 1-8")
|
||||
end
|
||||
|
||||
test "Match generation works for 64‐slot bracket" do
|
||||
assert @tournament.matches.count == 126
|
||||
|
||||
# Winners‐bracket
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "Bracket Round of 64" }.count == 32
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "Bracket Round of 32" }.count == 16
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "Bracket Round of 16" }.count == 8
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "Quarter" }.count == 4
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "Semis" }.count == 2
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "1/2" }.count == 1
|
||||
|
||||
# Losers‐bracket
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "Conso Round of 32.1" }.count == 16
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "Conso Round of 32.2" }.count == 16
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "Conso Round of 16.1" }.count == 8
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "Conso Round of 16.2" }.count == 8
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "Conso Round of 8.1" }.count == 4
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "Conso Round of 8.2" }.count == 4
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "Conso Quarter" }.count == 2
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "Conso Semis" }.count == 2
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "3/4" }.count == 1
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "5/6" }.count == 1
|
||||
assert @tournament.matches.select { |m| m.bracket_position == "7/8" }.count == 1
|
||||
end
|
||||
|
||||
test "Seeded wrestlers have correct first line in Round of 64" do
|
||||
@tournament.matches.reload
|
||||
|
||||
# Collect the 32 "Bracket Round of 64" matches in bracket_position_number order
|
||||
matches_r64 = (1..32).map do |i|
|
||||
@tournament.matches.find { |m|
|
||||
m.bracket_position == "Bracket Round of 64" &&
|
||||
m.bracket_position_number == i
|
||||
}
|
||||
end
|
||||
|
||||
# Match 1 - seed 1 vs seed 64 (BYE)
|
||||
assert matches_r64[0].wrestler1.bracket_line == 1
|
||||
assert matches_r64[0].loser2_name == "BYE"
|
||||
|
||||
# Match 2 - seed 32 vs seed 33
|
||||
assert matches_r64[1].wrestler1.bracket_line == 32
|
||||
assert matches_r64[1].wrestler2.bracket_line == 33
|
||||
|
||||
# Match 3 - seed 17 vs seed 48
|
||||
assert matches_r64[2].wrestler1.bracket_line == 17
|
||||
assert matches_r64[2].wrestler2.bracket_line == 48
|
||||
|
||||
# Match 4 - seed 16 vs seed 49
|
||||
assert matches_r64[3].wrestler1.bracket_line == 16
|
||||
assert matches_r64[3].wrestler2.bracket_line == 49
|
||||
|
||||
# Match 5 - seed 9 vs seed 56
|
||||
assert matches_r64[4].wrestler1.bracket_line == 9
|
||||
assert matches_r64[4].wrestler2.bracket_line == 56
|
||||
|
||||
# Match 6 - seed 24 vs seed 41
|
||||
assert matches_r64[5].wrestler1.bracket_line == 24
|
||||
assert matches_r64[5].wrestler2.bracket_line == 41
|
||||
|
||||
# Match 7 - seed 25 vs seed 40
|
||||
assert matches_r64[6].wrestler1.bracket_line == 25
|
||||
assert matches_r64[6].wrestler2.bracket_line == 40
|
||||
|
||||
# Match 8 - seed 8 vs seed 57
|
||||
assert matches_r64[7].wrestler1.bracket_line == 8
|
||||
assert matches_r64[7].wrestler2.bracket_line == 57
|
||||
|
||||
# Match 9 - seed 5 vs seed 60
|
||||
assert matches_r64[8].wrestler1.bracket_line == 5
|
||||
assert matches_r64[8].wrestler2.bracket_line == 60
|
||||
|
||||
# Match 10 - seed 28 vs seed 37
|
||||
assert matches_r64[9].wrestler1.bracket_line == 28
|
||||
assert matches_r64[9].wrestler2.bracket_line == 37
|
||||
|
||||
# Match 11 - seed 21 vs seed 44
|
||||
assert matches_r64[10].wrestler1.bracket_line == 21
|
||||
assert matches_r64[10].wrestler2.bracket_line == 44
|
||||
|
||||
# Match 12 - seed 12 vs seed 53
|
||||
assert matches_r64[11].wrestler1.bracket_line == 12
|
||||
assert matches_r64[11].wrestler2.bracket_line == 53
|
||||
|
||||
# Match 13 - seed 13 vs seed 52
|
||||
assert matches_r64[12].wrestler1.bracket_line == 13
|
||||
assert matches_r64[12].wrestler2.bracket_line == 52
|
||||
|
||||
# Match 14 - seed 20 vs seed 45
|
||||
assert matches_r64[13].wrestler1.bracket_line == 20
|
||||
assert matches_r64[13].wrestler2.bracket_line == 45
|
||||
|
||||
# Match 15 - seed 29 vs seed 36
|
||||
assert matches_r64[14].wrestler1.bracket_line == 29
|
||||
assert matches_r64[14].wrestler2.bracket_line == 36
|
||||
|
||||
# Match 16 - seed 4 vs seed 61
|
||||
assert matches_r64[15].wrestler1.bracket_line == 4
|
||||
assert matches_r64[15].wrestler2.bracket_line == 61
|
||||
|
||||
# Match 17 - seed 3 vs seed 62
|
||||
assert matches_r64[16].wrestler1.bracket_line == 3
|
||||
assert matches_r64[16].wrestler2.bracket_line == 62
|
||||
|
||||
# Match 18 - seed 30 vs seed 35
|
||||
assert matches_r64[17].wrestler1.bracket_line == 30
|
||||
assert matches_r64[17].wrestler2.bracket_line == 35
|
||||
|
||||
# Match 19 - seed 19 vs seed 46
|
||||
assert matches_r64[18].wrestler1.bracket_line == 19
|
||||
assert matches_r64[18].wrestler2.bracket_line == 46
|
||||
|
||||
# Match 20 - seed 14 vs seed 51
|
||||
assert matches_r64[19].wrestler1.bracket_line == 14
|
||||
assert matches_r64[19].wrestler2.bracket_line == 51
|
||||
|
||||
# Match 21 - seed 11 vs seed 54
|
||||
assert matches_r64[20].wrestler1.bracket_line == 11
|
||||
assert matches_r64[20].wrestler2.bracket_line == 54
|
||||
|
||||
# Match 22 - seed 22 vs seed 43
|
||||
assert matches_r64[21].wrestler1.bracket_line == 22
|
||||
assert matches_r64[21].wrestler2.bracket_line == 43
|
||||
|
||||
# Match 23 - seed 27 vs seed 38
|
||||
assert matches_r64[22].wrestler1.bracket_line == 27
|
||||
assert matches_r64[22].wrestler2.bracket_line == 38
|
||||
|
||||
# Match 24 - seed 6 vs seed 59
|
||||
assert matches_r64[23].wrestler1.bracket_line == 6
|
||||
assert matches_r64[23].wrestler2.bracket_line == 59
|
||||
|
||||
# Match 25 - seed 7 vs seed 58
|
||||
assert matches_r64[24].wrestler1.bracket_line == 7
|
||||
assert matches_r64[24].wrestler2.bracket_line == 58
|
||||
|
||||
# Match 26 - seed 26 vs seed 39
|
||||
assert matches_r64[25].wrestler1.bracket_line == 26
|
||||
assert matches_r64[25].wrestler2.bracket_line == 39
|
||||
|
||||
# Match 27 - seed 23 vs seed 42
|
||||
assert matches_r64[26].wrestler1.bracket_line == 23
|
||||
assert matches_r64[26].wrestler2.bracket_line == 42
|
||||
|
||||
# Match 28 - seed 10 vs seed 55
|
||||
assert matches_r64[27].wrestler1.bracket_line == 10
|
||||
assert matches_r64[27].wrestler2.bracket_line == 55
|
||||
|
||||
# Match 29 - seed 15 vs seed 50
|
||||
assert matches_r64[28].wrestler1.bracket_line == 15
|
||||
assert matches_r64[28].wrestler2.bracket_line == 50
|
||||
|
||||
# Match 30 - seed 18 vs seed 47
|
||||
assert matches_r64[29].wrestler1.bracket_line == 18
|
||||
assert matches_r64[29].wrestler2.bracket_line == 47
|
||||
|
||||
# Match 31 - seed 31 vs seed 34
|
||||
assert matches_r64[30].wrestler1.bracket_line == 31
|
||||
assert matches_r64[30].wrestler2.bracket_line == 34
|
||||
|
||||
# Match 32 - seed 2 vs seed 63 (BYE)
|
||||
assert matches_r64[31].wrestler1.bracket_line == 2
|
||||
assert matches_r64[31].loser2_name == "BYE"
|
||||
end
|
||||
|
||||
test "Byes are advanced correctly into Round of 32" do
|
||||
@tournament.matches.reload
|
||||
|
||||
# Round of 32, match 1: seed 1 (bye) should be advanced
|
||||
match_r32_1 = @tournament.matches.find { |m|
|
||||
m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 1
|
||||
}
|
||||
assert match_r32_1.wrestler1.name == "Test1"
|
||||
|
||||
# Round of 32, match 15: seed 2 (bye) should land in slot 2 of match 15
|
||||
match_r32_15 = @tournament.matches.find { |m|
|
||||
m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 16
|
||||
}
|
||||
assert match_r32_15.wrestler2.name == "Test2"
|
||||
end
|
||||
|
||||
test "Loser names set up correctly" do
|
||||
@tournament.matches.reload
|
||||
|
||||
# Round of 64 matches
|
||||
match1 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 1 }
|
||||
match2 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 2 }
|
||||
match3 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 3 }
|
||||
match4 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 4 }
|
||||
match5 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 5 }
|
||||
match6 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 6 }
|
||||
match7 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 7 }
|
||||
match8 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 8 }
|
||||
match9 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 9 }
|
||||
match10 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 10 }
|
||||
match11 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 11 }
|
||||
match12 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 12 }
|
||||
match13 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 13 }
|
||||
match14 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 14 }
|
||||
match15 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 15 }
|
||||
match16 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 16 }
|
||||
match17 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 17 }
|
||||
match18 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 18 }
|
||||
match19 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 19 }
|
||||
match20 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 20 }
|
||||
match21 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 21 }
|
||||
match22 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 22 }
|
||||
match23 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 23 }
|
||||
match24 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 24 }
|
||||
match25 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 25 }
|
||||
match26 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 26 }
|
||||
match27 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 27 }
|
||||
match28 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 28 }
|
||||
match29 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 29 }
|
||||
match30 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 30 }
|
||||
match31 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 31 }
|
||||
match32 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 64" && m.bracket_position_number == 32 }
|
||||
|
||||
# Conso Round of 32.1
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 1 }.loser1_name == "BYE"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 1 }.loser2_name == "Loser of #{match2.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 2 }.loser1_name == "Loser of #{match3.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 2 }.loser2_name == "Loser of #{match4.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 3 }.loser1_name == "Loser of #{match5.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 3 }.loser2_name == "Loser of #{match6.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 4 }.loser1_name == "Loser of #{match7.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 4 }.loser2_name == "Loser of #{match8.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 5 }.loser1_name == "Loser of #{match9.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 5 }.loser2_name == "Loser of #{match10.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 6 }.loser1_name == "Loser of #{match11.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 6 }.loser2_name == "Loser of #{match12.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 7 }.loser1_name == "Loser of #{match13.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 7 }.loser2_name == "Loser of #{match14.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 8 }.loser1_name == "Loser of #{match15.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 8 }.loser2_name == "Loser of #{match16.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 9 }.loser1_name == "Loser of #{match17.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 9 }.loser2_name == "Loser of #{match18.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 10 }.loser1_name == "Loser of #{match19.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 10 }.loser2_name == "Loser of #{match20.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 11 }.loser1_name == "Loser of #{match21.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 11 }.loser2_name == "Loser of #{match22.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 12 }.loser1_name == "Loser of #{match23.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 12 }.loser2_name == "Loser of #{match24.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 13 }.loser1_name == "Loser of #{match25.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 13 }.loser2_name == "Loser of #{match26.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 14 }.loser1_name == "Loser of #{match27.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 14 }.loser2_name == "Loser of #{match28.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 15 }.loser1_name == "Loser of #{match29.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 15 }.loser2_name == "Loser of #{match30.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 16 }.loser1_name == "Loser of #{match31.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.1" && m.bracket_position_number == 16 }.loser2_name == "BYE"
|
||||
|
||||
# Conso Round of 32.2
|
||||
r32_match1 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 1 }
|
||||
r32_match2 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 2 }
|
||||
r32_match3 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 3 }
|
||||
r32_match4 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 4 }
|
||||
r32_match5 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 5 }
|
||||
r32_match6 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 6 }
|
||||
r32_match7 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 7 }
|
||||
r32_match8 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 8 }
|
||||
r32_match9 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 9 }
|
||||
r32_match10 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 10 }
|
||||
r32_match11 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 11 }
|
||||
r32_match12 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 12 }
|
||||
r32_match13 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 13 }
|
||||
r32_match14 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 14 }
|
||||
r32_match15 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 15 }
|
||||
r32_match16 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 32" && m.bracket_position_number == 16 }
|
||||
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.2" && m.bracket_position_number == 1 }.loser1_name == "Loser of #{r32_match16.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.2" && m.bracket_position_number == 2 }.loser1_name == "Loser of #{r32_match15.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.2" && m.bracket_position_number == 3 }.loser1_name == "Loser of #{r32_match14.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.2" && m.bracket_position_number == 4 }.loser1_name == "Loser of #{r32_match13.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.2" && m.bracket_position_number == 5 }.loser1_name == "Loser of #{r32_match12.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.2" && m.bracket_position_number == 6 }.loser1_name == "Loser of #{r32_match11.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.2" && m.bracket_position_number == 7 }.loser1_name == "Loser of #{r32_match10.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.2" && m.bracket_position_number == 8 }.loser1_name == "Loser of #{r32_match9.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.2" && m.bracket_position_number == 9 }.loser1_name == "Loser of #{r32_match8.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.2" && m.bracket_position_number == 10 }.loser1_name == "Loser of #{r32_match7.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.2" && m.bracket_position_number == 11 }.loser1_name == "Loser of #{r32_match6.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.2" && m.bracket_position_number == 12 }.loser1_name == "Loser of #{r32_match5.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.2" && m.bracket_position_number == 13 }.loser1_name == "Loser of #{r32_match4.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.2" && m.bracket_position_number == 14 }.loser1_name == "Loser of #{r32_match3.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.2" && m.bracket_position_number == 15 }.loser1_name == "Loser of #{r32_match2.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 32.2" && m.bracket_position_number == 16 }.loser1_name == "Loser of #{r32_match1.bout_number}"
|
||||
|
||||
# Conso Round of 16.2
|
||||
r16_match1 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 16" && m.bracket_position_number == 1 }
|
||||
r16_match2 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 16" && m.bracket_position_number == 2 }
|
||||
r16_match3 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 16" && m.bracket_position_number == 3 }
|
||||
r16_match4 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 16" && m.bracket_position_number == 4 }
|
||||
r16_match5 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 16" && m.bracket_position_number == 5 }
|
||||
r16_match6 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 16" && m.bracket_position_number == 6 }
|
||||
r16_match7 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 16" && m.bracket_position_number == 7 }
|
||||
r16_match8 = @tournament.matches.find { |m| m.bracket_position == "Bracket Round of 16" && m.bracket_position_number == 8 }
|
||||
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 16.2" && m.bracket_position_number == 1 }.loser1_name == "Loser of #{r16_match1.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 16.2" && m.bracket_position_number == 2 }.loser1_name == "Loser of #{r16_match2.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 16.2" && m.bracket_position_number == 3 }.loser1_name == "Loser of #{r16_match3.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 16.2" && m.bracket_position_number == 4 }.loser1_name == "Loser of #{r16_match4.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 16.2" && m.bracket_position_number == 5 }.loser1_name == "Loser of #{r16_match5.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 16.2" && m.bracket_position_number == 6 }.loser1_name == "Loser of #{r16_match6.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 16.2" && m.bracket_position_number == 7 }.loser1_name == "Loser of #{r16_match7.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 16.2" && m.bracket_position_number == 8 }.loser1_name == "Loser of #{r16_match8.bout_number}"
|
||||
|
||||
# Conso Round of 8.2
|
||||
quarter1 = @tournament.matches.find { |m| m.bracket_position == "Quarter" && m.bracket_position_number == 1 }
|
||||
quarter2 = @tournament.matches.find { |m| m.bracket_position == "Quarter" && m.bracket_position_number == 2 }
|
||||
quarter3 = @tournament.matches.find { |m| m.bracket_position == "Quarter" && m.bracket_position_number == 3 }
|
||||
quarter4 = @tournament.matches.find { |m| m.bracket_position == "Quarter" && m.bracket_position_number == 4 }
|
||||
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 8.2" && m.bracket_position_number == 1 }.loser1_name == "Loser of #{quarter4.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 8.2" && m.bracket_position_number == 2 }.loser1_name == "Loser of #{quarter3.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 8.2" && m.bracket_position_number == 3 }.loser1_name == "Loser of #{quarter2.bout_number}"
|
||||
assert @tournament.matches.find { |m| m.bracket_position == "Conso Round of 8.2" && m.bracket_position_number == 4 }.loser1_name == "Loser of #{quarter1.bout_number}"
|
||||
|
||||
# Conso Semis
|
||||
semis1 = @tournament.matches.find { |m| m.bracket_position == "Semis" && m.bracket_position_number == 1 }
|
||||
semis2 = @tournament.matches.find { |m| m.bracket_position == "Semis" && m.bracket_position_number == 2 }
|
||||
conso_s1 = @tournament.matches.find { |m| m.bracket_position == "Conso Semis" && m.bracket_position_number == 1 }
|
||||
conso_s2 = @tournament.matches.find { |m| m.bracket_position == "Conso Semis" && m.bracket_position_number == 2 }
|
||||
|
||||
assert conso_s1.loser1_name == "Loser of #{semis1.bout_number}"
|
||||
assert conso_s2.loser1_name == "Loser of #{semis2.bout_number}"
|
||||
|
||||
# 5/6
|
||||
match_5_6 = @tournament.matches.find { |m| m.bracket_position == "5/6" && m.bracket_position_number == 1 }
|
||||
assert match_5_6.loser1_name == "Loser of #{conso_s1.bout_number}"
|
||||
assert match_5_6.loser2_name == "Loser of #{conso_s2.bout_number}"
|
||||
|
||||
# 7/8
|
||||
cq1 = @tournament.matches.find { |m| m.bracket_position == "Conso Quarter" && m.bracket_position_number == 1 }
|
||||
cq2 = @tournament.matches.find { |m| m.bracket_position == "Conso Quarter" && m.bracket_position_number == 2 }
|
||||
match_7_8 = @tournament.matches.find { |m| m.bracket_position == "7/8" && m.bracket_position_number == 1 }
|
||||
|
||||
assert match_7_8.loser1_name == "Loser of #{cq1.bout_number}"
|
||||
assert match_7_8.loser2_name == "Loser of #{cq2.bout_number}"
|
||||
end
|
||||
|
||||
test "Placement points are given when moving through bracket" do
|
||||
match_semis = @tournament.matches.find { |m|
|
||||
m.bracket_position == "Semis" && m.bracket_position_number == 1
|
||||
}
|
||||
wrestler_a = get_wrestler_by_name("Test1")
|
||||
match_semis.w1 = wrestler_a.id
|
||||
match_semis.save
|
||||
|
||||
match_conso_semi = @tournament.matches.find { |m|
|
||||
m.bracket_position == "Conso Semis" && m.bracket_position_number == 1
|
||||
}
|
||||
wrestler_b = get_wrestler_by_name("Test2")
|
||||
match_conso_semi.w1 = wrestler_b.id
|
||||
match_conso_semi.save
|
||||
|
||||
match_conso_q = @tournament.matches.find { |m|
|
||||
m.bracket_position == "Conso Quarter" && m.bracket_position_number == 1
|
||||
}
|
||||
wrestler_c = get_wrestler_by_name("Test3")
|
||||
match_conso_q.w1 = wrestler_c.id
|
||||
match_conso_q.save
|
||||
|
||||
assert wrestler_a.reload.placement_points == 3
|
||||
assert wrestler_b.reload.placement_points == 3
|
||||
assert wrestler_c.reload.placement_points == 1
|
||||
end
|
||||
|
||||
# test "Run through all matches works" do
|
||||
# @tournament.matches.sort_by(&:bout_number).each do |match|
|
||||
# match.reload
|
||||
# if match.finished != 1 && match.w1 && match.w2
|
||||
# match.winner_id = match.w1
|
||||
# match.win_type = "Decision"
|
||||
# match.score = "0-0"
|
||||
# match.finished = 1
|
||||
# match.save
|
||||
# end
|
||||
# end
|
||||
|
||||
# assert @tournament.matches.reload.none? { |m| m.finished == 0 }
|
||||
# end
|
||||
|
||||
# test "test output" do
|
||||
# matches_r64 = (1..32).map do |i|
|
||||
# @tournament.matches.find { |m|
|
||||
# m.bracket_position == "Bracket Round of 64" &&
|
||||
# m.bracket_position_number == i
|
||||
# }
|
||||
# end
|
||||
# matches_r64.sort_by{|m| m.bracket_position_number}.each do |match|
|
||||
# string = ""
|
||||
# if match.wrestler1
|
||||
# string += "#{match.wrestler1.bracket_line}"
|
||||
# end
|
||||
# string += " vs "
|
||||
# if match.wrestler2
|
||||
# string += "#{match.wrestler2.bracket_line}"
|
||||
# end
|
||||
# puts string
|
||||
# end
|
||||
# end
|
||||
end
|
||||
@@ -0,0 +1,377 @@
|
||||
require 'test_helper'
|
||||
|
||||
class DoubleEliminationSixtyFourManEightPlacesRunThrough < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
end
|
||||
|
||||
def winner_by_name(winner_name,match)
|
||||
wrestler = @tournament.weights.first.wrestlers.select{|w| w.name == winner_name}.first
|
||||
match.winner_id = wrestler.id
|
||||
match.finished = 1
|
||||
match.win_type = "Decision"
|
||||
match.score = "1-0"
|
||||
match.save
|
||||
end
|
||||
|
||||
test "64 man double elimination place 1-8" do
|
||||
create_double_elim_tournament_single_weight(62, "Regular Double Elimination 1-8")
|
||||
matches = @tournament.matches.reload
|
||||
# BYEs are automatically advanced
|
||||
bracket_r64 = matches.reload.select { |m| m.bracket_position == "Bracket Round of 64" }.sort_by(&:bracket_position_number)
|
||||
# winner_by_name("Test1", bracket_r64.select{|m| m.bracket_position_number == 1}.first) # seed 1 vs 64 (BYE)
|
||||
winner_by_name("Test32", bracket_r64.select{|m| m.bracket_position_number == 2}.first) # seed 32 vs seed 33
|
||||
winner_by_name("Test17", bracket_r64.select{|m| m.bracket_position_number == 3}.first) # seed 17 vs seed 48
|
||||
winner_by_name("Test49", bracket_r64.select{|m| m.bracket_position_number == 4}.first) # seed 16 vs seed 49
|
||||
winner_by_name("Test9", bracket_r64.select{|m| m.bracket_position_number == 5}.first) # seed 9 vs seed 56
|
||||
winner_by_name("Test24", bracket_r64.select{|m| m.bracket_position_number == 6}.first) # seed 24 vs seed 41
|
||||
winner_by_name("Test25", bracket_r64.select{|m| m.bracket_position_number == 7}.first) # seed 25 vs seed 40
|
||||
winner_by_name("Test8", bracket_r64.select{|m| m.bracket_position_number == 8}.first) # seed 8 vs seed 57
|
||||
winner_by_name("Test5", bracket_r64.select{|m| m.bracket_position_number == 9}.first) # seed 5 vs seed 60
|
||||
winner_by_name("Test37", bracket_r64.select{|m| m.bracket_position_number == 10}.first) # seed 28 vs seed 37
|
||||
winner_by_name("Test21", bracket_r64.select{|m| m.bracket_position_number == 11}.first) # seed 21 vs seed 44
|
||||
winner_by_name("Test12", bracket_r64.select{|m| m.bracket_position_number == 12}.first) # seed 12 vs seed 53
|
||||
winner_by_name("Test13", bracket_r64.select{|m| m.bracket_position_number == 13}.first) # seed 13 vs seed 52
|
||||
winner_by_name("Test20", bracket_r64.select{|m| m.bracket_position_number == 14}.first) # seed 20 vs 45
|
||||
winner_by_name("Test29", bracket_r64.select{|m| m.bracket_position_number == 15}.first) # seed 29 vs 36
|
||||
winner_by_name("Test4", bracket_r64.select{|m| m.bracket_position_number == 16}.first) # seed 4 vs 61
|
||||
winner_by_name("Test3", bracket_r64.select{|m| m.bracket_position_number == 17}.first) # seed 3 vs 62
|
||||
winner_by_name("Test30", bracket_r64.select{|m| m.bracket_position_number == 18}.first) # seed 30 vs 35
|
||||
winner_by_name("Test19", bracket_r64.select{|m| m.bracket_position_number == 19}.first) # seed 19 vs 46
|
||||
winner_by_name("Test14", bracket_r64.select{|m| m.bracket_position_number == 20}.first) # seed 14 vs 51
|
||||
winner_by_name("Test11", bracket_r64.select{|m| m.bracket_position_number == 21}.first) # seed 11 vs 54
|
||||
winner_by_name("Test22", bracket_r64.select{|m| m.bracket_position_number == 22}.first) # seed 22 vs 43
|
||||
winner_by_name("Test27", bracket_r64.select{|m| m.bracket_position_number == 23}.first) # seed 27 vs 38
|
||||
winner_by_name("Test6", bracket_r64.select{|m| m.bracket_position_number == 24}.first) # seed 6 vs 59
|
||||
winner_by_name("Test7", bracket_r64.select{|m| m.bracket_position_number == 25}.first) # seed 7 vs 58
|
||||
winner_by_name("Test26", bracket_r64.select{|m| m.bracket_position_number == 26}.first) # seed 26 vs 39
|
||||
winner_by_name("Test23", bracket_r64.select{|m| m.bracket_position_number == 27}.first) # seed 23 vs 42
|
||||
winner_by_name("Test10", bracket_r64.select{|m| m.bracket_position_number == 28}.first) # seed 10 vs 55
|
||||
winner_by_name("Test15", bracket_r64.select{|m| m.bracket_position_number == 29}.first) # seed 15 vs 50
|
||||
winner_by_name("Test18", bracket_r64.select{|m| m.bracket_position_number == 30}.first) # seed 18 vs 47
|
||||
winner_by_name("Test31", bracket_r64.select{|m| m.bracket_position_number == 31}.first) # seed 31 vs 34
|
||||
# BYE's auto move
|
||||
# winner_by_name("Test2", bracket_r64.select{|m| m.bracket_position_number == 32}.first) # seed 2 vs seed 63 (BYE)
|
||||
|
||||
bracket_r32 = matches.select{|m| m.bracket_position == "Bracket Round of 32"}
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 1}.first.reload.wrestler1.name == "Test1"
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 1}.first.reload.wrestler2.name == "Test32"
|
||||
winner_by_name("Test1", bracket_r32.select{|m| m.bracket_position_number == 1}.first)
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 2}.first.reload.wrestler1.name == "Test17"
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 2}.first.reload.wrestler2.name == "Test49"
|
||||
winner_by_name("Test17", bracket_r32.select{|m| m.bracket_position_number == 2}.first)
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 3}.first.reload.wrestler1.name == "Test9"
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 3}.first.reload.wrestler2.name == "Test24"
|
||||
winner_by_name("Test24", bracket_r32.select{|m| m.bracket_position_number == 3}.first)
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 4}.first.reload.wrestler1.name == "Test25"
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 4}.first.reload.wrestler2.name == "Test8"
|
||||
winner_by_name("Test8", bracket_r32.select{|m| m.bracket_position_number == 4}.first)
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 5}.first.reload.wrestler1.name == "Test5"
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 5}.first.reload.wrestler2.name == "Test37"
|
||||
winner_by_name("Test5", bracket_r32.select{|m| m.bracket_position_number == 5}.first)
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 6}.first.reload.wrestler1.name == "Test21"
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 6}.first.reload.wrestler2.name == "Test12"
|
||||
winner_by_name("Test21", bracket_r32.select{|m| m.bracket_position_number == 6}.first)
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 7}.first.reload.wrestler1.name == "Test13"
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 7}.first.reload.wrestler2.name == "Test20"
|
||||
winner_by_name("Test13", bracket_r32.select{|m| m.bracket_position_number == 7}.first)
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 8}.first.reload.wrestler1.name == "Test29"
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 8}.first.reload.wrestler2.name == "Test4"
|
||||
winner_by_name("Test4", bracket_r32.select{|m| m.bracket_position_number == 8}.first)
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 9}.first.reload.wrestler1.name == "Test3"
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 9}.first.reload.wrestler2.name == "Test30"
|
||||
winner_by_name("Test3", bracket_r32.select{|m| m.bracket_position_number == 9}.first)
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 10}.first.reload.wrestler1.name == "Test19"
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 10}.first.reload.wrestler2.name == "Test14"
|
||||
winner_by_name("Test19", bracket_r32.select{|m| m.bracket_position_number == 10}.first)
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 11}.first.reload.wrestler1.name == "Test11"
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 11}.first.reload.wrestler2.name == "Test22"
|
||||
winner_by_name("Test11", bracket_r32.select{|m| m.bracket_position_number == 11}.first)
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 12}.first.reload.wrestler1.name == "Test27"
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 12}.first.reload.wrestler2.name == "Test6"
|
||||
winner_by_name("Test27", bracket_r32.select{|m| m.bracket_position_number == 12}.first)
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 13}.first.reload.wrestler1.name == "Test7"
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 13}.first.reload.wrestler2.name == "Test26"
|
||||
winner_by_name("Test7", bracket_r32.select{|m| m.bracket_position_number == 13}.first)
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 14}.first.reload.wrestler1.name == "Test23"
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 14}.first.reload.wrestler2.name == "Test10"
|
||||
winner_by_name("Test23", bracket_r32.select{|m| m.bracket_position_number == 14}.first)
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 15}.first.reload.wrestler1.name == "Test15"
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 15}.first.reload.wrestler2.name == "Test18"
|
||||
winner_by_name("Test15", bracket_r32.select{|m| m.bracket_position_number == 15}.first)
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 16}.first.reload.wrestler1.name == "Test31"
|
||||
assert bracket_r32.select{|m| m.bracket_position_number == 16}.first.reload.wrestler2.name == "Test2"
|
||||
winner_by_name("Test2", bracket_r32.select{|m| m.bracket_position_number == 16}.first)
|
||||
|
||||
conso_r32_1 = matches.reload.select { |m| m.bracket_position == "Conso Round of 32.1" }.sort_by(&:bracket_position_number)
|
||||
assert conso_r32_1[0].loser1_name == "BYE"
|
||||
assert conso_r32_1[0].wrestler2.name == "Test33"
|
||||
# BYE's auto move
|
||||
assert conso_r32_1[1].wrestler1.name == "Test48"
|
||||
assert conso_r32_1[1].wrestler2.name == "Test16"
|
||||
winner_by_name("Test16", conso_r32_1[1])
|
||||
assert conso_r32_1[2].wrestler1.name == "Test56"
|
||||
assert conso_r32_1[2].wrestler2.name == "Test41"
|
||||
winner_by_name("Test56", conso_r32_1[2])
|
||||
assert conso_r32_1[3].wrestler1.name == "Test40"
|
||||
assert conso_r32_1[3].wrestler2.name == "Test57"
|
||||
winner_by_name("Test57", conso_r32_1[3])
|
||||
assert conso_r32_1[4].wrestler1.name == "Test60"
|
||||
assert conso_r32_1[4].wrestler2.name == "Test28"
|
||||
winner_by_name("Test28", conso_r32_1[4])
|
||||
assert conso_r32_1[5].wrestler1.name == "Test44"
|
||||
assert conso_r32_1[5].wrestler2.name == "Test53"
|
||||
winner_by_name("Test53", conso_r32_1[5])
|
||||
assert conso_r32_1[6].wrestler1.name == "Test52"
|
||||
assert conso_r32_1[6].wrestler2.name == "Test45"
|
||||
winner_by_name("Test45", conso_r32_1[6])
|
||||
assert conso_r32_1[7].wrestler1.name == "Test36"
|
||||
assert conso_r32_1[7].wrestler2.name == "Test61"
|
||||
winner_by_name("Test61", conso_r32_1[7])
|
||||
assert conso_r32_1[8].wrestler1.name == "Test62"
|
||||
assert conso_r32_1[8].wrestler2.name == "Test35"
|
||||
winner_by_name("Test35", conso_r32_1[8])
|
||||
assert conso_r32_1[9].wrestler1.name == "Test46"
|
||||
assert conso_r32_1[9].wrestler2.name == "Test51"
|
||||
winner_by_name("Test51", conso_r32_1[9])
|
||||
assert conso_r32_1[10].wrestler1.name == "Test54"
|
||||
assert conso_r32_1[10].wrestler2.name == "Test43"
|
||||
winner_by_name("Test43", conso_r32_1[10])
|
||||
assert conso_r32_1[11].wrestler1.name == "Test38"
|
||||
assert conso_r32_1[11].wrestler2.name == "Test59"
|
||||
winner_by_name("Test59", conso_r32_1[11])
|
||||
assert conso_r32_1[12].wrestler1.name == "Test58"
|
||||
assert conso_r32_1[12].wrestler2.name == "Test39"
|
||||
winner_by_name("Test39", conso_r32_1[12])
|
||||
assert conso_r32_1[13].wrestler1.name == "Test42"
|
||||
assert conso_r32_1[13].wrestler2.name == "Test55"
|
||||
winner_by_name("Test55", conso_r32_1[13])
|
||||
assert conso_r32_1[14].wrestler1.name == "Test50"
|
||||
assert conso_r32_1[14].wrestler2.name == "Test47"
|
||||
winner_by_name("Test47", conso_r32_1[14])
|
||||
assert conso_r32_1[15].wrestler1.name == "Test34"
|
||||
assert conso_r32_1[15].loser2_name == "BYE"
|
||||
# Auto BYE
|
||||
|
||||
conso_r32_2 = matches.reload.select { |m| m.bracket_position == "Conso Round of 32.2" }.sort_by(&:bracket_position_number)
|
||||
assert conso_r32_2[0].wrestler1.name == "Test31"
|
||||
assert conso_r32_2[0].wrestler2.name == "Test33"
|
||||
winner_by_name("Test31", conso_r32_2[0])
|
||||
assert conso_r32_2[1].wrestler1.name == "Test18"
|
||||
assert conso_r32_2[1].wrestler2.name == "Test16"
|
||||
winner_by_name("Test16", conso_r32_2[1])
|
||||
assert conso_r32_2[2].wrestler1.name == "Test10"
|
||||
assert conso_r32_2[2].wrestler2.name == "Test56"
|
||||
winner_by_name("Test10", conso_r32_2[2])
|
||||
assert conso_r32_2[3].wrestler1.name == "Test26"
|
||||
assert conso_r32_2[3].wrestler2.name == "Test57"
|
||||
winner_by_name("Test26", conso_r32_2[3])
|
||||
assert conso_r32_2[4].wrestler1.name == "Test6"
|
||||
assert conso_r32_2[4].wrestler2.name == "Test28"
|
||||
winner_by_name("Test6", conso_r32_2[4])
|
||||
assert conso_r32_2[5].wrestler1.name == "Test22"
|
||||
assert conso_r32_2[5].wrestler2.name == "Test53"
|
||||
winner_by_name("Test22", conso_r32_2[5])
|
||||
assert conso_r32_2[6].wrestler1.name == "Test14"
|
||||
assert conso_r32_2[6].wrestler2.name == "Test45"
|
||||
winner_by_name("Test45", conso_r32_2[6])
|
||||
assert conso_r32_2[7].wrestler1.name == "Test30"
|
||||
assert conso_r32_2[7].wrestler2.name == "Test61"
|
||||
winner_by_name("Test30", conso_r32_2[7])
|
||||
assert conso_r32_2[8].wrestler1.name == "Test29"
|
||||
assert conso_r32_2[8].wrestler2.name == "Test35"
|
||||
winner_by_name("Test35", conso_r32_2[8])
|
||||
assert conso_r32_2[9].wrestler1.name == "Test20"
|
||||
assert conso_r32_2[9].wrestler2.name == "Test51"
|
||||
winner_by_name("Test20", conso_r32_2[9])
|
||||
assert conso_r32_2[10].wrestler1.name == "Test12"
|
||||
assert conso_r32_2[10].wrestler2.name == "Test43"
|
||||
winner_by_name("Test43", conso_r32_2[10])
|
||||
assert conso_r32_2[11].wrestler1.name == "Test37"
|
||||
assert conso_r32_2[11].wrestler2.name == "Test59"
|
||||
winner_by_name("Test59", conso_r32_2[11])
|
||||
assert conso_r32_2[12].wrestler1.name == "Test25"
|
||||
assert conso_r32_2[12].wrestler2.name == "Test39"
|
||||
winner_by_name("Test25", conso_r32_2[12])
|
||||
assert conso_r32_2[13].wrestler1.name == "Test9"
|
||||
assert conso_r32_2[13].wrestler2.name == "Test55"
|
||||
winner_by_name("Test9", conso_r32_2[13])
|
||||
assert conso_r32_2[14].wrestler1.name == "Test49"
|
||||
assert conso_r32_2[14].wrestler2.name == "Test47"
|
||||
winner_by_name("Test47", conso_r32_2[14])
|
||||
assert conso_r32_2[15].wrestler1.name == "Test32"
|
||||
assert conso_r32_2[15].wrestler2.name == "Test34"
|
||||
winner_by_name("Test32", conso_r32_2[15])
|
||||
|
||||
bracket_r16 = matches.reload.select { |m| m.bracket_position == "Bracket Round of 16" }.sort_by(&:bracket_position_number)
|
||||
assert bracket_r16[0].wrestler1.name == "Test1"
|
||||
assert bracket_r16[0].wrestler2.name == "Test17"
|
||||
winner_by_name("Test1", bracket_r16[0])
|
||||
assert bracket_r16[1].wrestler1.name == "Test24"
|
||||
assert bracket_r16[1].wrestler2.name == "Test8"
|
||||
winner_by_name("Test8", bracket_r16[1])
|
||||
assert bracket_r16[2].wrestler1.name == "Test5"
|
||||
assert bracket_r16[2].wrestler2.name == "Test21"
|
||||
winner_by_name("Test5", bracket_r16[2])
|
||||
assert bracket_r16[3].wrestler1.name == "Test13"
|
||||
assert bracket_r16[3].wrestler2.name == "Test4"
|
||||
winner_by_name("Test4", bracket_r16[3])
|
||||
assert bracket_r16[4].wrestler1.name == "Test3"
|
||||
assert bracket_r16[4].wrestler2.name == "Test19"
|
||||
winner_by_name("Test3", bracket_r16[4])
|
||||
assert bracket_r16[5].wrestler1.name == "Test11"
|
||||
assert bracket_r16[5].wrestler2.name == "Test27"
|
||||
winner_by_name("Test27", bracket_r16[5])
|
||||
assert bracket_r16[6].wrestler1.name == "Test7"
|
||||
assert bracket_r16[6].wrestler2.name == "Test23"
|
||||
winner_by_name("Test23", bracket_r16[6])
|
||||
assert bracket_r16[7].wrestler1.name == "Test15"
|
||||
assert bracket_r16[7].wrestler2.name == "Test2"
|
||||
winner_by_name("Test2", bracket_r16[7])
|
||||
|
||||
quarters = matches.reload.select { |m| m.bracket_position == "Quarter" }.sort_by(&:bracket_position_number)
|
||||
assert_equal "Test1", quarters[0].reload.wrestler1.name
|
||||
assert_equal "Test8", quarters[0].reload.wrestler2.name
|
||||
assert_equal "Test5", quarters[1].reload.wrestler1.name
|
||||
assert_equal "Test4", quarters[1].reload.wrestler2.name
|
||||
assert_equal "Test3", quarters[2].reload.wrestler1.name
|
||||
assert_equal "Test27", quarters[2].reload.wrestler2.name
|
||||
assert_equal "Test23", quarters[3].reload.wrestler1.name
|
||||
assert_equal "Test2", quarters[3].reload.wrestler2.name
|
||||
winner_by_name("Test1", quarters[0])
|
||||
winner_by_name("Test5", quarters[1])
|
||||
winner_by_name("Test3", quarters[2])
|
||||
winner_by_name("Test2", quarters[3])
|
||||
|
||||
conso_r16_1 = matches.reload.select { |m| m.bracket_position == "Conso Round of 16.1" }.sort_by(&:bracket_position_number)
|
||||
assert_equal "Test31", conso_r16_1[0].reload.wrestler1.name
|
||||
assert_equal "Test16", conso_r16_1[0].reload.wrestler2.name
|
||||
assert_equal "Test10", conso_r16_1[1].reload.wrestler1.name
|
||||
assert_equal "Test26", conso_r16_1[1].reload.wrestler2.name
|
||||
assert_equal "Test6", conso_r16_1[2].reload.wrestler1.name
|
||||
assert_equal "Test22", conso_r16_1[2].reload.wrestler2.name
|
||||
assert_equal "Test45", conso_r16_1[3].reload.wrestler1.name
|
||||
assert_equal "Test30", conso_r16_1[3].reload.wrestler2.name
|
||||
assert_equal "Test35", conso_r16_1[4].reload.wrestler1.name
|
||||
assert_equal "Test20", conso_r16_1[4].reload.wrestler2.name
|
||||
assert_equal "Test43", conso_r16_1[5].reload.wrestler1.name
|
||||
assert_equal "Test59", conso_r16_1[5].reload.wrestler2.name
|
||||
assert_equal "Test25", conso_r16_1[6].reload.wrestler1.name
|
||||
assert_equal "Test9", conso_r16_1[6].reload.wrestler2.name
|
||||
assert_equal "Test47", conso_r16_1[7].reload.wrestler1.name
|
||||
assert_equal "Test32", conso_r16_1[7].reload.wrestler2.name
|
||||
winner_by_name("Test16", conso_r16_1[0])
|
||||
winner_by_name("Test10", conso_r16_1[1])
|
||||
winner_by_name("Test6", conso_r16_1[2])
|
||||
winner_by_name("Test30", conso_r16_1[3])
|
||||
winner_by_name("Test35", conso_r16_1[4])
|
||||
winner_by_name("Test43", conso_r16_1[5])
|
||||
winner_by_name("Test25", conso_r16_1[6])
|
||||
winner_by_name("Test32", conso_r16_1[7])
|
||||
|
||||
conso_r16_2 = matches.reload.select { |m| m.bracket_position == "Conso Round of 16.2" }.sort_by(&:bracket_position_number)
|
||||
assert_equal "Test17", conso_r16_2[0].reload.wrestler1.name
|
||||
assert_equal "Test16", conso_r16_2[0].reload.wrestler2.name
|
||||
assert_equal "Test24", conso_r16_2[1].reload.wrestler1.name
|
||||
assert_equal "Test10", conso_r16_2[1].reload.wrestler2.name
|
||||
assert_equal "Test21", conso_r16_2[2].reload.wrestler1.name
|
||||
assert_equal "Test6", conso_r16_2[2].reload.wrestler2.name
|
||||
assert_equal "Test13", conso_r16_2[3].reload.wrestler1.name
|
||||
assert_equal "Test30", conso_r16_2[3].reload.wrestler2.name
|
||||
assert_equal "Test19", conso_r16_2[4].reload.wrestler1.name
|
||||
assert_equal "Test35", conso_r16_2[4].reload.wrestler2.name
|
||||
assert_equal "Test11", conso_r16_2[5].reload.wrestler1.name
|
||||
assert_equal "Test43", conso_r16_2[5].reload.wrestler2.name
|
||||
assert_equal "Test7", conso_r16_2[6].reload.wrestler1.name
|
||||
assert_equal "Test25", conso_r16_2[6].reload.wrestler2.name
|
||||
assert_equal "Test15", conso_r16_2[7].reload.wrestler1.name
|
||||
assert_equal "Test32", conso_r16_2[7].reload.wrestler2.name
|
||||
winner_by_name("Test16", conso_r16_2[0])
|
||||
winner_by_name("Test10", conso_r16_2[1])
|
||||
winner_by_name("Test6", conso_r16_2[2])
|
||||
winner_by_name("Test30", conso_r16_2[3])
|
||||
winner_by_name("Test35", conso_r16_2[4])
|
||||
winner_by_name("Test43", conso_r16_2[5])
|
||||
winner_by_name("Test25", conso_r16_2[6])
|
||||
winner_by_name("Test32", conso_r16_2[7])
|
||||
|
||||
conso_r8_1 = matches.reload.select { |m| m.bracket_position == "Conso Round of 8.1" }.sort_by(&:bracket_position_number)
|
||||
assert_equal "Test16", conso_r8_1[0].reload.wrestler1.name
|
||||
assert_equal "Test10", conso_r8_1[0].reload.wrestler2.name
|
||||
assert_equal "Test6", conso_r8_1[1].reload.wrestler1.name
|
||||
assert_equal "Test30", conso_r8_1[1].reload.wrestler2.name
|
||||
assert_equal "Test35", conso_r8_1[2].reload.wrestler1.name
|
||||
assert_equal "Test43", conso_r8_1[2].reload.wrestler2.name
|
||||
assert_equal "Test25", conso_r8_1[3].reload.wrestler1.name
|
||||
assert_equal "Test32", conso_r8_1[3].reload.wrestler2.name
|
||||
winner_by_name("Test16", conso_r8_1[0])
|
||||
winner_by_name("Test6", conso_r8_1[1])
|
||||
winner_by_name("Test35", conso_r8_1[2])
|
||||
winner_by_name("Test25", conso_r8_1[3])
|
||||
|
||||
conso_r8_2 = matches.reload.select { |m| m.bracket_position == "Conso Round of 8.2" }.sort_by(&:bracket_position_number)
|
||||
assert_equal "Test23", conso_r8_2[0].reload.wrestler1.name
|
||||
assert_equal "Test16", conso_r8_2[0].reload.wrestler2.name
|
||||
assert_equal "Test27", conso_r8_2[1].reload.wrestler1.name
|
||||
assert_equal "Test6", conso_r8_2[1].reload.wrestler2.name
|
||||
assert_equal "Test4", conso_r8_2[2].reload.wrestler1.name
|
||||
assert_equal "Test35", conso_r8_2[2].reload.wrestler2.name
|
||||
assert_equal "Test8", conso_r8_2[3].reload.wrestler1.name
|
||||
assert_equal "Test25", conso_r8_2[3].reload.wrestler2.name
|
||||
winner_by_name("Test16", conso_r8_2[0])
|
||||
winner_by_name("Test6", conso_r8_2[1])
|
||||
winner_by_name("Test35", conso_r8_2[2])
|
||||
winner_by_name("Test25", conso_r8_2[3])
|
||||
|
||||
conso_quarters = matches.reload.select { |m| m.bracket_position == "Conso Quarter" }.sort_by(&:bracket_position_number)
|
||||
assert conso_quarters.select { |m| m.bracket_position_number == 1 }.first.reload.wrestler1.name == "Test16"
|
||||
assert conso_quarters.select { |m| m.bracket_position_number == 1 }.first.reload.wrestler2.name == "Test6"
|
||||
winner_by_name("Test16", conso_quarters.select { |m| m.bracket_position_number == 1 }.first)
|
||||
assert conso_quarters.select { |m| m.bracket_position_number == 2 }.first.reload.wrestler1.name == "Test35"
|
||||
assert conso_quarters.select { |m| m.bracket_position_number == 2 }.first.reload.wrestler2.name == "Test25"
|
||||
winner_by_name("Test35", conso_quarters.select { |m| m.bracket_position_number == 2 }.first)
|
||||
|
||||
semis = matches.reload.select { |m| m.bracket_position == "Semis" }.sort_by(&:bracket_position_number)
|
||||
assert_equal "Test1", semis[0].reload.wrestler1.name
|
||||
assert_equal "Test5", semis[0].reload.wrestler2.name
|
||||
assert_equal "Test3", semis[1].reload.wrestler1.name
|
||||
assert_equal "Test2", semis[1].reload.wrestler2.name
|
||||
winner_by_name("Test5", semis[0])
|
||||
winner_by_name("Test2", semis[1])
|
||||
|
||||
semis_conso = matches.reload.select { |m| m.bracket_position == "Conso Semis" }.sort_by(&:bracket_position_number)
|
||||
bout0_names = [semis_conso[0].reload.wrestler1&.name, semis_conso[0].reload.wrestler2&.name]
|
||||
bout1_names = [semis_conso[1].reload.wrestler1&.name, semis_conso[1].reload.wrestler2&.name]
|
||||
assert (bout0_names & ["Test1","Test16"]).size == 2
|
||||
assert (bout1_names & ["Test3","Test35"]).size == 2
|
||||
winner_by_name("Test1", semis_conso[0])
|
||||
winner_by_name("Test3", semis_conso[1])
|
||||
|
||||
# --- PLACEMENT MATCHES ---
|
||||
first_finals = matches.reload.find { |m| m.bracket_position == "1/2" }
|
||||
third_finals = matches.reload.find { |m| m.bracket_position == "3/4" }
|
||||
fifth_finals = matches.reload.find { |m| m.bracket_position == "5/6" }
|
||||
seventh_finals = matches.reload.find { |m| m.bracket_position == "7/8" }
|
||||
|
||||
# 1st/2nd: winners of semis
|
||||
assert_equal "Test5", first_finals.reload.wrestler1.name
|
||||
assert_equal "Test2", first_finals.reload.wrestler2.name
|
||||
|
||||
# 3rd/4th: winners of Conso Semis (we set winners to champs losers 1 and 3)
|
||||
assert_equal "Test1", third_finals.reload.wrestler1.name
|
||||
assert_equal "Test3", third_finals.reload.wrestler2.name
|
||||
|
||||
# 5th/6th: losers of Conso Semis (the CQ winners we defeated there)
|
||||
assert_equal "Test16", fifth_finals.reload.wrestler1.name
|
||||
assert_equal "Test35", fifth_finals.reload.wrestler2.name
|
||||
|
||||
# 7th/8th: losers of Conso Quarters (the two who didn’t advance: 6 and 25)
|
||||
assert_equal "Test6", seventh_finals.reload.wrestler1.name
|
||||
assert_equal "Test25", seventh_finals.reload.wrestler2.name
|
||||
|
||||
# DEBUG
|
||||
# matches.sort_by{|m| m.bout_number}.each do |match|
|
||||
# match.reload
|
||||
# puts "Bracket Position: #{match.bracket_position} Round: #{match.round} #{match.w1_bracket_name} vs #{match.w2_bracket_name}"
|
||||
# end
|
||||
end
|
||||
end
|
||||
@@ -85,17 +85,17 @@ class DoubleEliminationEightManMatchGeneration < ActionDispatch::IntegrationTest
|
||||
assert wrestler2.reload.placement_points == 3
|
||||
end
|
||||
|
||||
test "Run through all matches works" do
|
||||
@tournament.matches.sort_by{ |match| match.bout_number }.each do |match|
|
||||
match.reload
|
||||
if match.finished != 1 and match.w1 and match.w2
|
||||
match.winner_id = match.w1
|
||||
match.win_type = "Decision"
|
||||
match.score = "0-0"
|
||||
match.finished = 1
|
||||
match.save
|
||||
end
|
||||
end
|
||||
assert @tournament.matches.reload.select{|m| m.finished == 0}.count == 0
|
||||
end
|
||||
# test "Run through all matches works" do
|
||||
# @tournament.matches.sort_by{ |match| match.bout_number }.each do |match|
|
||||
# match.reload
|
||||
# if match.finished != 1 and match.w1 and match.w2
|
||||
# match.winner_id = match.w1
|
||||
# match.win_type = "Decision"
|
||||
# match.score = "0-0"
|
||||
# match.finished = 1
|
||||
# match.save
|
||||
# end
|
||||
# end
|
||||
# assert @tournament.matches.reload.select{|m| m.finished == 0}.count == 0
|
||||
# end
|
||||
end
|
||||
@@ -125,17 +125,17 @@ class DoubleEliminationSixteenManSixPlacesMatchGeneration < ActionDispatch::Inte
|
||||
assert wrestler2.reload.placement_points == 3
|
||||
end
|
||||
|
||||
test "Run through all matches works" do
|
||||
@tournament.matches.sort_by{ |match| match.bout_number }.each do |match|
|
||||
match.reload
|
||||
if match.finished != 1 and match.w1 and match.w2
|
||||
match.winner_id = match.w1
|
||||
match.win_type = "Decision"
|
||||
match.score = "0-0"
|
||||
match.finished = 1
|
||||
match.save
|
||||
end
|
||||
end
|
||||
assert @tournament.matches.reload.select{|m| m.finished == 0}.count == 0
|
||||
end
|
||||
# test "Run through all matches works" do
|
||||
# @tournament.matches.sort_by{ |match| match.bout_number }.each do |match|
|
||||
# match.reload
|
||||
# if match.finished != 1 and match.w1 and match.w2
|
||||
# match.winner_id = match.w1
|
||||
# match.win_type = "Decision"
|
||||
# match.score = "0-0"
|
||||
# match.finished = 1
|
||||
# match.save
|
||||
# end
|
||||
# end
|
||||
# assert @tournament.matches.reload.select{|m| m.finished == 0}.count == 0
|
||||
# end
|
||||
end
|
||||
@@ -137,17 +137,17 @@ class DoubleEliminationSixteenManEightPlacesMatchGeneration < ActionDispatch::In
|
||||
assert wrestler3.reload.placement_points == 1
|
||||
end
|
||||
|
||||
test "Run through all matches works" do
|
||||
@tournament.matches.sort_by{ |match| match.bout_number }.each do |match|
|
||||
match.reload
|
||||
if match.finished != 1 and match.w1 and match.w2
|
||||
match.winner_id = match.w1
|
||||
match.win_type = "Decision"
|
||||
match.score = "0-0"
|
||||
match.finished = 1
|
||||
match.save
|
||||
end
|
||||
end
|
||||
assert @tournament.matches.reload.select{|m| m.finished == 0}.count == 0
|
||||
end
|
||||
# test "Run through all matches works" do
|
||||
# @tournament.matches.sort_by{ |match| match.bout_number }.each do |match|
|
||||
# match.reload
|
||||
# if match.finished != 1 and match.w1 and match.w2
|
||||
# match.winner_id = match.w1
|
||||
# match.win_type = "Decision"
|
||||
# match.score = "0-0"
|
||||
# match.finished = 1
|
||||
# match.save
|
||||
# end
|
||||
# end
|
||||
# assert @tournament.matches.reload.select{|m| m.finished == 0}.count == 0
|
||||
# end
|
||||
end
|
||||
@@ -113,17 +113,17 @@ class ModifiedDoubleEliminationSixPlacesManMatchGeneration < ActionDispatch::Int
|
||||
assert wrestler.reload.placement_points == 7
|
||||
end
|
||||
|
||||
test "Run through all matches works" do
|
||||
@tournament.matches.sort_by{ |match| match.bout_number }.each do |match|
|
||||
match.reload
|
||||
if match.finished != 1 and match.w1 and match.w2
|
||||
match.winner_id = match.w1
|
||||
match.win_type = "Decision"
|
||||
match.score = "0-0"
|
||||
match.finished = 1
|
||||
match.save
|
||||
end
|
||||
end
|
||||
assert @tournament.matches.reload.select{|m| m.finished == 0}.count == 0
|
||||
end
|
||||
# test "Run through all matches works" do
|
||||
# @tournament.matches.sort_by{ |match| match.bout_number }.each do |match|
|
||||
# match.reload
|
||||
# if match.finished != 1 and match.w1 and match.w2
|
||||
# match.winner_id = match.w1
|
||||
# match.win_type = "Decision"
|
||||
# match.score = "0-0"
|
||||
# match.finished = 1
|
||||
# match.save
|
||||
# end
|
||||
# end
|
||||
# assert @tournament.matches.reload.select{|m| m.finished == 0}.count == 0
|
||||
# end
|
||||
end
|
||||
@@ -126,17 +126,17 @@ class ModifiedDoubleEliminationEightPlacesManMatchGeneration < ActionDispatch::I
|
||||
assert wrestler2.reload.placement_points == 1
|
||||
end
|
||||
|
||||
test "Run through all matches works" do
|
||||
@tournament.matches.sort_by{ |match| match.bout_number }.each do |match|
|
||||
match.reload
|
||||
if match.finished != 1 and match.w1 and match.w2
|
||||
match.winner_id = match.w1
|
||||
match.win_type = "Decision"
|
||||
match.score = "0-0"
|
||||
match.finished = 1
|
||||
match.save
|
||||
end
|
||||
end
|
||||
assert @tournament.matches.reload.select{|m| m.finished == 0}.count == 0
|
||||
end
|
||||
# test "Run through all matches works" do
|
||||
# @tournament.matches.sort_by{ |match| match.bout_number }.each do |match|
|
||||
# match.reload
|
||||
# if match.finished != 1 and match.w1 and match.w2
|
||||
# match.winner_id = match.w1
|
||||
# match.win_type = "Decision"
|
||||
# match.score = "0-0"
|
||||
# match.finished = 1
|
||||
# match.save
|
||||
# end
|
||||
# end
|
||||
# assert @tournament.matches.reload.select{|m| m.finished == 0}.count == 0
|
||||
# end
|
||||
end
|
||||
36
test/integration/random_seeding_test.rb
Normal file
36
test/integration/random_seeding_test.rb
Normal file
@@ -0,0 +1,36 @@
|
||||
require 'test_helper'
|
||||
|
||||
class RandomSeedingTest < ActionDispatch::IntegrationTest
|
||||
def setup
|
||||
|
||||
end
|
||||
|
||||
def clean_up_original_seeds(tournament)
|
||||
tournament.wrestlers.select{|w| w.original_seed > 12}.each do |wrestler|
|
||||
wrestler.original_seed = nil
|
||||
wrestler.save
|
||||
end
|
||||
tournament.wrestlers.reload.each do |wrestler|
|
||||
wrestler.bracket_line = nil
|
||||
wrestler.save
|
||||
end
|
||||
GenerateTournamentMatches.new(tournament).generate
|
||||
end
|
||||
|
||||
test "There are no double byes in a double elimination tournament round 1" do
|
||||
create_double_elim_tournament_single_weight(18, "Regular Double Elimination 1-8")
|
||||
clean_up_original_seeds(@tournament)
|
||||
round_one_matches = @tournament.matches.reload.select{|m| m.round == 1}
|
||||
assert round_one_matches.select{|m| m.w1.nil? and m.w2.nil? }.size == 0
|
||||
end
|
||||
|
||||
test "There are the same number of matches in the top half and bottom half of a double elimination tournament in round 1" do
|
||||
create_double_elim_tournament_single_weight(18, "Regular Double Elimination 1-8")
|
||||
clean_up_original_seeds(@tournament)
|
||||
round_one_matches = @tournament.matches.reload.select{|m| m.round == 1}
|
||||
# 32 man bracket there are 16 matches so top half is bracket_position_number 1-8 and bottom is 9-16
|
||||
round_one_top_half = round_one_matches.select{|m| !m.w1.nil? and !m.w2.nil? and m.bracket_position_number < 9}
|
||||
round_one_bottom_half = round_one_matches.select{|m| !m.w1.nil? and !m.w2.nil? and m.bracket_position_number > 8}
|
||||
assert round_one_top_half.size == round_one_bottom_half.size
|
||||
end
|
||||
end
|
||||
@@ -8,7 +8,7 @@ class MatTest < ActiveSupport::TestCase
|
||||
test "Mat validations" do
|
||||
mat = Mat.new
|
||||
assert_not mat.valid?
|
||||
assert_equal [:name], mat.errors.attribute_names
|
||||
assert_equal [:tournament, :name], mat.errors.attribute_names
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
68
test/models/match_broadcast_test.rb
Normal file
68
test/models/match_broadcast_test.rb
Normal file
@@ -0,0 +1,68 @@
|
||||
require 'test_helper'
|
||||
|
||||
class MatchBroadcastTest < ActiveSupport::TestCase
|
||||
include ActionView::RecordIdentifier
|
||||
|
||||
test "broadcasts to old and new mats when mat changes" do
|
||||
create_double_elim_tournament_single_weight_1_6(4)
|
||||
mat1 = @tournament.mats.create!(name: "Mat 1")
|
||||
mat2 = @tournament.mats.create!(name: "Mat 2")
|
||||
@tournament.matches.update_all(mat_id: nil)
|
||||
match = @tournament.matches.first
|
||||
|
||||
# Set an initial mat
|
||||
match.update!(mat: mat1)
|
||||
stream1 = stream_name_for(mat1)
|
||||
stream2 = stream_name_for(mat2)
|
||||
|
||||
# Clear the stream so we can test changes from this state
|
||||
clear_streams(stream1, stream2)
|
||||
|
||||
# Update the mat and check the stream
|
||||
match.update!(mat: mat2)
|
||||
assert_equal [mat1.id, mat2.id], match.saved_change_to_mat_id
|
||||
|
||||
assert_equal 1, broadcasts_for(stream1).size
|
||||
assert_equal 1, broadcasts_for(stream2).size
|
||||
|
||||
assert_includes broadcasts_for(stream2).last, dom_id(mat2, :current_match)
|
||||
end
|
||||
|
||||
test "broadcasts when a match is removed from a mat" do
|
||||
create_double_elim_tournament_single_weight_1_6(4)
|
||||
mat = @tournament.mats.create!(name: "Mat 1")
|
||||
@tournament.matches.update_all(mat_id: nil)
|
||||
match = @tournament.matches.first
|
||||
|
||||
# Set an initial mat
|
||||
match.update!(mat: mat)
|
||||
stream = stream_name_for(mat)
|
||||
|
||||
# Clear the stream so we can test changes from this state
|
||||
clear_streams(stream)
|
||||
|
||||
# Update the mat and check the stream
|
||||
match.update!(mat: nil)
|
||||
assert_equal [mat.id, nil], match.saved_change_to_mat_id
|
||||
|
||||
assert_equal 1, broadcasts_for(stream).size
|
||||
assert_includes broadcasts_for(stream).last, dom_id(mat, :current_match)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def broadcasts_for(stream)
|
||||
ActionCable.server.pubsub.broadcasts(stream)
|
||||
end
|
||||
|
||||
def clear_streams(*streams)
|
||||
ActionCable.server.pubsub.clear
|
||||
streams.each do |stream|
|
||||
broadcasts_for(stream).clear
|
||||
end
|
||||
end
|
||||
|
||||
def stream_name_for(streamable)
|
||||
Turbo::StreamsChannel.send(:stream_name_from, [streamable])
|
||||
end
|
||||
end
|
||||
@@ -8,7 +8,7 @@ class SchoolTest < ActiveSupport::TestCase
|
||||
test "School validations" do
|
||||
school = School.new
|
||||
assert_not school.valid?
|
||||
assert_equal [:name], school.errors.attribute_names
|
||||
assert_equal [:tournament, :name], school.errors.attribute_names
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -69,8 +69,8 @@ class TournamentTest < ActiveSupport::TestCase
|
||||
assert @tournament.match_generation_error != nil
|
||||
end
|
||||
|
||||
test "Tournament Double Elimination 1-8 match generation errors with more than 32 wrestlers" do
|
||||
number_of_wrestlers=33
|
||||
test "Tournament Double Elimination 1-8 match generation errors with more than 64 wrestlers" do
|
||||
number_of_wrestlers=65
|
||||
create_a_tournament_with_single_weight("Double Elimination 1-8", number_of_wrestlers)
|
||||
assert @tournament.match_generation_error != nil
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@ class WeightTest < ActiveSupport::TestCase
|
||||
test "Weight validations" do
|
||||
weight = Weight.new
|
||||
assert_not weight.valid?
|
||||
assert_equal [:max], weight.errors.attribute_names
|
||||
assert_equal [:tournament, :max], weight.errors.attribute_names
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@ class WrestlerTest < ActiveSupport::TestCase
|
||||
test "Wrestler validations" do
|
||||
wrestler = Wrestler.new
|
||||
assert_not wrestler.valid?
|
||||
assert_equal [:name, :weight_id, :school_id], wrestler.errors.attribute_names
|
||||
assert_equal [:school, :weight, :name, :weight_id, :school_id], wrestler.errors.attribute_names
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
29
test/views/mats_current_match_partial_test.rb
Normal file
29
test/views/mats_current_match_partial_test.rb
Normal file
@@ -0,0 +1,29 @@
|
||||
require "test_helper"
|
||||
|
||||
class MatsCurrentMatchPartialTest < ActionView::TestCase
|
||||
include ActionView::RecordIdentifier
|
||||
|
||||
test "renders current match contents when assigned" do
|
||||
create_double_elim_tournament_single_weight_1_6(4)
|
||||
mat = @tournament.mats.create!(name: "Mat 1")
|
||||
match = @tournament.matches.first
|
||||
|
||||
match.update!(mat: mat)
|
||||
|
||||
render partial: "mats/current_match", locals: { mat: mat }
|
||||
|
||||
assert_includes rendered, "Bout"
|
||||
assert_includes rendered, match.bout_number.to_s
|
||||
assert_includes rendered, mat.name
|
||||
end
|
||||
|
||||
test "renders friendly message when no matches assigned" do
|
||||
create_double_elim_tournament_single_weight_1_6(4)
|
||||
mat = @tournament.mats.create!(name: "Mat 1")
|
||||
@tournament.matches.update_all(mat_id: nil)
|
||||
|
||||
render partial: "mats/current_match", locals: { mat: mat }
|
||||
|
||||
assert_includes rendered, "No matches assigned to this mat."
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user