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

Added overtime_type to matches

This commit is contained in:
2022-09-13 11:31:35 +00:00
parent 645fb59e5b
commit 994fc18365
9 changed files with 47 additions and 14 deletions

View File

@@ -26,6 +26,8 @@ jobs:
steps:
- checkout
- run: |
echo Deploys are happening on my home Jenkins server
echo this is a placeholder in case I want to move that
cat >~/.netrc <<EOF
machine api.heroku.com
login $HEROKU_EMAIL
@@ -34,8 +36,8 @@ jobs:
login $HEROKU_EMAIL
password $HEROKU_TOKEN
EOF
chmod 600 ~/.netrc # Heroku cli complains about permissions without this
heroku git:remote -a wrestlingapp
git push heroku master
sleep 20s
heroku run rake db:migrate --app wrestlingapp
#chmod 600 ~/.netrc # Heroku cli complains about permissions without this
#heroku git:remote -a wrestlingapp
#git push heroku master
#sleep 20s
#heroku run rake db:migrate --app wrestlingapp

View File

@@ -80,7 +80,7 @@ class MatchesController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def match_params
params.require(:match).permit(:w1, :w2, :w1_stat, :w2_stat, :winner_id, :win_type, :score, :finished)
params.require(:match).permit(:w1, :w2, :w1_stat, :w2_stat, :winner_id, :win_type, :score, :overtime_type, :finished)
end
def check_access

View File

@@ -4,7 +4,7 @@ class Match < ActiveRecord::Base
belongs_to :mat, touch: true
has_many :wrestlers, :through => :weight
has_many :schools, :through => :wrestlers
validate :score_validation, :win_type_validation, :bracket_position_validation
validate :score_validation, :win_type_validation, :bracket_position_validation, :overtime_type_validation
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
@@ -25,6 +25,7 @@ class Match < ActiveRecord::Base
BRACKET_POSITIONS = ["Pool","1/2","3/4","5/6","7/8","Quarter","Semis","Conso Semis","Bracket","Conso", "Conso Quarter"]
WIN_TYPES = ["Decision", "Major", "Tech Fall", "Pin", "Forfeit", "Injury Default", "Default", "DQ", "BYE"]
OVERTIME_TYPES = ["", "SV-1", "TB-1", "UTB", "SV-2", "TB-2", "OT"] # had to keep the blank here for validations
def score_validation
if finished == 1
@@ -51,6 +52,13 @@ class Match < ActiveRecord::Base
end
end
def overtime_type_validation
# overtime_type can be nil or of type OVERTIME_TYPES
if overtime_type != nil and ! OVERTIME_TYPES.include? overtime_type
errors.add(:overtime_type, "can only be one of the following #{OVERTIME_TYPES.to_s}")
end
end
def bracket_position_validation
if ! BRACKET_POSITIONS.include? bracket_position
errors.add(:bracket_position, "can only be one of the following #{BRACKET_POSITIONS.to_s}")
@@ -122,9 +130,11 @@ class Match < ActiveRecord::Base
return ""
end
if self.finished == 1
if self.win_type == "Default"
return "(Def)"
elsif self.win_type == "Injury Default"
overtime_type_abbreviation = ""
if self.overtime_type != "" and self.overtime_type
overtime_type_abbreviation = " #{self.overtime_type}"
end
if self.win_type == "Injury Default"
return "(Inj)"
elsif self.win_type == "DQ"
return "(DQ)"
@@ -132,7 +142,7 @@ class Match < ActiveRecord::Base
return "(FF)"
else
win_type_abbreviation = "#{self.win_type.chars.to_a[0..2].join('')}"
return "(#{win_type_abbreviation} #{self.score})"
return "(#{win_type_abbreviation} #{self.score}#{overtime_type_abbreviation})"
end
end
end

View File

@@ -143,6 +143,7 @@ class WrestlingdevImporter
new_match.loser1_name = match_array[13]
new_match.loser2_name = match_array[14]
# new_match.mat_id = mat_id if match_array[15].size > 0
new_match.overtime_type = match_array[16]
new_match.save
end
end

View File

@@ -83,13 +83,18 @@
<%= f.select(:win_type, Match::WIN_TYPES) %>
</div>
<br>
<div class="field">
<%= f.label "Overtime Type" %> Leave blank if not overtime. For High School the 1st overtime is SV-1, second overtime is TB-1, third overtime is UTB.<br>
<%= f.select(:overtime_type, Match::OVERTIME_TYPES) %>
</div>
<br>
<div class="field">
<%= f.label "Winner" %> Please choose the winner<br>
<%= f.collection_select :winner_id, @wrestlers, :id, :name, include_blank: true %>
</div>
<br>
<div class="field">
<%= f.label "Final Score" %> For decision, major, or tech fall put the score here in Number-Number format. If pin, put the accumulated pin time in the format MM:SS. If default, injury default, dq, bye, or forfeit, leave blank. Examples: 7-2, 17-2, 0:30, or 2:34<br>
<%= f.label "Final Score" %> For decision, major, or tech fall put the score here in Number-Number format. If pin, put the accumulated pin time in the format MM:SS. If default, injury default, dq, bye, or forfeit, leave blank. Examples: 7-2, 17-2, 0:30, or 2:34.<br>
<%= f.text_field :score %>
</div>
<br>

