From 410bbdce9752fb49ab711d4c148af1c6bbc2a53f Mon Sep 17 00:00:00 2001
From: Luke Shumaker
Date: Sun, 27 Apr 2014 18:53:25 -0400
Subject: clean up seeds.rb
---
db/seeds.rb | 41 ++++++++++++++---------------------------
1 file changed, 14 insertions(+), 27 deletions(-)
diff --git a/db/seeds.rb b/db/seeds.rb
index f565815..dc95929 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -9,33 +9,20 @@
p = User.permission_bits
Server.create(default_user_permissions: p[:join_tournament] | p[:create_pm] | p[:edit_pm] | p[:create_bracket])
-Game.create(name: "League of Legends",min_players_per_team: 5, max_players_per_team: 5, min_teams_per_match: 2, max_teams_per_match: 2, sampling_method: "Manual,Double Blind,RiotAPI")
-Game.create(name: "Chess", min_players_per_team: 1, max_players_per_team: 1, min_teams_per_match: 2, max_teams_per_match: 2, sampling_method: "Manual,Double Blind")
-Game.create(name: "Hearthstone", min_players_per_team: 1, max_players_per_team: 1, min_teams_per_match: 2, max_teams_per_match: 2, sampling_method: "Manual,Double Blind")
-Game.create(name: "Rock, Paper, Scissors", min_players_per_team: 1, max_players_per_team: 3, min_teams_per_match: 2, max_teams_per_match: 2, sampling_method: "Manual,Double Blind")
-
-Game.find_by_name("League of Legends").settings.create(name: "Map", default: "Summoners Rift", type_opt: "Summoners Rift,Twisted Treeline,Crystal Scar,Haunted Abyss", description: "Select a map to play on.", vartype: 5, display_order: 1)
-Game.find_by_name("League of Legends").settings.create(name: "Pick Type", type_opt: "Blind Pick,Draft", description: "Select a pick type.", vartype: 5, display_order: 2)
-#Game.find_by_name("League of Legends").settings.create(name: "Scoring Method", type_opt: "FibonacciPeerWithBlowout,MarginalPeer,WinnerTakesAll", description: "Select Scoring Method", vartype: 5, display_order: 3)
-#Game.find_by_name("League of Legends").settings.create(name: "Seeding Method", type_opt: "Manual,Random,MultiStage", description: "Select Seeding Method", vartype: 5, display_order: 4)
-#Game.find_by_name("League of Legends").settings.create(name: "Scheduling Method", type_opt: "Elimination,RoundRobin", description: "Select Scheduling Method", vartype: 5, display_order: 5)
-
-Game.find_by_name("Chess").settings.create(name: "Time Control", description: "Enter a value for Time Control (ie. 5-5, 30, 6hr, or None)", vartype: 0, display_order: 1)
-#Game.find_by_name("Chess").settings.create(name: "Scoring Method", type_opt: "WinnerTakesAll", description: "Select Scoring Method", vartype: 5, display_order: 2)
-#Game.find_by_name("Chess").settings.create(name: "Seeding Method", type_opt: "Manual,Random,MultiStage", description: "Select Seeding Method", vartype: 5, display_order: 3)
-#Game.find_by_name("Chess").settings.create(name: "Scheduling Method", type_opt: "Elimination,RoundRobin", description: "Select Scheduling Method", vartype: 5, display_order: 4)
-
-Game.find_by_name("Hearthstone").settings.create(name: "Deck Name", description: "Enter a name for your deck, be descriptive.", vartype: 1, display_order: 1)
-#Game.find_by_name("Hearthstone").settings.create(name: "Scoring Method", type_opt: "WinnerTakesAll", description: "Select Scoring Method", vartype: 5, display_order: 2)
-#Game.find_by_name("Hearthstone").settings.create(name: "Seeding Method", type_opt: "Manual,Random,MultiStage", description: "Select Seeding Method", vartype: 5, display_order: 3)
-#Game.find_by_name("Hearthstone").settings.create(name: "Scheduling Method", type_opt: "Elimination,RoundRobin", description: "Select Scheduling Method", vartype: 5, display_order: 4)
-
-Game.find_by_name("Rock, Paper, Scissors").settings.create(name: "Favorite Object", description: "What is your favorite object in RPS?", type_opt: "Rock,Paper,Scissors", vartype: 2, display_order: 5)
-Game.find_by_name("Rock, Paper, Scissors").settings.create(name: "Lizard, Spock allowed?", description: "Will you allow Lizard and Spock?", vartype: 4, display_order: 4)
-Game.find_by_name("Rock, Paper, Scissors").settings.create(name: "Why are those up there even called radio buttons?", description: "Check boxes make sense at least", type_opt: "I do not know.,There is now spoon.,Wow.,Because electricity.,Wat?", vartype: 3, display_order: 6)
-#Game.find_by_name("Rock, Paper, Scissors").settings.create(name: "Scoring Method", type_opt: "WinnerTakesAll", description: "Select Scoring Method", vartype: 5, display_order: 1)
-#Game.find_by_name("Rock, Paper, Scissors").settings.create(name: "Seeding Method", type_opt: "Manual,Random,MultiStage", description: "Select Seeding Method", vartype: 5, display_order: 2)
-#Game.find_by_name("Rock, Paper, Scissors").settings.create(name: "Scheduling Method", type_opt: "Elimination,RoundRobin", description: "Select Scheduling Method", vartype: 5, display_order: 3)
+league = Game.create(name: "League of Legends", min_players_per_team: 5, max_players_per_team: 5, min_teams_per_match: 2, max_teams_per_match: 2, sampling_method: "riot_api")
+league.settings.create(display_order: 1, name: "Map" , description: "Select a map to play on.", vartype: GameSetting::types[:pick_one_dropdown], type_opt: "Summoners Rift,Twisted Treeline,Crystal Scar,Haunted Abyss", default: "Summoners Rift")
+league.settings.create(display_order: 2, name: "Pick type", description: "Select a pick type." , vartype: GameSetting::types[:pick_one_dropdown], type_opt: "Blind pick,Draft" , default: "Draft")
+
+chess = Game.create(name: "Chess", min_players_per_team: 1, max_players_per_team: 1, min_teams_per_match: 2, max_teams_per_match: 2, sampling_method: "Manual,Double Blind")
+chess.settings.create(display_order: 1, name: "Time Control", description: "Enter a value for Time Control (ie. 5-5, 30, 6hr, or None)", vartype: GameSetting::types[:text_short], default: "")
+
+hearthstone = Game.create(name: "Hearthstone", min_players_per_team: 1, max_players_per_team: 1, min_teams_per_match: 2, max_teams_per_match: 2, sampling_method: "Manual,Double Blind")
+hearthstone.settings.create(display_order: 1, name: "Deck name", description: "Enter a name for your deck, be descriptive.", vartype: GameSetting::types[:text_long], default: "")
+
+rockpaperscissors = Game.create(name: "Rock, Paper, Scissors", min_players_per_team: 1, max_players_per_team: 3, min_teams_per_match: 2, max_teams_per_match: 2, sampling_method: "Manual,Double Blind")
+rockpaperscissors.settings.create(display_order: 4, name: "Lizard/Spock allowed?", description: "Will you allow Lizard and Spock?" , vartype: GameSetting::types[:true_false] , default: false)
+rockpaperscissors.settings.create(display_order: 5, name: "Favorite object" , description: "What is your favorite object in RPS?", vartype: GameSetting::types[:pick_one_radio], type_opt: "Rock,Paper,Scissors", default: "Rock")
+rockpaperscissors.settings.create(display_order: 6, name: "Check boxes" , description: "Example boxes" , vartype: GameSetting::types[:pick_several] , type_opt: "I do not know,There is now spoon,Wow,Because electricity,Wat?", default: "Wow,Wat?")
if Rails.env.development?
#user 1, the ADMIN
--
cgit v1.2.3
From 70690fe168e88ad54be83e7a1ac45bdc32f1a54a Mon Sep 17 00:00:00 2001
From: AndrewMurrell
Date: Sun, 27 Apr 2014 20:13:18 -0400
Subject: Updated RR scheduling.
---
lib/scheduling/round_robin.rb | 77 ++++++++++++++++++-------------------------
1 file changed, 32 insertions(+), 45 deletions(-)
diff --git a/lib/scheduling/round_robin.rb b/lib/scheduling/round_robin.rb
index 1d9ac0d..0cbddc1 100644
--- a/lib/scheduling/round_robin.rb
+++ b/lib/scheduling/round_robin.rb
@@ -7,42 +7,53 @@ module Scheduling
end
def create_matches
- #number of teams*number of teams per match = number of matches per round
- num_teams = (tournament.players.count/tournament.min_players_per_team).floor
+ # => find the number of matches and teams to create
+ @num_teams = (tournament.players.count/tournament.min_players_per_team).floor
@matches_per_round = num_teams * tournament.min_teams_per_match
+ # => initialize data and status members
+ @team_pairs ||= {}
+ if @team_pairs.empty?
+ @matches_finished = 0
+ end
+
+ # => Create new matches
@matches_per_round.each do |match|
tournament_stage.matches.create(status: 0, submitted_peer_evaluations: 0)
end
- tournament_stage.seeding.seed_matches(tournament_stage)
+ # => seed the first time
+ if @team_pairs.empty?
+ tournament_stage.seeding.seed_matches(tournament_stage)
+ tournament_stage.matches.each {|match| match.teams.each {|team| @team_pairs += team}}
+ else
+ # => Reorder the list of teams
+ top = @team_pairs.shift
+ @team_pairs.push @team_pairs.shift
+ @team_pairs.unshift top
+
+ # => Add the teams to the matches
+ match = tournament_stage.matches[@matches_finished-1]
+ matches = 1
+ (0..@team_pairs.count-1).each do |i|
+ match.teams += @team_pairs[i]
+ if @team_pairs.count.%(tournament.min_teams_per_match).zero?
+ match = tournament_stage.matches[@matches_finished-1 + matches]
+ matches += 1
+ end
+ end
+
+ end
end
def finish_match(match)
- #declare winner of match, and store that somehow
- rotate
- return "totes worked\n"
+ @matches_finished += 1
end
def graph(current_user)
end
private
-
- def create_round_array
- #round robin should look like this.
- #NOTE: I DO NOT KNOW IF THIS IS HOW TO PROPERLY POPULATE THE ROUND ROBIN ARRAY WITH TEAMS
- @team_pairs = Array.new(num_matches)
- for i in 0..@match.teams.size
- @team_pairs.push(@match.teams[i])
- #if there is an odd number of teams, add a dummy for byes
- if @match.teams.size % 2 != 0 && i == @match.teams.size-1
- dummy = Team.create
- @team_pairs.push(dummy)
- end
- end
- end
-
def tournament_stage
@tournament_stage
end
@@ -50,29 +61,5 @@ module Scheduling
def tournament
tournament_stage.tournament
end
-
- def rotate
- #this is called when a round has completed
-
- #remove first team
- hold = @team_pairs.shift
- #rotate by 1 element
- @team_pairs.rotate!
- #place first team the front of the array
- @team_pairs.unshift(hold)
- end
-
- def mother_fuckin_winner
- scores = {}
- @teams_pairs.each do |team|
- scores[team] = team.matches.
- where(:tournament_stage => tournament_stage).
- collect{|match|match.winner==team}
- end
- weiner = scores.index(scores.max)
- scores[weiner]
- end
-
-
end
end
--
cgit v1.2.3
From b8ce4ab9ad7e6359080e894958a3181cbb3895d2 Mon Sep 17 00:00:00 2001
From: Luke Shumaker
Date: Sun, 27 Apr 2014 20:24:36 -0400
Subject: touch up tournament creation
---
app/controllers/tournaments_controller.rb | 17 ++++++++++++++---
app/models/game.rb | 4 +++-
app/models/tournament.rb | 24 +++++++++++++-----------
app/views/tournaments/_form.html.erb | 25 ++++++++++++-------------
4 files changed, 42 insertions(+), 28 deletions(-)
diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb
index 9c8ad7a..2e854a2 100644
--- a/app/controllers/tournaments_controller.rb
+++ b/app/controllers/tournaments_controller.rb
@@ -31,6 +31,17 @@ class TournamentsController < ApplicationController
# GET /tournaments/new
def new
@tournament = Tournament.new(tournament_attribute_params)
+ if @tournament.game
+ @tournament.game.settings.each do |game_setting|
+ @tournament.tournament_settings.build(
+ name: game_setting.name,
+ value: game_setting.value,
+ vartype: game_setting.vartype,
+ type_opt: game_setting.type_opt,
+ description: game_setting.description,
+ display_order: game_setting.display_order)
+ end
+ end
end
# GET /tournaments/1/edit
@@ -46,17 +57,17 @@ class TournamentsController < ApplicationController
ok = true
begin
ActiveRecord::Base.transaction do
- ok &= @tournament.save
ok &= @tournament.update(tournament_setting_params)
ok &= @tournament.hosts.push(current_user)
for i in 1..(params[:num_stages].to_i) do
begin
- ok &= @tournament.stages.create(tournament_stage_params(i))
+ ok &= @tournament.stages.build(tournament_stage_params(i))
rescue ActionController::ParameterMissing => e
ok = false
- @tournament.errors.add("stages[#{i}]", "Stage #{i} not set")
+ @tournament.errors.add("stages[#{i}]", "needs to be set")
end
end
+ ok &= @tournament.save
end
rescue ActiveRecord::RecordNotUnique => e
ok = false
diff --git a/app/models/game.rb b/app/models/game.rb
index 5f4c46d..c5cb32a 100644
--- a/app/models/game.rb
+++ b/app/models/game.rb
@@ -1,5 +1,7 @@
class Game < ActiveRecord::Base
belongs_to :parent, class_name: "Game"
has_many :children, class_name: "Game"
- has_many :settings, class_name: "GameSetting"
+ has_many :game_settings
+
+ alias_attribute :settings, :game_settings
end
diff --git a/app/models/tournament.rb b/app/models/tournament.rb
index 97eee57..a569213 100644
--- a/app/models/tournament.rb
+++ b/app/models/tournament.rb
@@ -1,11 +1,13 @@
class Tournament < ActiveRecord::Base
belongs_to :game
- has_many :stages, class_name: "TournamentStage"
+ has_many :tournament_stages
has_many :brackets
- has_many :settings_raw, class_name: "TournamentSetting"
+ has_many :tournament_settings
has_and_belongs_to_many :players, class_name: "User", association_foreign_key: "player_id", join_table: "players_tournaments"
has_and_belongs_to_many :hosts, class_name: "User", association_foreign_key: "host_id", join_table: "hosts_tournaments"
+ alias_attribute :stages, :tournament_stages
+
# Settings #################################################################
def settings
@@ -25,7 +27,7 @@ class Tournament < ActiveRecord::Base
end
def [](setting_name)
- tournament_setting = @tournament.settings_raw.find_by_name(setting_name)
+ tournament_setting = @tournament.tournament_settings.find{|s|s.name==setting_name}
if tournament_setting.nil?
return nil
else
@@ -34,13 +36,13 @@ class Tournament < ActiveRecord::Base
end
def []=(setting_name, val)
- tournament_setting = @tournament.settings_raw.find_by_name(setting_name)
+ tournament_setting = @tournament.tournament_settings.find{|s|s.name==setting_name}
if tournament_setting.nil?
game_setting = @tournament.game.settings.find_by_name(setting_name)
- @tournament.settings_raw.create(name: setting, value: val,
- vartype: game_setting.vartype,
- type_opt: game_setting.type_opt,
- description: game_setting.description,
+ @tournament.tournament_settings.build(name: setting_name, value: val,
+ vartype: game_setting.vartype,
+ type_opt: game_setting.type_opt,
+ description: game_setting.description,
display_order: game_setting.display_order)
else
tournament_setting.value = val
@@ -48,7 +50,7 @@ class Tournament < ActiveRecord::Base
end
def keys
- @tournament.settings_raw.all.collect { |x| x.name }
+ @tournament.tournament_settings.all.collect { |x| x.name }
end
def empty?() keys.empty? end
@@ -58,9 +60,9 @@ class Tournament < ActiveRecord::Base
def method_missing(name, *args)
if name.to_s.ends_with?('=')
- self[name.to_s.sub(/=$/, '').to_sym] = args.first
+ self[name.to_s.sub(/=$/, '').to_s] = args.first
else
- return self[name.to_sym]
+ return self[name.to_s]
end
end
end
diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb
index cb4c175..329fc5f 100644
--- a/app/views/tournaments/_form.html.erb
+++ b/app/views/tournaments/_form.html.erb
@@ -7,7 +7,7 @@
<%= f.label :game_id, "Select a game type" %>
<%= f.select(:game_id, Game.all.map{|game| [game.name, game.id]}) %>
- <%= submit_tag("Select", :class => "btn") %>
+ <%= f.submit("Select") %>
<% if @tournament.game.nil? %>
@@ -50,32 +50,31 @@
<% end %>
<% end %>
@@ -83,8 +82,8 @@
<%= f.fields_for :stages do |stages_fields| %>