summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--app/controllers/tournaments_controller.rb13
-rw-r--r--app/controllers/users_controller.rb17
-rw-r--r--app/models/remote_username.rb2
-rw-r--r--app/views/tournaments/_selected.html.erb9
-rw-r--r--app/views/tournaments/new.html.erb2
-rw-r--r--app/views/users/show.html.erb8
-rw-r--r--db/seeds.rb2
-rw-r--r--lib/scoring/.FibonacciPeerWithBlowout.rb.swpbin12288 -> 0 bytes
-rw-r--r--lib/scoring/fibonacci_peer_with_blowout.rb29
-rw-r--r--lib/scoring/marginal_peer.rb24
-rw-r--r--lib/scoring/scoring_algorithm.rb6
-rw-r--r--lib/scoring/winner_takes_all.rb28
13 files changed, 89 insertions, 52 deletions
diff --git a/.gitignore b/.gitignore
index 830e151..c9926d1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,3 +24,4 @@ nohup.out
*#
.#*
.nfs*
+.*.swp
diff --git a/app/controllers/tournaments_controller.rb b/app/controllers/tournaments_controller.rb
index 03dc5b8..b276368 100644
--- a/app/controllers/tournaments_controller.rb
+++ b/app/controllers/tournaments_controller.rb
@@ -32,7 +32,11 @@ class TournamentsController < ApplicationController
# GET /tournaments/new
def new
@games = Game.all
- @tournament = Tournament.new(game: Game.find_by_id(params[:game]))
+ if params[:tournament]
+ @tournament = Tournament.new(game: Game.find(params[:tournament][:game_id]))
+ else
+ @tournament = Tournament.new()
+ end
end
# GET /tournaments/1/edit
@@ -146,7 +150,12 @@ class TournamentsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through.
def tournament_params
- params.require(:tournament).permit(:game, :game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method)
+ permitted = [:game_id, :status, :name, :min_players_per_team, :max_players_per_team, :min_teams_per_match, :max_teams_per_match, :set_rounds, :randomized_teams, :sampling_method]
+ if params[:tournament][:game_id]
+ game = Game.find(params[:tournament][:game_id])
+ permitted.push(:settings => game.settings.collect{|s| s.name})
+ end
+ params.require(:tournament).permit(permitted)
end
def is_owner?(object)
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index c3261b8..cfa5d67 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1,5 +1,8 @@
class UsersController < ApplicationController
+ require 'httparty'
+ require 'json'
+
# GET /users
# GET /users.json
@@ -74,6 +77,20 @@ class UsersController < ApplicationController
end
end
+ def set_remote
+ game = Game.find_by_name("League of Legends")
+
+ remote_username = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/by-name/#{@name.downcase}?api_key=ad539f86-22fd-474d-9279-79a7a296ac38")
+
+ remote = @user.find_remote_username(game)
+ if remote.nil?
+ @user.remote_username.create(game: game, value: remote_username)
+ else
+ remote.value = remote_username
+ remote.save
+ end
+ end
+
private
# Use callbacks to share common setup or constraints between actions.
def set_user
diff --git a/app/models/remote_username.rb b/app/models/remote_username.rb
index e5d0a8c..c2c3d20 100644
--- a/app/models/remote_username.rb
+++ b/app/models/remote_username.rb
@@ -9,4 +9,4 @@ class RemoteUsername < ActiveRecord::Base
def value=(v)
self.json_value = v.to_json
end
-end
+end
diff --git a/app/views/tournaments/_selected.html.erb b/app/views/tournaments/_selected.html.erb
index 4efd17a..9240c49 100644
--- a/app/views/tournaments/_selected.html.erb
+++ b/app/views/tournaments/_selected.html.erb
@@ -2,18 +2,17 @@
<%= render "common/error_messages", :target => @tournament %>
<%= f.hidden_field(:game_id) %>
- <% @game = Game.find(params[:game]) %>
<% @tournament.attributes.each do |name, value| %>
<% if (name == "id") or (name =~ /.*_at$/) or (name == "game_id") or (name == "status") or (name == "set_rounds") %>
<% next %>
<% end %>
<p>
<%= f.label name %><br>
- <% unless @game.attributes[name].nil? %>
+ <% unless @tournament.game.attributes[name].nil? %>
<% if name == "sampling_method" %>
- <%= f.select( name, @game.sampling_method.split(',') ) %>
+ <%= f.select( name, @tournament.game.sampling_method.split(',') ) %>
<% else %>
- <%= f.text_field(name, :value => @game.attributes[name] ) %>
+ <%= f.text_field(name, :value => @tournament.game.attributes[name] ) %>
<% end %>
<% else %>
<%= f.text_field name %>
@@ -22,7 +21,7 @@
<% end %>
<%= fields_for "tournament[settings]", @tournament.settings do |setting_fields| %>
- <% @game.settings.each do |setting| %>
+ <% @tournament.game.settings.each do |setting| %>
<p>
<%= setting_fields.label setting.name %>
<br>
diff --git a/app/views/tournaments/new.html.erb b/app/views/tournaments/new.html.erb
index c2b9904..2837708 100644
--- a/app/views/tournaments/new.html.erb
+++ b/app/views/tournaments/new.html.erb
@@ -1,7 +1,7 @@
<h1>New Tournament</h1>
<%= form_tag(new_tournament_path, method: "get") do %>
- <%= select_tag('game',
+ <%= select_tag('tournament[game_id]',
options_from_collection_for_select(@games, 'id', 'name', @tournament.game.nil? || @tournament.game.id),
:prompt => "Select a Game Type") %>
<%= submit_tag("Select", :class => "btn") %>
diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb
index b85cbda..81eee6f 100644
--- a/app/views/users/show.html.erb
+++ b/app/views/users/show.html.erb
@@ -20,6 +20,14 @@
too single
</p>
+<p>
+ <%= label :username %><br>
+ <%= text_field %>
+
+ <br><input type="submit" value="Submit"><br>
+
+</p>
+
<div class="row">
<div class="col-md-6">
<h3> Recent Tournaments Played </h3>
diff --git a/db/seeds.rb b/db/seeds.rb
index e0c2800..7b8709c 100644
--- a/db/seeds.rb
+++ b/db/seeds.rb
@@ -12,7 +12,7 @@ Server.create(default_user_permissions: p[:join_tournament] | p[:create_pm])
Game.create(name: "League of Legends",min_players_per_team: 5, max_players_per_team: 5, min_teams_per_match: 2, max_teams_per_match: 2, set_rounds: nil, randomized_teams: true, sampling_method: "Manual,Double Blind,RiotAPI")
Game.create(name: "Chess", min_players_per_team: 1, max_players_per_team: 1, min_teams_per_match: 2, max_teams_per_match: 2, set_rounds: nil, randomized_teams: true, sampling_method: "Manual,Double Blind")
Game.create(name: "Hearthstone", min_players_per_team: 1, max_players_per_team: 1, min_teams_per_match: 2, max_teams_per_match: 2, set_rounds: 1, randomized_teams: false, sampling_method: "Manual,Double Blind")
-Game.create(name: "Rock, Paper, Scissors", min_players_per_team: 1, max_players_per_team: 3, min_teams_per_match: 1, max_teams_per_match: nil, set_rounds: nil, randomized_teams: false, sampling_method: "Manual,Double Blind")
+Game.create(name: "Rock, Paper, Scissors", min_players_per_team: 1, max_players_per_team: 3, min_teams_per_match: 2, max_teams_per_match: 2, set_rounds: nil, randomized_teams: false, sampling_method: "Manual,Double Blind")
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)
diff --git a/lib/scoring/.FibonacciPeerWithBlowout.rb.swp b/lib/scoring/.FibonacciPeerWithBlowout.rb.swp
deleted file mode 100644
index 49504ab..0000000
--- a/lib/scoring/.FibonacciPeerWithBlowout.rb.swp
+++ /dev/null
Binary files differ
diff --git a/lib/scoring/fibonacci_peer_with_blowout.rb b/lib/scoring/fibonacci_peer_with_blowout.rb
index 19ac9a7..8043fb7 100644
--- a/lib/scoring/fibonacci_peer_with_blowout.rb
+++ b/lib/scoring/fibonacci_peer_with_blowout.rb
@@ -1,16 +1,21 @@
-require 'ScoringAlgorithm'
-
-class FibonacciPeerWithBlowout < ScoringAlgorithm
+module Scoring
+ module FibonacciPeerWithBlowout
+ def stats_needed
+ return [:votes]
+ end
- def self.score(match, interface)
- match.players.each do |player|
- scores[player.user_name] = scoreUser(interface.getStatistic(match, player, :votes), match.win?(player), match.blowout)
+ def score(match, interface)
+ scores = {}
+ match.players.each do |player|
+ scores[player.user_name] = score_user(interface.get_statistic(match, player, :votes), match.win?(player), match.blowout)
+ end
+ scores
end
- scores
- end
- def self.scoreUser(votes, win, blowout)
- fibonacci = Hash.new { |h,k| h[k] = k < 2 ? k : h[k-1] + h[k-2] }
- fibonacci[votes+3] + (win ? blowout ? 12 : 10 : blowout ? 5 : 7)
+ private
+ def score_user(votes, win, blowout)
+ fibonacci = Hash.new { |h,k| h[k] = k < 2 ? k : h[k-1] + h[k-2] }
+ fibonacci[votes+3] + (win ? blowout ? 12 : 10 : blowout ? 5 : 7)
+ end
end
-end \ No newline at end of file
+end
diff --git a/lib/scoring/marginal_peer.rb b/lib/scoring/marginal_peer.rb
index 0e1cfa8..13e1796 100644
--- a/lib/scoring/marginal_peer.rb
+++ b/lib/scoring/marginal_peer.rb
@@ -1,15 +1,15 @@
-require 'ScoringAlgorithm'
-
-class MarginalPeer < ScoringAlgorithm
-
- def self.score(match, interface)
- match.players.each do |player|
- scores[player.user_name] = scoreUser(interface.getStatistic(match, player, rating))
+module Scoring
+ module MarginalPeer
+ def stats_needed
+ return [:rating]
end
- scores
- end
- def self.score(rating)
- rating
+ def score(match, interface)
+ scores = {}
+ match.players.each do |player|
+ scores[player.user_name] = interface.get_statistic(match, player, :rating)
+ end
+ scores
+ end
end
-end \ No newline at end of file
+end
diff --git a/lib/scoring/scoring_algorithm.rb b/lib/scoring/scoring_algorithm.rb
deleted file mode 100644
index f2afa6f..0000000
--- a/lib/scoring/scoring_algorithm.rb
+++ /dev/null
@@ -1,6 +0,0 @@
-module Scoring
- class ScoringAlgorithm
- def self.score(match, interface)
- end
- end
-end
diff --git a/lib/scoring/winner_takes_all.rb b/lib/scoring/winner_takes_all.rb
index ad2471b..517dfd6 100644
--- a/lib/scoring/winner_takes_all.rb
+++ b/lib/scoring/winner_takes_all.rb
@@ -1,16 +1,20 @@
-require 'ScoringAlgorithm'
-
-class WinnerTakesAll < ScoringAlgorithm
-
- def self.score(match, interface)
- match.players.each do |player|
- scores[player.user_name] = scoreUser(match.win?(player))
+module Scoring
+ module WinnerTakesAll
+ def stats_needed
+ return []
end
- scores
- end
+ def score(match, interface)
+ scores = {}
+ match.players.each do |player|
+ scores[player.user_name] = score_user(match.win?(player))
+ end
+ scores
+ end
- def self.score(win)
- win.nil? ? 0.5 : win ? 1 : 0
+ private
+ def score_user(win)
+ win.nil? ? 0.5 : win ? 1 : 0
+ end
end
-end \ No newline at end of file
+end