From 442146c7160b95d452975336dfddaf8faf74d544 Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Sun, 27 Apr 2014 14:22:17 -0400 Subject: fixed, seeds, roundrobin, and _show_tourn --- app/controllers/tournaments_controller.rb | 23 +++------- app/views/common/_show_tournament.html.erb | 2 +- app/views/tournaments/_form.html.erb | 2 +- db/seeds.rb | 18 ++++---- lib/scheduling/round_robin.rb | 74 ++++++++++++++++++++++++++++++ lib/scheduling/roundrobin.rb | 74 ------------------------------ 6 files changed, 92 insertions(+), 101 deletions(-) create mode 100644 lib/scheduling/round_robin.rb delete mode 100644 lib/scheduling/roundrobin.rb diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb index 8752298..c212273 100644 --- a/app/controllers/tournaments_controller.rb +++ b/app/controllers/tournaments_controller.rb @@ -15,7 +15,8 @@ class TournamentsController < ApplicationController when 0 render action: 'show' when 1 - redirect_to tournament_matches_path(@tournament) + #redirect_to tournament_matches_page(@tournament) + redirect_to "/tournaments/" + @tournament.id.to_s + "/matches" when 2 redirect_to tournaments_page end @@ -50,20 +51,11 @@ class TournamentsController < ApplicationController 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)) - rescue ActionController::ParameterMissing => e - ok = false - @tournament.errors.add("stages[#{i}]", "Stage #{i} not set") - end + ok &= @tournament.stages.create(tournament_stage_params(i)) end end - rescue ActiveRecord::RecordNotUnique => e - ok = false - @tournament.errors.add(:name, "must be unique") - rescue => e + rescue ok = false - @tournament.errors.add(:exception, "Unknown error: ``#{e.class.name}'' -- #{e.inspect} -- #{e.methods - Object.new.methods}") end respond_to do |format| if ok @@ -134,7 +126,7 @@ class TournamentsController < ApplicationController ActiveRecord::Base.transaction do success &= @tournament.save && sched = tournament_attribute_params[:type_opt] - success &= @tournament.stages.create(scheduling: sched) + success &= @tournament.stages.create(scheduling_method: sched) success &= @tournament.stages.first.create_matches end if success @@ -179,9 +171,8 @@ class TournamentsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def tournament_attribute_params - params[:num_stages] ||= 1 if params[:tournament] - p = params.require(:tournament).permit(:game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :sampling_method, :scoring_method) + p = params.require(:tournament).permit(:game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method, :scoring_method) if p[:game_id] game = Game.find(p[:game_id]) p[:min_players_per_team] ||= game.min_players_per_team @@ -207,7 +198,7 @@ class TournamentsController < ApplicationController end def tournament_stage_params(i) - params.require(:tournament).require(:stages).require(i.to_s).permit(:scheduling_method, :seeding_method) + params.require(:tournament).require(i.to_sym).permit(:scheduling_method, :seeding_method) end def is_owner?(object) diff --git a/app/views/common/_show_tournament.html.erb b/app/views/common/_show_tournament.html.erb index b16a37b..a9569b6 100644 --- a/app/views/common/_show_tournament.html.erb +++ b/app/views/common/_show_tournament.html.erb @@ -14,7 +14,7 @@

Players signed up: <%= target.players.count %>

-

<%= (target.randomized_teams)? "Teams are Random" : "Teams are Chosen" %>

+

<%# (target.randomized_teams)? "Teams are Random" : "Teams are Chosen" %>

Players signed up: <%= target.players.count %>

diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb index 28d9c27..cb4c175 100644 --- a/app/views/tournaments/_form.html.erb +++ b/app/views/tournaments/_form.html.erb @@ -84,7 +84,7 @@ <%= f.fields_for :stages do |stages_fields| %>
Stages - <%= submit_tag("Set Stages", :class => "btn") %> + <%# submit_tag("Set Stages", :class => "btn") %> <% for i in 1..(params[:num_stages].to_i) do %> <%= stages_fields.fields_for i.to_s do |stage_fields| %>
Stage <%= i %> <%= stage_fields.label :scheduling_method %> diff --git a/db/seeds.rb b/db/seeds.rb index 0d77208..f565815 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -9,10 +9,10 @@ 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, set_rounds: nil, randomized_teams: true, 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, set_rounds: nil, randomized_teams: true, 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, set_rounds: 1, randomized_teams: false, 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, set_rounds: nil, randomized_teams: false, sampling_method: "Manual,Double Blind") +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) @@ -84,7 +84,7 @@ if Rails.env.development? #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, set_rounds: 1, randomized_teams: true, sampling_method: nil) + max_teams_per_match: 2, sampling_method: nil) #adds players to the seeded league tournament for i in 0..9 @@ -97,7 +97,7 @@ if Rails.env.development? #chess chess_tourn = Tournament.create(game_id: 2, status: 0, name: "Chess Seed", min_players_per_team: 1, max_players_per_team: 1, min_teams_per_match: 2, - max_teams_per_match: 2, set_rounds: 1, randomized_teams: true, sampling_method: nil) + max_teams_per_match: 2, sampling_method: nil) chess_tourn.hosts.push(davis) chess_tourn.join(davis) @@ -105,7 +105,7 @@ if Rails.env.development? #Rock Paper Scissors rps = Tournament.create(game_id: 4, status: 0, name: "Rock, Paper, Scissors Seed", min_players_per_team: 1, max_players_per_team: 3, min_teams_per_match: 2, - max_teams_per_match: 2, set_rounds: 1, randomized_teams: true, sampling_method: nil) + max_teams_per_match: 2, sampling_method: nil) rps.hosts.push(davis) rps.join(davis) @@ -113,7 +113,7 @@ if Rails.env.development? rps.join(guntas) tourn5 = Tournament.create(game_id: 1, status: 0, name: "5 Teams, 2 Teams Per Match", min_players_per_team: 1, max_players_per_team: 1, min_teams_per_match: 2, - max_teams_per_match: 2, set_rounds: 1, randomized_teams: true, sampling_method: nil) + max_teams_per_match: 2, sampling_method: nil) for i in 0..9 if i == 0 @@ -124,7 +124,7 @@ if Rails.env.development? tourn5.join(players_for_league[9]) tourn6 = Tournament.create(game_id: 1, status: 0, name: "3 teams per match", min_players_per_team: 1, max_players_per_team: 1, min_teams_per_match: 3, - max_teams_per_match: 3, set_rounds: 1, randomized_teams: true, sampling_method: nil) + max_teams_per_match: 3, sampling_method: nil) for i in 0..9 if i == 0 diff --git a/lib/scheduling/round_robin.rb b/lib/scheduling/round_robin.rb new file mode 100644 index 0000000..7a9e257 --- /dev/null +++ b/lib/scheduling/round_robin.rb @@ -0,0 +1,74 @@ +module Scheduling + class RoundRobin + include Rails.application.routes.url_helpers + + def initialize(tournament_stage) + @tournament_stage = tournament_stage + 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 + tournament_stage.matches.create(status: 0, submitted_peer_evaluations: 0) + end + end + + def finish_match(match) + #declare winner of match, and store that somehow + rotate + return "totes worked\n" + 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 + + 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/scheduling/roundrobin.rb b/lib/scheduling/roundrobin.rb deleted file mode 100644 index 7a9e257..0000000 --- a/lib/scheduling/roundrobin.rb +++ /dev/null @@ -1,74 +0,0 @@ -module Scheduling - class RoundRobin - include Rails.application.routes.url_helpers - - def initialize(tournament_stage) - @tournament_stage = tournament_stage - 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 - tournament_stage.matches.create(status: 0, submitted_peer_evaluations: 0) - end - end - - def finish_match(match) - #declare winner of match, and store that somehow - rotate - return "totes worked\n" - 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 - - 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-54-g00ecf