From e612a4b10edef18f557751bdc497c3de142056aa Mon Sep 17 00:00:00 2001 From: Jacob Cody Wimer Date: Fri, 10 Jan 2025 16:02:37 -0500 Subject: [PATCH] Fixed the query for unassigned matches on the up_matches page and also only allow mats to get a new match assigned if they have less than 4 unfinished matches. Added mats to the finish_tournament_204 rake task. --- app/controllers/tournaments_controller.rb | 7 +++++-- app/models/mat.rb | 3 ++- lib/tasks/finish_tournament_204.rake | 23 ++++++++++++++++++++++- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index f32f7a7..60ab985 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -191,9 +191,12 @@ class TournamentsController < ApplicationController def up_matches + # .where.not(loser1_name: 'BYE') won't return matches with NULL loser1_name + # so I was only getting back matches with Loser of BOUT_NUMBER @matches = @tournament.matches - .where("mat_id is NULL and (finished <> ? or finished is NULL)",1) - .where.not(loser1_name: "BYE").where.not(loser2_name: "BYE") + .where("mat_id is NULL and (finished != 1 or finished is NULL)") + .where("loser1_name != ? OR loser1_name IS NULL", "BYE") + .where("loser2_name != ? OR loser2_name IS NULL", "BYE") .order('bout_number ASC') .limit(10).includes(:wrestlers) @mats = @tournament.mats.includes(:matches) diff --git a/app/models/mat.rb b/app/models/mat.rb index f43ea9e..b9d5569 100644 --- a/app/models/mat.rb +++ b/app/models/mat.rb @@ -23,7 +23,8 @@ class Mat < ApplicationRecord def assign_next_match match = next_eligible_match - if match + self.matches.reload + if match and self.unfinished_matches.size < 4 match.mat_id = self.id if match.save # Invalidate any wrestler caches diff --git a/lib/tasks/finish_tournament_204.rake b/lib/tasks/finish_tournament_204.rake index 0a5ead1..923c8a0 100644 --- a/lib/tasks/finish_tournament_204.rake +++ b/lib/tasks/finish_tournament_204.rake @@ -5,6 +5,27 @@ namespace :tournament do @tournament = Tournament.find(204) + Mat.create( + name: "1", + tournament_id: @tournament.id + ) + Mat.create( + name: "2", + tournament_id: @tournament.id + ) + Mat.create( + name: "3", + tournament_id: @tournament.id + ) + Mat.create( + name: "4", + tournament_id: @tournament.id + ) + Mat.create( + name: "5", + tournament_id: @tournament.id + ) + GenerateTournamentMatches.new(@tournament).generate sleep(180) @@ -45,7 +66,7 @@ namespace :tournament do match.save # Pause to simulate processing delay - sleep(30) + sleep(10) end end end