diff options
-rw-r--r-- | app/controllers/matches_controller.rb | 37 | ||||
-rw-r--r-- | app/views/matches/show.html.erb | 20 | ||||
-rw-r--r-- | db/seeds.rb | 24 | ||||
-rw-r--r-- | lib/scheduling/elimination.rb | 1 | ||||
-rw-r--r-- | lib/scheduling/roundrobin.rb | 42 |
5 files changed, 79 insertions, 45 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index b1b283b..6709a53 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -168,6 +168,10 @@ class MatchesController < ApplicationController def update case params[:update_action] when "start" + # + # Redirect to the current match page for this tournament with the correct sampling view rendered + # + @match.status = 1 respond_to do |format| if @match.save @@ -180,15 +184,30 @@ class MatchesController < ApplicationController end when "finish" + # + # Get the winner and blowout status from the params given by the correct sampling view + # + + + #in general + #provide contribution + #if all contributions are in, update statistics + + #make this use the statistics interface for scoring and ScoringAlgorithms @match.winner = @match.teams.find_by_id(params['winner']) - @match.blowout = false + @match.statistics.create(name: "blowout", user: nil, value: 0) - @match.statistics['Score'] = @tournament.settings['ScoringMethod'].constantize.score(@match, @match.statistics) -=begin + #How to access the blowout statistic of a match: + @match.statistics.where(:name => "blowout").first.value + + + #@match.statistics.create(name: 'score', value: @tournament.settings.where(:name => 'Scoring Method').value.constantize.score(@match, @match.statistics) + +=begin # Individual scores #scores = params["scores"] #scores.each do |user_name, score| @@ -233,6 +252,10 @@ class MatchesController < ApplicationController end end when "peer" + # + # Update user scores via scoring method + # + order = params[:review_action] base_score = 2 next_score = 3 @@ -262,10 +285,14 @@ class MatchesController < ApplicationController end end when "reset" - @match.status = 0 + # + # Reset Match Status to 1 in case something needs to be replayed. + # + + @match.status = 1 respond_to do |format| if @match.save - format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Match Status Reset to 0' } + format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Match Status Reset to 1' } format.json { head :no_content } else format.html { redirect_to @tournament, notice: "You don't have permission to start this match." } diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index 7a82527..8344a7a 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -78,24 +78,8 @@ function score_peers() { <!-- Started, waiting to finish --> <!-- This will depend on the Sampling Method Eventually instead of always being Manual --> - <% case @tournament.sampling_method %> - <% when "Manual" %> - <% if @tournament.hosts.include? current_user %> - <input type="hidden" name="update_action" value="finish"> - <% @match.teams.each do |team| %> - <%= tag :input, {"type" => "radio", "name" => "winner", "value" => "#{team.id}" } %> - <%= "Team #{team.id} Won" %> - <% end %> - <%= submit_tag("Finish match") %> - <%= @tournament.settings['ScoringMethod'] %> - <% else %> - <p>The match is running; the host has yet to post the scores of the match.</p> - <% end %> - <% when "Double Blind" %> - <p>Double Blind isn't implemented yet.</p> - <% when "RiotAPI" %> - <p>Riot API is being called for Statistics. Results will appear shortly.</p> - <% end %> + <%= raw @match.tournament_stage.tournament.sampling_method.camelcase.constantize.render_user_interaction(@match, current_user) %> + <% when 2 %> <!-- Finished, waiting for peer reviews --> <input type="hidden" name="update_action" value="peer"> diff --git a/db/seeds.rb b/db/seeds.rb index 0917afc..3b98070 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -16,26 +16,26 @@ Game.create(name: "Rock, Paper, Scissors", min_players_per_team: 1, max_players_ 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("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("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("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) +#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) if Rails.env.development? #user 1, the ADMIN diff --git a/lib/scheduling/elimination.rb b/lib/scheduling/elimination.rb index bf752b6..074cb5c 100644 --- a/lib/scheduling/elimination.rb +++ b/lib/scheduling/elimination.rb @@ -34,6 +34,7 @@ module Scheduling end def match_finished(match) + #what in the goddamn fuck does this mean matches = match.tournament_stage.matches_ordered cur_match_num = matches.invert[match] unless cur_match_num == 1 diff --git a/lib/scheduling/roundrobin.rb b/lib/scheduling/roundrobin.rb index e2db2cf..e149860 100644 --- a/lib/scheduling/roundrobin.rb +++ b/lib/scheduling/roundrobin.rb @@ -7,35 +7,57 @@ module Scheduling end def create_matches - num_teams = (self.tournament.players.count/self.tournament.min_players_per_team).floor - num_matches = (num_teams* Float(num_teams-1)/2).ceil + 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 - #round robin should look like this + 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 - #team_pairs needs populated with the team objects and im not sure how to do that end #this is called when a round has completed def rotate + #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) - # for j in 0..4 - # puts "#{array[j]}, #{array[j+(array.size/2)-1]}" - # end - # puts "\n\n" + + 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 def match_finished(match) - + #declare winner of match, and store that somehow + rotate + return "totes worked\n" end def graph(current_user) - + end end end |