From 86992e85220e9a42ed498497ca733e39fb7266fc Mon Sep 17 00:00:00 2001 From: guntasgrewal Date: Thu, 24 Apr 2014 21:46:10 -0400 Subject: seeds and elimination small changes --- db/seeds.rb | 19 +++++++++++++++++++ lib/scheduling/elimination.rb | 17 +++++++++-------- lib/scheduling/roundrobin.rb | 24 ++++++++++++++++++++++++ lib/scoring/ScoringAlgorithm.rb | 6 ++++++ 4 files changed, 58 insertions(+), 8 deletions(-) create mode 100644 lib/scheduling/roundrobin.rb create mode 100644 lib/scoring/ScoringAlgorithm.rb diff --git a/db/seeds.rb b/db/seeds.rb index 78c8ea0..7628efe 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -138,6 +138,25 @@ if Rails.env.development? tourn6.join(guntas) tourn6.join(luke) tourn6.join(marco) +=begin + hash1 = {:username => "TeslasMind", :id => id} + hash2 = {:username => "Alpha142", :id => id} + hash3 = {:username => "ImFromNasa", :id => id} + hash4 = {:username => "NalfeinX", :id => id} + hash5 = {:username => "GTBPhoenix", :id => id} + hash6 = {:username => , :id => id} + hash7 = {:username => username, :id => id} + hash8 = {:username => username, :id => id} + hash9 = {:username => username, :id => id} + hash10 = {:username => username, :id => id} + +FOR ROUNG ROBIN + +http://stackoverflow.com/questions/6648512/scheduling-algorithm-for-a-round-robin-tournament + + +=end + end diff --git a/lib/scheduling/elimination.rb b/lib/scheduling/elimination.rb index 0e93f7a..543df52 100644 --- a/lib/scheduling/elimination.rb +++ b/lib/scheduling/elimination.rb @@ -7,14 +7,6 @@ module Scheduling @tournament_stage = tournament_stage end - def tournament_stage - @tournament_stage - end - - def tournament - self.tournament_stage.tournament - end - def create_matches num_teams = (self.tournament.players.count/self.tournament.min_players_per_team).floor num_matches = (Float(num_teams - tournament.min_teams_per_match)/(tournament.min_teams_per_match - 1)).ceil + 1 @@ -138,5 +130,14 @@ STRING return str end + private + + def tournament_stage + @tournament_stage + end + + def tournament + self.tournament_stage.tournament + end end end diff --git a/lib/scheduling/roundrobin.rb b/lib/scheduling/roundrobin.rb new file mode 100644 index 0000000..e050c41 --- /dev/null +++ b/lib/scheduling/roundrobin.rb @@ -0,0 +1,24 @@ + +module Scheduling + class RoundRobin + include Rails.application.routes.url_helpers + + def initialize(tournament_stage) + @tournament_stage = tournament_stage + end + + def create_matches + num_teams = (self.tournament.players.count/self.tournament.min_players_per_team).floor + num_matches = Float(num_teams/2)*(num_teams-1) + + end + + def match_finished(match) + + end + + def graph(current_user) + + end + end +end diff --git a/lib/scoring/ScoringAlgorithm.rb b/lib/scoring/ScoringAlgorithm.rb new file mode 100644 index 0000000..f2afa6f --- /dev/null +++ b/lib/scoring/ScoringAlgorithm.rb @@ -0,0 +1,6 @@ +module Scoring + class ScoringAlgorithm + def self.score(match, interface) + end + end +end -- cgit v1.1-4-g5e80 From e1ef99a9ade5723c7bc65977546b4e1fdaab9688 Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Thu, 24 Apr 2014 21:55:49 -0400 Subject: Mixed things up a bit on the matches controller and show view. --- app/controllers/matches_controller.rb | 23 ++++++++++++++--------- app/views/matches/show.html.erb | 34 +++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 138cf28..b1b283b 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -55,7 +55,6 @@ class MatchesController < ApplicationController @purp = purple @blue = blue - end def get_riot_info_fake @@ -151,8 +150,7 @@ class MatchesController < ApplicationController @purp = purple @blue = blue - - end #end def + end # GET /tournaments/1/matches/1 # GET /tournaments/1/matches/1.json @@ -184,13 +182,18 @@ class MatchesController < ApplicationController #make this use the statistics interface for scoring and ScoringAlgorithms + @match.winner = @match.teams.find_by_id(params['winner']) + @match.blowout = false + @match.statistics['Score'] = @tournament.settings['ScoringMethod'].constantize.score(@match, @match.statistics) + +=begin # Individual scores - scores = params["scores"] - scores.each do |user_name, score| - Statistic.create(user: User.find_by_user_name(user_name), match: @match, name: "score", value: score.to_i) - end + #scores = params["scores"] + #scores.each do |user_name, score| + # Statistic.create(user: User.find_by_user_name(user_name), match: @match, name: "score", value: score.to_i) + #end # Team scores (processing for manual) team_scores = {} @@ -208,6 +211,7 @@ class MatchesController < ApplicationController #unless cur_match_num == 1 # @match.winner.matches.push(@tournament.matches_ordered[cur_match_num/2]) #end +=end # Skip peer evaluation if there aren't enough players per team peer = false @@ -218,12 +222,13 @@ class MatchesController < ApplicationController end @match.status = peer ? 2 : 3 + respond_to do |format| if @match.save format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Peer evaluation started.' } format.json { head :no_content } else - format.html { redirect_to @tournament, notice: "You don't have permission to start this match." } + format.html { redirect_to @tournament, notice: "Permission denied" } format.json { render json: "Permission denied", status: :forbidden } end end @@ -273,7 +278,6 @@ class MatchesController < ApplicationController format.json { render json: @tournament.errors, status: :unprocessable_entity } end end - end private @@ -282,6 +286,7 @@ class MatchesController < ApplicationController @match = Match.find(params[:id]) @tournament = @match.tournament_stage.tournament end + def set_tournament @tournament = Tournament.find(params[:tournament_id]) end diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index e1fe29e..2ec0ea6 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -47,7 +47,8 @@ function score_peers() { <% if @match.status <= 1 %>
  • <%= user.user_name %>
  • <% else %> -
  • <%= user.user_name %> - SCORE: <%= Statistic.where(:name => "score", :user => user, :match => @match).first.value %>
  • + <% score = Statistic.where(:name => "score", :user => user, :match => @match).first%> +
  • <%= user.user_name %> - SCORE: <%= score ? score.value : 0 %>
  • <% end %> <% end %> @@ -76,21 +77,24 @@ function score_peers() { <% when 1 %> - <% if @tournament.hosts.include? current_user %> - - <% @match.teams.each do |team| %> -
    Team <%= team.id.to_s %> - <% team.users.collect{|u| u.user_name}.each do |k| %><% end %> -
    + + <% case @tournament.sampling_method %> + <% when "Manual" %> + <% if @tournament.hosts.include? current_user %> + + <% @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 %> +

    The match is running; the host has yet to post the scores of the match.

    <% end %> - <%= submit_tag("Finish match") %> - <% else %> -

    The match is running; the host has yet to post the scores of the match.

    + <% when "Double Blind" %> +

    Double Blind isn't implemented yet.

    + <% when "RiotAPI" %> +

    Riot API is being called for Statistics. Results will appear shortly.

    <% end %> <% when 2 %> -- cgit v1.1-4-g5e80 From 63a665823b8f05bf0b3a9acf9b18cc01252951fb Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 25 Apr 2014 11:03:55 -0400 Subject: Touch up s/scores/statistics/ --- app/models/match.rb | 2 +- app/models/user.rb | 4 ---- app/views/matches/show.html.erb | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/app/models/match.rb b/app/models/match.rb index 20a36a5..9045d67 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -1,6 +1,6 @@ class Match < ActiveRecord::Base belongs_to :tournament_stage - has_many :scores + has_many :statistics has_and_belongs_to_many :teams belongs_to :winner, class_name: "Team" diff --git a/app/models/user.rb b/app/models/user.rb index e5ae7ea..5aca8a6 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -23,10 +23,6 @@ class User < ActiveRecord::Base self.permissions ||= Server.first.default_user_permissions end - def scores - self.statistics.find_by_name(:score) - end - def find_remote_username(game) obj = self.remote_usernames.where(:game => game).first if obj.nil? diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index e1fe29e..e87ce5d 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -47,7 +47,7 @@ function score_peers() { <% if @match.status <= 1 %>
  • <%= user.user_name %>
  • <% else %> -
  • <%= user.user_name %> - SCORE: <%= Statistic.where(:name => "score", :user => user, :match => @match).first.value %>
  • +
  • <%= user.user_name %> - SCORE: <%= user.statistics.where(:name => "score", :match => @match).first.value %>
  • <% end %> <% end %> -- cgit v1.1-4-g5e80 From 0f0974ffdffcd98665f7e36293813e68e0668bcf Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 25 Apr 2014 11:16:20 -0400 Subject: Use Figaro for configuration --- .gitignore | 8 +++++++- Gemfile | 2 ++ Gemfile.lock | 4 ++++ config/application.example.yml | 3 +++ config/initializers/secret_token.rb | 6 +++++- 5 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 config/application.example.yml diff --git a/.gitignore b/.gitignore index c9926d1..0859f70 100644 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,13 @@ /log/*.log /tmp -# The above is from Rails. The following is from Luke. +# The above is from Rails. + +# The next lines are from `rails generate figaro:install` +# Ignore application configuration +/config/application.yml + +# The rest is from Luke. /vendor/bundle nohup.out # As noted above, you probably want to add the following to your global git config. diff --git a/Gemfile b/Gemfile index 5a5be8b..5a6b98d 100644 --- a/Gemfile +++ b/Gemfile @@ -52,6 +52,8 @@ gem 'delayed_job_active_record' # Mailboxer supports a messaging and alerting system. gem 'mailboxer' +gem 'figaro' + group :doc do # bundle exec rake doc:rails generates the API under doc/api. gem 'sdoc', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 145a7fc..2de3fea 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -50,6 +50,9 @@ GEM delayed_job (>= 3.0, < 4.1) erubis (2.7.0) execjs (2.0.2) + figaro (0.7.0) + bundler (~> 1.0) + rails (>= 3, < 5) foreigner (1.6.1) activerecord (>= 3.0.0) hike (1.2.3) @@ -143,6 +146,7 @@ DEPENDENCIES coffee-rails (~> 4.0.0) daemons delayed_job_active_record + figaro httparty jbuilder (~> 1.2) jquery-rails diff --git a/config/application.example.yml b/config/application.example.yml new file mode 100644 index 0000000..a98b40e --- /dev/null +++ b/config/application.example.yml @@ -0,0 +1,3 @@ +SECRET_TOKEN: 'cc884af613d0dd093f1d6c9153abac1200c5a0db923613245b80c5c3f5e9c9f9ba51712b702f2d494a22ddea8ab40601b38a41eb39eec97b50a7a2e37748b1bc' +RIOT_API_KEY: 'ad539f86-22fd-474d-9279-79a7a296ac38' +RIOT_API_REGION: 'na' diff --git a/config/initializers/secret_token.rb b/config/initializers/secret_token.rb index 604d43d..fbab4b9 100644 --- a/config/initializers/secret_token.rb +++ b/config/initializers/secret_token.rb @@ -9,4 +9,8 @@ # Make sure your secret_key_base is kept private # if you're sharing your code publicly. -Leaguer::Application.config.secret_key_base = 'cc884af613d0dd093f1d6c9153abac1200c5a0db923613245b80c5c3f5e9c9f9ba51712b702f2d494a22ddea8ab40601b38a41eb39eec97b50a7a2e37748b1bc' +Leaguer::Application.config.secret_key_base = if Rails.env.development? or Rails.env.test? + ('x' * 30) # meets minimum requirement of 30 chars long +else + ENV['SECRET_TOKEN'] +end -- cgit v1.1-4-g5e80 From d3cfd8683e842ce60ba339d6e6c7342738ec4cf8 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 25 Apr 2014 11:18:11 -0400 Subject: Make User#{find,get,set}_remote_username symetric with get/set --- app/models/user.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 5aca8a6..d87f988 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -23,13 +23,23 @@ class User < ActiveRecord::Base self.permissions ||= Server.first.default_user_permissions end - def find_remote_username(game) + def set_remote_username(game, data) + remote = self.remote_usernames.where(:game => game).first + if remote.nil? + self.remote_usernames.create(game: game, value: data) + else + remote.value = data + remote.save + end + end + + def get_remote_username(game) obj = self.remote_usernames.where(:game => game).first if obj.nil? if game.parent.nil? return nil else - return find_remote_username(game.parent) + return get_remote_username(game.parent) end else return obj.value -- cgit v1.1-4-g5e80 From 426c916c62d5ff28742821e482f291c5cecc0f64 Mon Sep 17 00:00:00 2001 From: DavisLWebb Date: Fri, 25 Apr 2014 12:36:52 -0400 Subject: Added the round robin algorithm. Its based on array rotations. The array needs to be properly populated (I'm not sure how to add the teams to the array) --- lib/scheduling/roundrobin.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/lib/scheduling/roundrobin.rb b/lib/scheduling/roundrobin.rb index e050c41..a3a75c9 100644 --- a/lib/scheduling/roundrobin.rb +++ b/lib/scheduling/roundrobin.rb @@ -11,6 +11,23 @@ module Scheduling num_teams = (self.tournament.players.count/self.tournament.min_players_per_team).floor num_matches = Float(num_teams/2)*(num_teams-1) + #round robin should look like this + @team_pairs = Array.new(num_matches) + #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 + + for i in 0..@team_pairs-2 + hold = @team_pairs.shift + @team_pairs.rotate! + @team_pairs.unshift(hold) + # for j in 0..4 + # puts "#{array[j]}, #{array[j+(array.size/2)-1]}" + # end + # puts "\n\n" + end end def match_finished(match) -- cgit v1.1-4-g5e80 From ef45245dda03b5bba3d66432ed814fdec1f51af3 Mon Sep 17 00:00:00 2001 From: DavisLWebb Date: Fri, 25 Apr 2014 12:47:37 -0400 Subject: I think I properly populated the teams into the @teams_pair array. Its in roundRobin.rb. Someone may want to check to make sure I did it right. --- lib/scheduling/roundrobin.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/scheduling/roundrobin.rb b/lib/scheduling/roundrobin.rb index a3a75c9..ffac9b6 100644 --- a/lib/scheduling/roundrobin.rb +++ b/lib/scheduling/roundrobin.rb @@ -1,4 +1,3 @@ - module Scheduling class RoundRobin include Rails.application.routes.url_helpers @@ -13,6 +12,9 @@ module Scheduling #round robin should look like this @team_pairs = Array.new(num_matches) + for i in 0..@match.teams.size + @team_pairs.push(@match.teams[i] + end #team_pairs needs populated with the team objects and im not sure how to do that end -- cgit v1.1-4-g5e80 From 2aaaf29ae291edc34d0512ce9a812fc0de14f76b Mon Sep 17 00:00:00 2001 From: DavisLWebb Date: Fri, 25 Apr 2014 12:48:29 -0400 Subject: fixed a dumb mistake --- lib/scheduling/roundrobin.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/scheduling/roundrobin.rb b/lib/scheduling/roundrobin.rb index ffac9b6..10af20e 100644 --- a/lib/scheduling/roundrobin.rb +++ b/lib/scheduling/roundrobin.rb @@ -20,16 +20,14 @@ module Scheduling #this is called when a round has completed def rotate - - for i in 0..@team_pairs-2 - hold = @team_pairs.shift - @team_pairs.rotate! - @team_pairs.unshift(hold) + hold = @team_pairs.shift + @team_pairs.rotate! + @team_pairs.unshift(hold) # for j in 0..4 # puts "#{array[j]}, #{array[j+(array.size/2)-1]}" # end # puts "\n\n" - end + end def match_finished(match) -- cgit v1.1-4-g5e80