View File

@@ -19,4 +19,4 @@
<br>
--Wrestlers--<% @tournament.wrestlers.each do |wrestler| %><%= model_separator %><%= wrestler.name %><%= attribute_separator %><%= wrestler.school.name %><%= attribute_separator %><%= wrestler.weight.max %><%= attribute_separator %><%= wrestler.bracket_line %><%= attribute_separator %><%= wrestler.original_seed %><%= attribute_separator %><%= wrestler.season_win %><%= attribute_separator %><%= wrestler.season_loss %><%= attribute_separator %><%= wrestler.criteria %><%= attribute_separator %><%= wrestler.extra %><%= attribute_separator %><%= wrestler.offical_weight %><%= attribute_separator %><%= wrestler.pool %><%= attribute_separator %><%= wrestler.pool_placement %><%= attribute_separator %><%= wrestler.pool_placement_tiebreaker %><% end %>
<br>
--Matches--<% @tournament.matches.sort_by{|match| match.bout_number}.each do |match| %><%= model_separator %><%= Wrestler.where("id = ?",match.w1).first.name if match.w1 %><%= attribute_separator %><%= Wrestler.where("id = ?",match.w2).first.name if match.w2 %><%= attribute_separator %><%= match.w1_stat %><%= attribute_separator %><%= match.w2_stat %><%= attribute_separator %><%= Wrestler.where("id = ?",match.winner_id).first.name if match.winner_id %><%= attribute_separator %><%= match.win_type %><%= attribute_separator %><%= match.score %><%= attribute_separator %><%= match.round %><%= attribute_separator %><%= match.finished %><%= attribute_separator %><%= match.bout_number %><%= attribute_separator %><%= Weight.where("id = ?",match.weight_id).first.max if match.weight_id %><%= attribute_separator %><%= match.bracket_position %><%= attribute_separator %><%= match.bracket_position_number %><%= attribute_separator %><%= match.loser1_name %><%= attribute_separator %><%= match.loser2_name %><%= attribute_separator %><%= Mat.where("id = ?",match.mat_id).first.name if match.mat_id %><% end %>
--Matches--<% @tournament.matches.sort_by{|match| match.bout_number}.each do |match| %><%= model_separator %><%= Wrestler.where("id = ?",match.w1).first.name if match.w1 %><%= attribute_separator %><%= Wrestler.where("id = ?",match.w2).first.name if match.w2 %><%= attribute_separator %><%= match.w1_stat %><%= attribute_separator %><%= match.w2_stat %><%= attribute_separator %><%= Wrestler.where("id = ?",match.winner_id).first.name if match.winner_id %><%= attribute_separator %><%= match.win_type %><%= attribute_separator %><%= match.score %><%= attribute_separator %><%= match.round %><%= attribute_separator %><%= match.finished %><%= attribute_separator %><%= match.bout_number %><%= attribute_separator %><%= Weight.where("id = ?",match.weight_id).first.max if match.weight_id %><%= attribute_separator %><%= match.bracket_position %><%= attribute_separator %><%= match.bracket_position_number %><%= attribute_separator %><%= match.loser1_name %><%= attribute_separator %><%= match.loser2_name %><%= attribute_separator %><%= Mat.where("id = ?",match.mat_id).first.name if match.mat_id %><% end %><%= attribute_separator %><%= match.overtime_type %>

View File

@@ -0,0 +1,5 @@
class AddOvertimeToMatch < ActiveRecord::Migration[6.1]
def change
add_column :matches, :overtime_type, :string
end
end

View File

@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_02_23_185853) do
ActiveRecord::Schema.define(version: 2022_09_12_171922) do
create_table "delayed_jobs", force: :cascade do |t|
t.integer "priority", default: 0, null: false
@@ -49,6 +49,7 @@ ActiveRecord::Schema.define(version: 2022_02_23_185853) do
t.string "loser1_name"
t.string "loser2_name"
t.integer "mat_id"
t.string "overtime_type"
t.index ["mat_id"], name: "index_matches_on_mat_id"
t.index ["tournament_id"], name: "index_matches_on_tournament_id"
t.index ["w1", "w2"], name: "index_matches_on_w1_and_w2"

View File

@@ -117,4 +117,13 @@ class MatchTest < ActiveSupport::TestCase
match.save
assert !match.valid?
end
test "Match should not be valid if an incorrect overtime_type is given" do
create_double_elim_tournament_single_weight(14, "Regular Double Elimination 1-8")
matches = @tournament.matches.reload
round1 = matches.select{|m| m.round == 1}
match = matches.first
match.overtime_type = "TEST"
match.save
assert !match.valid?
end
end