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(-) (limited to 'lib') 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-54-g00ecf From b71747c6c8b24ab8144a3fc412cc2d385406c512 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 27 Apr 2014 20:26:10 -0400 Subject: clean lib/seeding/README.md --- lib/seeding/README.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/seeding/README.md b/lib/seeding/README.md index 596adea..d323b6d 100644 --- a/lib/seeding/README.md +++ b/lib/seeding/README.md @@ -1,5 +1,10 @@ -Files in this directory should implement the following interface: +Seeding interface +================= -- `seed(tournament_stage)` - take a tournament stage, assign players to teams and teams to - matches (matches 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). -- cgit v1.2.3-54-g00ecf From 9d0be853cef35412c0bfe92c80502fd9da7947f1 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sun, 27 Apr 2014 20:29:22 -0400 Subject: Fix namespacing in lib/seeding --- lib/seeding/early_bird_seeding.rb | 6 +++--- lib/seeding/fair_ranked_seeding.rb | 16 ++++++++-------- lib/seeding/random_seeding.rb | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) (limited to 'lib') diff --git a/lib/seeding/early_bird_seeding.rb b/lib/seeding/early_bird_seeding.rb index f3fc6f9..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(tournament_stage) + 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 22c245e..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(tournament_stage) + 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 bc332ef..723d70e 100644 --- a/lib/seeding/random_seeding.rb +++ b/lib/seeding/random_seeding.rb @@ -1,6 +1,6 @@ module Seeding - class RandomSeeding - def seed(tournament_stage) + 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 -- cgit v1.2.3-54-g00ecf