diff options
author | Luke Shumaker <shumakl@purdue.edu> | 2014-04-27 20:24:51 -0400 |
---|---|---|
committer | Luke Shumaker <shumakl@purdue.edu> | 2014-04-27 20:24:51 -0400 |
commit | 2bc378643564451b872a52fdcf97d7ee8afa2108 (patch) | |
tree | a72f280e8cfbf267d83647f4e3e0605895e3672e | |
parent | dedb63d770af24eee6e73289499ba22ec607cbf2 (diff) | |
parent | 8891daf9f1b38dadd5d5873fd3703d246876cabc (diff) |
Merge branch 'master' of https://github.com/LukeShu/leaguer
-rw-r--r-- | app/assets/images/chess.png (renamed from app/assets/images/chess_icon.png) | bin | 893 -> 893 bytes | |||
-rw-r--r-- | app/assets/images/league_icon.gif | bin | 8207 -> 0 bytes | |||
-rw-r--r-- | app/assets/images/league_of_legends.png | bin | 0 -> 10078 bytes | |||
-rw-r--r-- | app/controllers/matches_controller.rb | 2 | ||||
-rw-r--r-- | app/views/common/_show_tournament.html.erb | 4 | ||||
-rw-r--r-- | app/views/users/show.html.erb | 2 | ||||
-rw-r--r-- | lib/scheduling/round_robin.rb | 81 | ||||
-rw-r--r-- | lib/seeding/README.md | 5 | ||||
-rw-r--r-- | lib/seeding/early_bird_seeding.rb | 2 | ||||
-rw-r--r-- | lib/seeding/fair_ranked_seeding.rb | 2 | ||||
-rw-r--r-- | lib/seeding/random_seeding.rb | 2 |
11 files changed, 47 insertions, 53 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/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/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/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/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 |