From c16c1b2928d0156fc00617a6abd81f4714045e5e Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Sun, 27 Apr 2014 18:25:04 -0400 Subject: Updated Seeing and Round Robin scheduling. --- app/controllers/matches_controller.rb | 2 +- lib/scheduling/round_robin.rb | 8 ++++++-- lib/seeding/README.md | 5 +++-- lib/seeding/early_bird_seeding.rb | 2 +- lib/seeding/fair_ranked_seeding.rb | 2 +- lib/seeding/random_seeding.rb | 2 +- 6 files changed, 13 insertions(+), 8 deletions(-) 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/lib/scheduling/round_robin.rb b/lib/scheduling/round_robin.rb index 7a9e257..1d9ac0d 100644 --- a/lib/scheduling/round_robin.rb +++ b/lib/scheduling/round_robin.rb @@ -7,11 +7,15 @@ 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 - num_matches = Float(num_teams/2)*(num_teams-1) - for i in 1..num_matches + @matches_per_round = num_teams * tournament.min_teams_per_match + + @matches_per_round.each do |match| tournament_stage.matches.create(status: 0, submitted_peer_evaluations: 0) end + + tournament_stage.seeding.seed_matches(tournament_stage) end def finish_match(match) diff --git a/lib/seeding/README.md b/lib/seeding/README.md index 67fc19b..596adea 100644 --- a/lib/seeding/README.md +++ b/lib/seeding/README.md @@ -1,4 +1,5 @@ Files in this directory should implement the following 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 +- `seed(tournament_stage)` + take a tournament stage, assign players to teams and teams to + matches (matches must exist) \ No newline at end of file diff --git a/lib/seeding/early_bird_seeding.rb b/lib/seeding/early_bird_seeding.rb index 30e15fc..f3fc6f9 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) + def seed(tournament_stage) matches = tournament.current_stage.matches match = matches.first match_num = 0 diff --git a/lib/seeding/fair_ranked_seeding.rb b/lib/seeding/fair_ranked_seeding.rb index 4eb8c26..22c245e 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) + def seed(tournament_stage) matches = tournament.current_stage.matches match = matches.first match_num = 0 diff --git a/lib/seeding/random_seeding.rb b/lib/seeding/random_seeding.rb index ec39e61..bc332ef 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) + def seed(tournament_stage) matches = tournament.current_stage.matches match = matches.first match_num = 0 -- cgit v1.2.3 From 07dbbeb404dedcf9733262ae2ce9cdddc086bb0e Mon Sep 17 00:00:00 2001 From: nfoy Date: Sun, 27 Apr 2014 19:12:01 -0400 Subject: Tournament index now displays game images. Images must be named the exact name of the game and be of the .png format. --- app/assets/images/chess.png | Bin 0 -> 893 bytes app/assets/images/chess_icon.png | Bin 893 -> 0 bytes app/assets/images/league_icon.gif | Bin 8207 -> 0 bytes app/assets/images/league_of_legends.png | Bin 0 -> 10078 bytes app/views/common/_show_tournament.html.erb | 4 +++- app/views/users/show.html.erb | 2 +- 6 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 app/assets/images/chess.png delete mode 100644 app/assets/images/chess_icon.png delete mode 100644 app/assets/images/league_icon.gif create mode 100644 app/assets/images/league_of_legends.png diff --git a/app/assets/images/chess.png b/app/assets/images/chess.png new file mode 100644 index 0000000..6bcffe6 Binary files /dev/null and b/app/assets/images/chess.png differ diff --git a/app/assets/images/chess_icon.png b/app/assets/images/chess_icon.png deleted file mode 100644 index 6bcffe6..0000000 Binary files a/app/assets/images/chess_icon.png and /dev/null differ diff --git a/app/assets/images/league_icon.gif b/app/assets/images/league_icon.gif deleted file mode 100644 index 1f0fa43..0000000 Binary files a/app/assets/images/league_icon.gif and /dev/null differ diff --git a/app/assets/images/league_of_legends.png b/app/assets/images/league_of_legends.png new file mode 100644 index 0000000..9a78047 Binary files /dev/null and b/app/assets/images/league_of_legends.png differ 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 @@
-
<%= image_tag('http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(target.hosts.first.email) + '?s=100&d=mm', class: "t-image") %> +
+ <%= image_tag(target.game.name.downcase.tr(" ", "_") + ".png", class: "t-image") %>

<%= Game.find(target.game_id).name %>

@@ -8,6 +9,7 @@
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") %>

Players per team: <%= target.min_players_per_team %>

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 @@

<%= @user.user_name %>'s Profile

- <%= 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' %>

-- 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