mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-07 14:57:48 +00:00
Added queues for mats and provided a way for tournament directors to move matches to a mat.
This commit is contained in:
@@ -37,7 +37,11 @@ class TournamentBackupService
|
||||
attributes: @tournament.attributes,
|
||||
schools: @tournament.schools.map(&:attributes),
|
||||
weights: @tournament.weights.map(&:attributes),
|
||||
mats: @tournament.mats.map(&:attributes),
|
||||
mats: @tournament.mats.map do |mat|
|
||||
mat.attributes.merge(
|
||||
"queue_bout_numbers" => mat.queue_matches.map { |match| match&.bout_number }
|
||||
)
|
||||
end,
|
||||
mat_assignment_rules: @tournament.mat_assignment_rules.map do |rule|
|
||||
rule.attributes.merge(
|
||||
mat: Mat.find_by(id: rule.mat_id)&.attributes.slice("name"),
|
||||
|
||||
@@ -45,15 +45,16 @@ class WrestlingdevImporter
|
||||
# Note: Teampointadjusts are deleted via School/Wrestler cascade
|
||||
end
|
||||
|
||||
def parse_data
|
||||
parse_tournament(@import_data["tournament"]["attributes"])
|
||||
parse_schools(@import_data["tournament"]["schools"])
|
||||
parse_weights(@import_data["tournament"]["weights"])
|
||||
parse_mats(@import_data["tournament"]["mats"])
|
||||
parse_wrestlers(@import_data["tournament"]["wrestlers"])
|
||||
parse_matches(@import_data["tournament"]["matches"])
|
||||
parse_mat_assignment_rules(@import_data["tournament"]["mat_assignment_rules"])
|
||||
end
|
||||
def parse_data
|
||||
parse_tournament(@import_data["tournament"]["attributes"])
|
||||
parse_schools(@import_data["tournament"]["schools"])
|
||||
parse_weights(@import_data["tournament"]["weights"])
|
||||
parse_mats(@import_data["tournament"]["mats"])
|
||||
parse_wrestlers(@import_data["tournament"]["wrestlers"])
|
||||
parse_matches(@import_data["tournament"]["matches"])
|
||||
apply_mat_queues
|
||||
parse_mat_assignment_rules(@import_data["tournament"]["mat_assignment_rules"])
|
||||
end
|
||||
|
||||
def parse_tournament(attributes)
|
||||
attributes.except!("id")
|
||||
@@ -74,12 +75,18 @@ class WrestlingdevImporter
|
||||
end
|
||||
end
|
||||
|
||||
def parse_mats(mats)
|
||||
mats.each do |mat_attributes|
|
||||
mat_attributes.except!("id")
|
||||
Mat.create(mat_attributes.merge(tournament_id: @tournament.id))
|
||||
end
|
||||
end
|
||||
def parse_mats(mats)
|
||||
@mat_queue_bout_numbers = {}
|
||||
mats.each do |mat_attributes|
|
||||
mat_name = mat_attributes["name"]
|
||||
queue_bout_numbers = mat_attributes["queue_bout_numbers"]
|
||||
mat_attributes.except!("id", "queue1", "queue2", "queue3", "queue4", "queue_bout_numbers", "tournament_id")
|
||||
Mat.create(mat_attributes.merge(tournament_id: @tournament.id))
|
||||
if mat_name && queue_bout_numbers
|
||||
@mat_queue_bout_numbers[mat_name] = queue_bout_numbers
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def parse_mat_assignment_rules(mat_assignment_rules)
|
||||
mat_assignment_rules.each do |rule_attributes|
|
||||
@@ -134,9 +141,9 @@ class WrestlingdevImporter
|
||||
end
|
||||
end
|
||||
|
||||
def parse_matches(matches)
|
||||
matches.each do |match_attributes|
|
||||
next unless match_attributes # Skip if match_attributes is nil
|
||||
def parse_matches(matches)
|
||||
matches.each do |match_attributes|
|
||||
next unless match_attributes # Skip if match_attributes is nil
|
||||
|
||||
weight = Weight.find_by(max: match_attributes.dig("weight", "max"), tournament_id: @tournament.id)
|
||||
mat = Mat.find_by(name: match_attributes.dig("mat", "name"), tournament_id: @tournament.id)
|
||||
@@ -155,6 +162,53 @@ class WrestlingdevImporter
|
||||
w2: w2&.id,
|
||||
winner_id: winner&.id
|
||||
))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def apply_mat_queues
|
||||
if @mat_queue_bout_numbers.blank?
|
||||
Mat.where(tournament_id: @tournament.id).find_each do |mat|
|
||||
match_ids = mat.matches.where(finished: [nil, 0]).order(:bout_number).limit(4).pluck(:id)
|
||||
mat.update(
|
||||
queue1: match_ids[0],
|
||||
queue2: match_ids[1],
|
||||
queue3: match_ids[2],
|
||||
queue4: match_ids[3]
|
||||
)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
@mat_queue_bout_numbers.each do |mat_name, bout_numbers|
|
||||
mat = Mat.find_by(name: mat_name, tournament_id: @tournament.id)
|
||||
next unless mat
|
||||
|
||||
matches = Array(bout_numbers).map do |bout_number|
|
||||
Match.find_by(bout_number: bout_number, tournament_id: @tournament.id)
|
||||
end
|
||||
|
||||
mat.update(
|
||||
queue1: matches[0]&.id,
|
||||
queue2: matches[1]&.id,
|
||||
queue3: matches[2]&.id,
|
||||
queue4: matches[3]&.id
|
||||
)
|
||||
|
||||
matches.compact.each do |match|
|
||||
match.update(mat_id: mat.id)
|
||||
end
|
||||
end
|
||||
|
||||
Mat.where(tournament_id: @tournament.id)
|
||||
.where(queue1: nil, queue2: nil, queue3: nil, queue4: nil)
|
||||
.find_each do |mat|
|
||||
match_ids = mat.matches.where(finished: [nil, 0]).order(:bout_number).limit(4).pluck(:id)
|
||||
mat.update(
|
||||
queue1: match_ids[0],
|
||||
queue2: match_ids[1],
|
||||
queue3: match_ids[2],
|
||||
queue4: match_ids[3]
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user