1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-03-25 01:14:43 +00:00

3 Commits

7 changed files with 108 additions and 114 deletions

View File

@@ -30,7 +30,7 @@ From here, you can run the normal rails commands.
* `rails generate blah blah blah`
* ` rails s -b 0.0.0.0` port 3000 is exposed. You can open [http://localhost:3000](http://localhost:3000) after running that command
* etc.
* `rake finish_seed_tournament` will complete all matches from the seed data. This command takes about 5 minutes to execute
* `rake finish_seed_tournaments` will complete all matches from the seed data. This command takes about 5 minutes to execute
To deploy a a full local version of the app `bash deploy/deploy-test.sh` (this requires docker-compose to be installed). This deploys a full version of the app. App, delayed job, memcached, and mariadb. Now, you can open [http://localhost](http://localhost). Delayed jobs are turned off in dev and everything that is a delayed job in prod just runs in browser.

View File

@@ -134,7 +134,7 @@ class TournamentsController < ApplicationController
end
def matches
@matches = @tournament.matches.sort_by{|m| m.bout_number}
@matches = @tournament.matches.includes(:wrestlers,:schools).sort_by{|m| m.bout_number}
if @match
@w1 = @match.wrestler1
@w2 = @match.wrestler2

View File

@@ -3,6 +3,7 @@ class Match < ActiveRecord::Base
belongs_to :weight, touch: true
belongs_to :mat, touch: true
has_many :wrestlers, :through => :weight
has_many :schools, :through => :wrestlers
after_update :after_finished_actions, :if => :saved_change_to_finished? or :saved_change_to_winner_id? or :saved_change_to_win_type? or :saved_change_to_score?
def after_finished_actions

View File

@@ -10,8 +10,8 @@ class Weight < ActiveRecord::Base
# passed via layouts/_tournament-navbar.html.erb
# tournaments controller does a .split(',') on this string and creates an array via commas
# tournament model runs the code via method create_pre_defined_weights
HS_WEIGHT_CLASSES = "106,113,120,126,132,138,145,152,160,170,182,195,220,285"
HS_GIRLS_WEIGHT_CLASSES = "101,106,111,116,121,126,131,137,143,150,160,170,189,235"
HS_WEIGHT_CLASSES = "106,113,120,126,132,138,144,150,157,165,175,190,215,285."
HS_GIRLS_WEIGHT_CLASSES = "100,105,110,115,120,125,130,135,140,145,155,170,190,235"
before_destroy do
self.tournament.destroy_all_matches

View File

@@ -6,103 +6,88 @@
# cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }])
# Mayor.create(name: 'Emanuel', city: cities.first)
#if Rails.env.development?
def create_schools(tournament, number_of_schools)
for number in (1..number_of_schools) do
school = School.new
school.name = "School#{number}"
school.tournament_id = tournament.id
school.save
end
end
def create_wrestlers_for_weight(weight, tournament, number_of_wrestlers, naming_start_number)
naming_number = naming_start_number
for number in (1..number_of_wrestlers) do
wrestler = Wrestler.new
wrestler.name = "Wrestler#{naming_number}"
wrestler.school_id = tournament.schools.select{|s|s.name == "School#{number}"}.first.id
wrestler.weight_id = weight.id
wrestler.original_seed = number
wrestler.save
naming_number = naming_number + 1
end
end
User.create(id: 1, email: 'test@test.com', password: 'password', password_confirmation: 'password')
Tournament.create(id: 200, name: 'test', address: 'some place', director: 'some guy', director_email: 'hismail@email.com', tournament_type: 'Pool to bracket', user_id: 1, date: Date.today)
School.create(id: 200, name: 'Central Crossing', tournament_id: 200)
School.create(id: 201, name: 'Turd Town', tournament_id: 200)
School.create(id: 202, name: 'Shit Show', tournament_id: 200)
School.create(id: 203, name: 'Westland', tournament_id: 200)
School.create(id: 204, name: 'Grove City', tournament_id: 200)
School.create(id: 205, name: 'Franklin Heights', tournament_id: 200)
Weight.create(id: 200, max: 132, tournament_id: 200 )
Weight.create(id: 201, max: 106, tournament_id: 200 )
Weight.create(id: 202, max: 113, tournament_id: 200 )
Weight.create(id: 203, max: 120, tournament_id: 200 )
Weight.create(id: 204, max: 126, tournament_id: 200 )
Weight.create(id: 205, max: 138, tournament_id: 200 )
Mat.create(id: 200, name: "1", tournament_id: 200 )
Mat.create(id: 201, name: "2", tournament_id: 200 )
Mat.create(id: 202, name: "3", tournament_id: 200 )
Mat.create(id: 203, name: "4", tournament_id: 200 )
Wrestler.create(name: 'Guy 1', school_id: 200, weight_id: 200, original_seed: 1, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 2', school_id: 201, weight_id: 200, original_seed: 2, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 3', school_id: 202, weight_id: 200, original_seed: 3, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 4', school_id: 203, weight_id: 200, original_seed: 4, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 5', school_id: 204, weight_id: 200, original_seed: 5, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 6', school_id: 200, weight_id: 200, original_seed: 6, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 7', school_id: 200, weight_id: 200, original_seed: 7, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 8', school_id: 200, weight_id: 200, original_seed: 8, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 9', school_id: 200, weight_id: 200, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 10', school_id: 200, weight_id: 200, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 11', school_id: 200, weight_id: 200, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 12', school_id: 200, weight_id: 200, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 13', school_id: 200, weight_id: 200, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 14', school_id: 200, weight_id: 200, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 15', school_id: 200, weight_id: 200, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 16', school_id: 200, weight_id: 200, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 17', school_id: 200, weight_id: 201, original_seed: 1, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 18', school_id: 201, weight_id: 201, original_seed: 2, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 19', school_id: 202, weight_id: 201, original_seed: 3, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 20', school_id: 203, weight_id: 201, original_seed: 4, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 21', school_id: 204, weight_id: 201, original_seed: 5, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 22', school_id: 200, weight_id: 201, original_seed: 6, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 23', school_id: 200, weight_id: 201, original_seed: 7, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 24', school_id: 200, weight_id: 201, original_seed: 8, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 25', school_id: 200, weight_id: 201, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 26', school_id: 201, weight_id: 201, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 27', school_id: 202, weight_id: 201, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 30', school_id: 204, weight_id: 202, original_seed: 1, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 31', school_id: 204, weight_id: 202, original_seed: 2, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 32', school_id: 204, weight_id: 202, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 33', school_id: 204, weight_id: 202, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 34', school_id: 204, weight_id: 202, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 35', school_id: 204, weight_id: 203, original_seed: 1, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 36', school_id: 204, weight_id: 203, original_seed: 2, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 37', school_id: 204, weight_id: 203, original_seed: 3, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 38', school_id: 204, weight_id: 203, original_seed: 4, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 39', school_id: 204, weight_id: 203, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 40', school_id: 204, weight_id: 203, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 41', school_id: 204, weight_id: 203, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 42', school_id: 204, weight_id: 203, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 43', school_id: 204, weight_id: 203, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 44', school_id: 204, weight_id: 203, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
# Pool to bracket
tournament = Tournament.create(id: 200, name: 'Test1', address: 'some place', director: 'some guy', director_email: 'their@email.com', tournament_type: 'Pool to bracket', user_id: 1, date: Date.today)
create_schools(tournament, 16)
weight_classes=Weight::HS_WEIGHT_CLASSES.split(",")
tournament.create_pre_defined_weights(weight_classes)
wrestler_name_number = 1
tournament.weights.each do |weight|
create_wrestlers_for_weight(weight, tournament, 16, wrestler_name_number)
wrestler_name_number += 16
end
Wrestler.create(name: 'Guy 45', school_id: 204, weight_id: 204, original_seed: 1, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 46', school_id: 204, weight_id: 204, original_seed: 2, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 47', school_id: 204, weight_id: 204, original_seed: 3, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 48', school_id: 204, weight_id: 204, original_seed: 4, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 49', school_id: 204, weight_id: 204, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 50', school_id: 204, weight_id: 204, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 51', school_id: 204, weight_id: 204, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 52', school_id: 204, weight_id: 204, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
# Modified 16 Man Double Elimination 1-6
tournament = Tournament.create(id: 201, name: 'Test2', address: 'some place', director: 'some guy', director_email: 'their@email.com', tournament_type: 'Modified 16 Man Double Elimination 1-6', user_id: 1, date: Date.today)
create_schools(tournament, 16)
weight_classes=Weight::HS_WEIGHT_CLASSES.split(",")
tournament.create_pre_defined_weights(weight_classes)
wrestler_name_number = 1
tournament.weights.each do |weight|
create_wrestlers_for_weight(weight, tournament, 16, wrestler_name_number)
wrestler_name_number += 16
end
Wrestler.create(name: 'Guy 53', school_id: 204, weight_id: 205, original_seed: 1, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 54', school_id: 204, weight_id: 205, original_seed: 2, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 55', school_id: 204, weight_id: 205, original_seed: 3, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 56', school_id: 204, weight_id: 205, original_seed: 4, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 57', school_id: 204, weight_id: 205, original_seed: 5, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 58', school_id: 204, weight_id: 205, original_seed: 6, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 59', school_id: 204, weight_id: 205, original_seed: 7, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 60', school_id: 204, weight_id: 205, original_seed: 8, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 61', school_id: 204, weight_id: 205, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 62', school_id: 204, weight_id: 205, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 63', school_id: 204, weight_id: 205, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 64', school_id: 204, weight_id: 205, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 65', school_id: 204, weight_id: 205, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 66', school_id: 204, weight_id: 205, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 67', school_id: 204, weight_id: 205, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 68', school_id: 204, weight_id: 205, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 69', school_id: 204, weight_id: 205, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 70', school_id: 204, weight_id: 205, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 71', school_id: 204, weight_id: 205, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 72', school_id: 204, weight_id: 205, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 73', school_id: 204, weight_id: 205, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 74', school_id: 204, weight_id: 205, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 75', school_id: 204, weight_id: 205, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
Wrestler.create(name: 'Guy 76', school_id: 204, weight_id: 205, original_seed: nil, season_win: 0, season_loss: 0, criteria: 'N/A')
# Modified 16 Man Double Elimination 1-8
tournament = Tournament.create(id: 202, name: 'Test3', address: 'some place', director: 'some guy', director_email: 'their@email.com', tournament_type: 'Modified 16 Man Double Elimination 1-8', user_id: 1, date: Date.today)
create_schools(tournament, 16)
weight_classes=Weight::HS_WEIGHT_CLASSES.split(",")
tournament.create_pre_defined_weights(weight_classes)
wrestler_name_number = 1
tournament.weights.each do |weight|
create_wrestlers_for_weight(weight, tournament, 16, wrestler_name_number)
wrestler_name_number += 16
end
# Regular Double Elimination 1-6
tournament = Tournament.create(id: 203, name: 'Test4', address: 'some place', director: 'some guy', director_email: 'their@email.com', tournament_type: 'Regular Double Elimination 1-6', user_id: 1, date: Date.today)
create_schools(tournament, 16)
weight_classes=Weight::HS_WEIGHT_CLASSES.split(",")
tournament.create_pre_defined_weights(weight_classes)
wrestler_name_number = 1
tournament.weights.each do |weight|
create_wrestlers_for_weight(weight, tournament, 16, wrestler_name_number)
wrestler_name_number += 16
end
# Regular Double Elimination 1-8
tournament = Tournament.create(id: 204, name: 'Test5', address: 'some place', director: 'some guy', director_email: 'their@email.com', tournament_type: 'Regular Double Elimination 1-8', user_id: 1, date: Date.today)
create_schools(tournament, 16)
weight_classes=Weight::HS_WEIGHT_CLASSES.split(",")
tournament.create_pre_defined_weights(weight_classes)
wrestler_name_number = 1
tournament.weights.each do |weight|
create_wrestlers_for_weight(weight, tournament, 16, wrestler_name_number)
wrestler_name_number += 16
end
#end

View File

@@ -1,19 +0,0 @@
task :finish_seed_tournament => :environment do
@tournament = Tournament.where(:id => 200).includes(:schools,:weights,:mats,:matches,:user,:wrestlers).first
GenerateTournamentMatches.new(@tournament).generate
(1..@tournament.reload.total_rounds).each do |round|
@tournament.reload.matches_by_round(round).select{|m| m.finished != 1}.each do |match|
match.reload
if match.wrestler1.bracket_line < match.wrestler2.bracket_line and match.w1
match.winner_id = match.w1
elsif match.w2
match.winner_id = match.w2
end
if match.winner_id
match.finished = 1
match.score = "2-1"
match.save
end
end
end
end

View File

@@ -0,0 +1,27 @@
task :finish_seed_tournaments => :environment do
finish_tournament(tournament_id)
@tournament = Tournament.where(:id => tournament_id).includes(:schools,:weights,:mats,:matches,:user,:wrestlers).first
GenerateTournamentMatches.new(@tournament).generate
(1..@tournament.reload.total_rounds).each do |round|
@tournament.reload.matches_by_round(round).select{|m| m.finished != 1}.each do |match|
match.reload
if match.wrestler1.bracket_line < match.wrestler2.bracket_line and match.w1
match.winner_id = match.w1
elsif match.w2
match.winner_id = match.w2
end
if match.winner_id
match.finished = 1
match.score = "2-1"
match.save
end
end
end
finish_tournament(200)
finish_tournament(201)
finish_tournament(202)
finish_tournament(203)
finish_tournament(204)
end