diff options
23 files changed, 196 insertions, 157 deletions
diff --git a/app/assets/images/chess_icon.png b/app/assets/images/chess.png Binary files differindex 6bcffe6..6bcffe6 100644 --- a/app/assets/images/chess_icon.png +++ b/app/assets/images/chess.png diff --git a/app/assets/images/league_icon.gif b/app/assets/images/league_icon.gif Binary files differdeleted file mode 100644 index 1f0fa43..0000000 --- a/app/assets/images/league_icon.gif +++ /dev/null diff --git a/app/assets/images/league_of_legends.png b/app/assets/images/league_of_legends.png Binary files differnew file mode 100644 index 0000000..9a78047 --- /dev/null +++ b/app/assets/images/league_of_legends.png diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 4a20df2..8b8e86d 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -286,7 +286,7 @@ class MatchesController < ApplicationController params.require(:match).permit(:status, :tournament_stage_id, :winner_id, :remote_id, :submitted_peer_evaluations, :update_action) end - # Turn of check_edit, since our #update is flexible + # Turn of check_edit, since our #update is flexible def check_edit set_match end 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/game_setting.rb b/app/models/game_setting.rb index bff8d97..e701cae 100644 --- a/app/models/game_setting.rb +++ b/app/models/game_setting.rb @@ -1,3 +1,16 @@ class GameSetting < ActiveRecord::Base belongs_to :game + + alias_attribute :value, :default + + def self.types + return { + :text_short => 0, + :text_long => 1, + :pick_one_radio => 2, + :pick_several => 3, + :true_false => 4, + :pick_one_dropdown => 5, + } + end 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/models/tournament_setting.rb b/app/models/tournament_setting.rb index b3e6ace..9efaaea 100644 --- a/app/models/tournament_setting.rb +++ b/app/models/tournament_setting.rb @@ -1,3 +1,7 @@ class TournamentSetting < ActiveRecord::Base belongs_to :tournament + + def self.types + GameSetting.types + end end diff --git a/app/views/common/_show_tournament.html.erb b/app/views/common/_show_tournament.html.erb index a9569b6..280d59d 100644 --- a/app/views/common/_show_tournament.html.erb +++ b/app/views/common/_show_tournament.html.erb @@ -1,5 +1,6 @@ <div class="row tournament-listing"> - <div class="col-md-2 col-sm-3 col-xs-6"><%= image_tag('http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(target.hosts.first.email) + '?s=100&d=mm', class: "t-image") %> + <div class="col-md-2 col-sm-3 col-xs-6"> + <%= image_tag(target.game.name.downcase.tr(" ", "_") + ".png", class: "t-image") %> <p class="t-game"> <%= Game.find(target.game_id).name %></p> </div> <div class="col-md-8 col-sm-7 col-xs-6"> @@ -8,6 +9,7 @@ <div class="row" style="margin-left:2%;"> <div class="col-md-4 host"> Hosted by: <%= target.hosts.first.name %> + <%= image_tag('http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(target.hosts.first.email) + '?s=45&d=identicon', class: "t-image") %> </div> <div class="col-md-4 things"> <p> Players per team: <%= target.min_players_per_team %></p> diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb index 2212515..e322601 100644 --- a/app/views/tournaments/_form.html.erb +++ b/app/views/tournaments/_form.html.erb @@ -7,7 +7,7 @@ <p> <%= 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") %> </p> <% if @tournament.game.nil? %> @@ -60,32 +60,31 @@ <fieldset><legend style="color:rgb(221, 145, 37)">Settings</legend> <%= f.fields_for :settings do |setting_fields| %> - <% (@tournament.settings.empty? ? @tournament.game.settings : @tournament.settings).each do |setting| %><p> - <% name = setting.name.parameterize.underscore %> - <%= setting_fields.label name %> + <% @tournament.tournament_settings.each do |setting| %><p> + <%= setting_fields.label setting.name %> <br> <% case setting.vartype %> <% when 0 %> - <%= setting_fields.text_field( name ) %> + <%= setting_fields.text_field( setting.name ) %> <% when 1 %> - <%= setting_fields.text_area( name ) %> + <%= setting_fields.text_area( setting.name ) %> <% when 2 %> <ul> <% setting.type_opt.split(',').each do |option|%> - <li><label><%= setting_fields.radio_button( name, option ) %><%= option %></label></li> + <li><label><%= setting_fields.radio_button( setting.name, option ) %><%= option.humanize %></label></li> <% end %> </ul> <% when 3 %> <ul> <% setting.type_opt.split(',').each do |option|%> - <li><label><%= check_box_tag(name, value = option, checked = false, options = {}) %><%= option %></label></li> + <li><label><%= check_box_tag("tournament[settings][#{setting.name}][]", option, setting.value.split(',').include?(option)) %><%= option.humanize %></label></li> <% end %> </ul> <% when 4 %> - <%= setting_fields.radio_button( name, "true" ) %> True - <%= setting_fields.radio_button( name, "false" ) %> False + <%= setting_fields.radio_button( setting.name, "true" ) %> True + <%= setting_fields.radio_button( setting.name, "false" ) %> False <% when 5 %> - <%= setting_fields.select( name, setting.type_opt.split(',') ) %> + <%= setting_fields.select( setting.name, setting.type_opt.split(',') ) %> <% end %> </p><% end %> <% end %> @@ -93,8 +92,8 @@ <%= f.fields_for :stages do |stages_fields| %><fieldset><legend style="color:rgb(221, 145, 37)">Stages</legend> <label for="num_stages">Number of tournament stages</label> - <input type="number" name="num_stages" min="1" value="<%= params[:num_stages] ? params[:num_stages].to_i : 1 %>"> - <%# submit_tag("Set Stages", :class => "btn") %> + <input type="number" name="num_stages" min="1" value="<%= params[:num_stages].to_i %>"> + <%# stage_fields.submit("Set Stages") %> <% for i in 1..(params[:num_stages].to_i) do %> <p> <%= stages_fields.fields_for i.to_s do |stage_fields| %><fieldset><legend style="color:rgb(221, 145, 37)">Stage <%= i %></legend> diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index a67aed9..b408589 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -2,7 +2,7 @@ <h1> <%= @user.user_name %>'s Profile </h1> <p> - <%= image_tag 'http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(@user.email) + '?s=100&d=mm' %> + <%= image_tag 'http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(@user.email) + '?s=100&d=identicon' %> </p> <p> diff --git a/db/seeds.rb b/db/seeds.rb index f565815..c37dcf7 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: "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: "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: "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 @@ -56,35 +43,36 @@ if Rails.env.development? players_for_league = Array.new #users for our fake seeded game from the yamls - players_for_league.push(User.create(name: "Sytrie", password: "password", email: "Sytrie@gmail.com", user_name: "Sytrie", password_confirmation: "password")) - players_for_league.push(User.create(name: "Derpanator115", password: "password", email: "Derpanator115@gmail.com", user_name: "Derpanator115", password_confirmation: "password")) - players_for_league.push(User.create(name: "Wlknexe56", password: "password", email: "Wlknexe56@gmail.com", user_name: "Wlknexe56", password_confirmation: "password")) - players_for_league.push(User.create(name: "DVisionzz", password: "password", email: "DVisionzz@gmail.com", user_name: "DVisionzz", password_confirmation: "password")) - players_for_league.push(User.create(name: "HYP3RTONIC", password: "password", email: "HYP3RTONIC@gmail.com", user_name: "HYP3RTONIC", password_confirmation: "password")) - players_for_league.push(User.create(name: "M9Fumjaa", password: "password", email: "M9Fumjaa@gmail.com", user_name: "M9Fumjaa", password_confirmation: "password")) - players_for_league.push(User.create(name: "spikevsnaruto", password: "password", email: "spikevsnaruto@gmail.com", user_name: "spikevsnaruto", password_confirmation: "password")) - players_for_league.push(User.create(name: "GoogleMaSkills", password: "password", email: "GoogleMaSkills@gmail.com", user_name: "GoogleMaSkills", password_confirmation: "password")) + players_for_league.push(User.create(name: "Sytrie" , password: "password", email: "Sytrie@gmail.com" , user_name: "Sytrie" , password_confirmation: "password")) + players_for_league.push(User.create(name: "Derpanator115" , password: "password", email: "Derpanator115@gmail.com" , user_name: "Derpanator115" , password_confirmation: "password")) + players_for_league.push(User.create(name: "Wlknexe56" , password: "password", email: "Wlknexe56@gmail.com" , user_name: "Wlknexe56" , password_confirmation: "password")) + players_for_league.push(User.create(name: "DVisionzz" , password: "password", email: "DVisionzz@gmail.com" , user_name: "DVisionzz" , password_confirmation: "password")) + players_for_league.push(User.create(name: "HYP3RTONIC" , password: "password", email: "HYP3RTONIC@gmail.com" , user_name: "HYP3RTONIC" , password_confirmation: "password")) + players_for_league.push(User.create(name: "M9Fumjaa" , password: "password", email: "M9Fumjaa@gmail.com" , user_name: "M9Fumjaa" , password_confirmation: "password")) + players_for_league.push(User.create(name: "spikevsnaruto" , password: "password", email: "spikevsnaruto@gmail.com" , user_name: "spikevsnaruto" , password_confirmation: "password")) + players_for_league.push(User.create(name: "GoogleMaSkills" , password: "password", email: "GoogleMaSkills@gmail.com" , user_name: "GoogleMaSkills" , password_confirmation: "password")) players_for_league.push(User.create(name: "james chamberlan", password: "password", email: "jameschamberlan@gmail.com", user_name: "james chamberlan", password_confirmation: "password")) - players_for_league.push(User.create(name: "Kaceytron", password: "password", email: "Kaceytron@gmail.com", user_name: "Kaceytron", password_confirmation: "password")) + players_for_league.push(User.create(name: "Kaceytron" , password: "password", email: "Kaceytron@gmail.com" , user_name: "Kaceytron" , password_confirmation: "password")) #semi-real users - davis = User.create(name: "Davis Webb", password: "password", email: "davislwebb@gmail.com", user_name: "TeslasMind", password_confirmation: "password") - foy = User.create(name: "Nathaniel Foy", password: "password", email: "nfoy@notreal.com", user_name: "Nalfeinx", password_confirmation: "password") - guntas = User.create(name: "Guntas Grewal", password: "password", email: "guntasgrewal@gmail.com", user_name: "guntasgrewal", password_confirmation: "password") - luke = User.create(name: "Luke Shumaker", password: "password", email: "lukeshu@emacs4lyfe.com", user_name: "lukeshu", password_confirmation: "password") - tomer = User.create(name: "Tomer Kimia", password: "password", email: "tomer@2majors4lyfe.com", user_name: "tkimia", password_confirmation: "password") - andrew = User.create(name: "Andrew Murrell", password: "password", email: "murrel@murrel.gov", user_name: "ImFromNasa", password_confirmation: "password") - joey = User.create(name: "Joseph Adams", password: "password", email: "alpha142@fluttershyop.com", user_name: "alpha142", password_confirmation: "password") - josh = User.create(name: "Josh Huser", password: "password", email: "jhuser@iownabusiness.net", user_name: "WinterWorks", password_confirmation: "password") - dunsmore = User.create(name: "Professor Dunsmore", password: "password", email: "bxd@purdue.edu", user_name: "Dumbledore", password_confirmation: "password") - marco = User.create(name: "Marco Polo", password: "password", email: "marco@ta4lyfe.com", user_name: "iCoordinate", password_confirmation: "password") - jordan = User.create(name: "Geoffrey Webb", password: "password", email: "imnotjoffreybarathian@gameofthrones.com", user_name: "GTBPhoenix", password_confirmation: "password") - obama = User.create(name: "Obama", password: "password", email: "obama@whitehouse.gov", user_name: "Obama", password_confirmation: "password") - + davis = User.create(name: "Davis Webb" , password: "password", email: "davislwebb@gmail.com" , user_name: "TeslasMind" , password_confirmation: "password") + foy = User.create(name: "Nathaniel Foy" , password: "password", email: "nfoy@notreal.com" , user_name: "Nalfeinx" , password_confirmation: "password") + guntas = User.create(name: "Guntas Grewal" , password: "password", email: "guntasgrewal@gmail.com" , user_name: "guntasgrewal", password_confirmation: "password") + luke = User.create(name: "Luke Shumaker" , password: "password", email: "lukeshu@emacs4lyfe.com" , user_name: "lukeshu" , password_confirmation: "password") + tomer = User.create(name: "Tomer Kimia" , password: "password", email: "tomer@2majors4lyfe.com" , user_name: "tkimia" , password_confirmation: "password") + andrew = User.create(name: "Andrew Murrell" , password: "password", email: "murrel@murrel.gov" , user_name: "ImFromNasa" , password_confirmation: "password") + joey = User.create(name: "Joseph Adams" , password: "password", email: "alpha142@fluttershyop.com" , user_name: "alpha142" , password_confirmation: "password") + josh = User.create(name: "Josh Huser" , password: "password", email: "jhuser@iownabusiness.net" , user_name: "WinterWorks" , password_confirmation: "password") + dunsmore = User.create(name: "Professor Dunsmore", password: "password", email: "bxd@purdue.edu" , user_name: "Dumbledore" , password_confirmation: "password") + marco = User.create(name: "Marco Polo" , password: "password", email: "marco@ta4lyfe.com" , user_name: "iCoordinate" , password_confirmation: "password") + jordan = User.create(name: "Geoffrey Webb" , password: "password", email: "imnotjoffreybarathian@gameofthrones.com", user_name: "GTBPhoenix" , password_confirmation: "password") + obama = User.create(name: "Obama" , password: "password", email: "obama@whitehouse.gov" , user_name: "Obama" , password_confirmation: "password") #league of legends tournament - league_tourn = Tournament.create(game_id: 1, status: 0, name: "League of Legends Seed", min_players_per_team: 5, max_players_per_team: 5, min_teams_per_match: 2, - max_teams_per_match: 2, sampling_method: nil) + league_tourn = Tournament.create(game: league, status: 0, name: "League of Legends Seed", + min_players_per_team: 5, max_players_per_team: 5, + min_teams_per_match: 2, max_teams_per_match: 2, + sampling_method: "riot_api", scoring_method: "TODO") #adds players to the seeded league tournament for i in 0..9 diff --git a/lib/pairing/PairingAlgorithm.rb b/lib/pairing/PairingAlgorithm.rb deleted file mode 100644 index 81e4df6..0000000 --- a/lib/pairing/PairingAlgorithm.rb +++ /dev/null @@ -1,6 +0,0 @@ -module Pairing - class PairingAlgorithm - def self.pair(matches, players) - end - end -end diff --git a/lib/playing/.keep b/lib/playing/.keep deleted file mode 100644 index e69de29..0000000 --- a/lib/playing/.keep +++ /dev/null diff --git a/lib/sampling/README.md b/lib/sampling/README.md index 28c603e..731f1d1 100644 --- a/lib/sampling/README.md +++ b/lib/sampling/README.md @@ -1,28 +1,41 @@ -Files in this directory should be modules implementing the following +Sampling interface +================== + +Files in this directory should be _modules_ implementing the following interface: - `works_with?(Game) => Boolean` + Returns whether or not this sampling method works with the specified game. - `uses_remote?() => Boolean` + Return whether or not this sampling method requires remote IDs for users. - `set_remote_name(User, Game, String)` + Set the remote ID for a user for the specified game. It is safe to assume that this sampling method `works_with?` that game. - `get_remote_name(Object)` + When given an object from `RemoteUsername#value`, give back a human-readable/editable name to display. - `sampling_start(Match)` + Fetch the statistics for a match. + - `sampling_done?(Match) => Boolean` + Returns whether or not statistics have been completely collected yet. - `render_user_interaction(Match, User) => String` + Returns HTML to render on a page. + - `handle_user_interaction(Match, User, Hash params)` + Handles params from the form generated by `#user_interaction_render`. diff --git a/lib/scheduling/README.md b/lib/scheduling/README.md index 173b7be..8b21164 100644 --- a/lib/scheduling/README.md +++ b/lib/scheduling/README.md @@ -1,13 +1,22 @@ -Files in this directory should implement the following interface: +Scheduling interface +==================== + +Files in this directory should be _classes_ implementing the following +interface: - `initialize(tournament_stage)` - construct new Scheduling object from tournament_stage + + Construct new Scheduling object from tournament_stage. - `create_matches` - creates all the matches of the current round + + Creates all the matches of the current round. - `finish_match(match)` - progresses the match through the schedule + + Progresses the match through the schedule. - `graph` - returns a string representation of an svg image of the current stage
\ No newline at end of file + + Returns a string representation of an svg image of the current + stage. diff --git a/lib/scheduling/round_robin.rb b/lib/scheduling/round_robin.rb index 7a9e257..0cbddc1 100644 --- a/lib/scheduling/round_robin.rb +++ b/lib/scheduling/round_robin.rb @@ -7,38 +7,53 @@ module Scheduling end def create_matches - num_teams = (tournament.players.count/tournament.min_players_per_team).floor - num_matches = Float(num_teams/2)*(num_teams-1) - for i in 1..num_matches + # => 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 + + # => 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 @@ -46,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 diff --git a/lib/scoring/README.md b/lib/scoring/README.md index 95dd5e0..5beb0a2 100644 --- a/lib/scoring/README.md +++ b/lib/scoring/README.md @@ -1,10 +1,15 @@ -Files in this directory should be modules implementing the following +Scoring interface +================= + +Files in this directory should be _modules_ implementing the following interface: - `stats_needed() => Array[i]=Symbol` + Returns which statistics need to be collected for this scoring algorithm. - `score(match) => Hash[User]=Integer` + User scores for this match, assuming statistics have been collected. diff --git a/lib/seeding/README.md b/lib/seeding/README.md index 67fc19b..d323b6d 100644 --- a/lib/seeding/README.md +++ b/lib/seeding/README.md @@ -1,4 +1,10 @@ -Files in this directory should implement the following interface: +Seeding interface +================= -- seed_matches(tournament) - take the matches of a tournament and the players in a tournament, assign players to teams, and teams to matches (all must exist)
\ No newline at end of file +Files in this directory should be _modules_ implement the following +interface: + + - `seed(TournamentStage)` + + Take a tournament stage, assign players to teams and teams to + matches (matches must exist). diff --git a/lib/seeding/early_bird_seeding.rb b/lib/seeding/early_bird_seeding.rb index 30e15fc..488a1a2 100644 --- a/lib/seeding/early_bird_seeding.rb +++ b/lib/seeding/early_bird_seeding.rb @@ -1,6 +1,6 @@ module Seeding - class EarlyBirdSeeding - def seed_matches(tournament) + module EarlyBirdSeeding + def self.seed(tournament_stage) matches = tournament.current_stage.matches match = matches.first match_num = 0 @@ -17,4 +17,4 @@ module Seeding end end end -end
\ No newline at end of file +end diff --git a/lib/seeding/fair_ranked_seeding.rb b/lib/seeding/fair_ranked_seeding.rb index 4eb8c26..f56d648 100644 --- a/lib/seeding/fair_ranked_seeding.rb +++ b/lib/seeding/fair_ranked_seeding.rb @@ -1,6 +1,6 @@ module Seeding - class FairRankedSeeding - def seed_matches(tournament) + module FairRankedSeeding + def self.seed(tournament_stage) matches = tournament.current_stage.matches match = matches.first match_num = 0 @@ -19,17 +19,17 @@ module Seeding end private - def best_first(tournament) + def self.best_first(tournament) tournament.players.sort {|a, b| better(a, b, tournament) } end - def better(player1, player2, tournament) - ps1 = previousScore(player1, tournament) - ps2 = previousScore(player2, tournament) + def self.better(player1, player2, tournament) + ps1 = previous_score(player1, tournament) + ps2 = previous_score(player2, tournament) ps1 <=> ps2 end - def previousScore(player, tournament) + def self.previous_score(player, tournament) score = tournament.statistics.getStatistic(player.matches.last, player, :score) if score.nil? return 0 @@ -37,4 +37,4 @@ module Seeding score end end -end
\ No newline at end of file +end diff --git a/lib/seeding/random_seeding.rb b/lib/seeding/random_seeding.rb index ec39e61..723d70e 100644 --- a/lib/seeding/random_seeding.rb +++ b/lib/seeding/random_seeding.rb @@ -1,6 +1,6 @@ module Seeding - class RandomSeeding - def seed_matches(tournament) + module RandomSeeding + def self.seed(tournament_stage) matches = tournament.current_stage.matches match = matches.first match_num = 0 @@ -17,4 +17,4 @@ module Seeding end end end -end
\ No newline at end of file +end |