diff options
author | nfoy <nfoy@purdue.edu> | 2014-04-23 20:41:03 -0400 |
---|---|---|
committer | nfoy <nfoy@purdue.edu> | 2014-04-23 20:41:03 -0400 |
commit | 9afd5a4f7a86eeaab3fa8a0c25609ac7977e0489 (patch) | |
tree | 8d47adc08a58a8936e2026f30852f877ee47cf64 | |
parent | 422a7b39a06e2fe54415f2be08548021a981e8a8 (diff) | |
parent | 7ff82b901705475f97e277a9f3f31756bd3ce948 (diff) |
Merge branch 'master' of https://github.com/LukeShu/leaguer
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | app/assets/stylesheets/custom.css.scss | 13 | ||||
-rw-r--r-- | app/assets/stylesheets/scaffolds.css.scss | 2 | ||||
-rw-r--r-- | app/assets/stylesheets/tournaments.css.scss | 10 | ||||
-rw-r--r-- | app/controllers/search_controller.rb | 19 | ||||
-rw-r--r-- | app/controllers/tournaments_controller.rb | 13 | ||||
-rw-r--r-- | app/controllers/users_controller.rb | 17 | ||||
-rw-r--r-- | app/models/remote_username.rb | 2 | ||||
-rw-r--r-- | app/views/common/_show_tournament.html.erb | 4 | ||||
-rw-r--r-- | app/views/common/_show_user.html.erb | 4 | ||||
-rw-r--r-- | app/views/search/go.html.erb | 16 | ||||
-rw-r--r-- | app/views/tournaments/_selected.html.erb | 9 | ||||
-rw-r--r-- | app/views/tournaments/new.html.erb | 4 | ||||
-rw-r--r-- | app/views/users/show.html.erb | 8 | ||||
-rw-r--r-- | db/seeds.rb | 2 | ||||
-rw-r--r-- | lib/scoring/.FibonacciPeerWithBlowout.rb.swp | bin | 12288 -> 0 bytes | |||
-rw-r--r-- | lib/scoring/fibonacci_peer_with_blowout.rb | 29 | ||||
-rw-r--r-- | lib/scoring/marginal_peer.rb | 24 | ||||
-rw-r--r-- | lib/scoring/scoring_algorithm.rb | 6 | ||||
-rw-r--r-- | lib/scoring/winner_takes_all.rb | 28 |
20 files changed, 150 insertions, 61 deletions
@@ -24,3 +24,4 @@ nohup.out *# .#* .nfs* +.*.swp diff --git a/app/assets/stylesheets/custom.css.scss b/app/assets/stylesheets/custom.css.scss index d299dda..4104235 100644 --- a/app/assets/stylesheets/custom.css.scss +++ b/app/assets/stylesheets/custom.css.scss @@ -1,5 +1,11 @@ @import "bootstrap"; +$page-color: #444; +$toolbar-color: black; +$orange: #DD9125; +$darker-orange: #9D4102; +$link-yellow: #FFC50D; + header > nav { @extend .navbar; @extend .navbar-inverse; @@ -41,6 +47,13 @@ input[type="text"], input[type="password"]{ margin: 0 0 5px 0; } +select { + background-color: #333; + padding: 5px; + border: none; + color: #DD9125 !important; +} + p.errors { background-color: rgba(0,0,0,0.5);; color: red; diff --git a/app/assets/stylesheets/scaffolds.css.scss b/app/assets/stylesheets/scaffolds.css.scss index e8fe9c5..eb1f751 100644 --- a/app/assets/stylesheets/scaffolds.css.scss +++ b/app/assets/stylesheets/scaffolds.css.scss @@ -19,7 +19,7 @@ body { height: 100%; } -h1, h2, h3, h4, h5, p, li{ +h1, h2, h3, h4, h5, p, li, label{ color: $orange; } diff --git a/app/assets/stylesheets/tournaments.css.scss b/app/assets/stylesheets/tournaments.css.scss index 41d6023..cc55253 100644 --- a/app/assets/stylesheets/tournaments.css.scss +++ b/app/assets/stylesheets/tournaments.css.scss @@ -75,6 +75,16 @@ div.tournament-listing { padding: 5px 0 0 0; } } + + .t-game{ + font-weight: bold; + text-align: center; + } + + .t-image{ + display: block; + margin:auto; + } } div.leave-buttons { diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 51aee9e..d312623 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -1,13 +1,28 @@ class SearchController < ApplicationController def go + stringMade = false; + @games = Game.all @query = params[:query] + @gametype = params[:game_type] - if (@query.nil?) then + if ( @gametype.nil? and (@query.nil? or @query.empty?)) then return end - @tournaments = Tournament.where("name LIKE '%#{@query}%'") + qstring = "" + if (!@query.empty?) + qstring += "name LIKE '%#{@query}%'" + stringMade = true + end + if (!@gametype.nil? and !@gametype.empty?) + if (stringMade) + qstring += " AND " + end + qstring += "game_id=#{@gametype}" + end + + @tournaments = Tournament.where(qstring) @players = User.where("name LIKE '%#{@query}%'") end 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/common/_show_tournament.html.erb b/app/views/common/_show_tournament.html.erb index 89d8f53..0f60fad 100644 --- a/app/views/common/_show_tournament.html.erb +++ b/app/views/common/_show_tournament.html.erb @@ -1,5 +1,7 @@ <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') %></div> + <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") %> + <p class="t-game"> <%= Game.find(target.game_id).name %></p> + </div> <div class="col-md-8 col-sm-7 col-xs-6"> <%# "header" %> <%= link_to(target) do %><h3><%= target.name %></h3><% end %> diff --git a/app/views/common/_show_user.html.erb b/app/views/common/_show_user.html.erb index 70f1ca4..dd136a0 100644 --- a/app/views/common/_show_user.html.erb +++ b/app/views/common/_show_user.html.erb @@ -1,8 +1,8 @@ <div class="row user-listing"> - <div class="col-md-3 col-sm-3 col-xs-6"><%= image_tag ('http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(target.email) + '?s=100&d=mm') %></div> + <div class="col-md-3 col-sm-4 col-xs-4"><%= image_tag ('http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(target.email) + '?s=100&d=mm') %></div> - <div class="col-md-9 col-sm-9 col-xs-6"> + <div class="col-md-9 col-sm-8 col-xs-8"> <%# "header" %> <%= link_to(target) do %><h3><%= target.user_name %></h3><% end %> diff --git a/app/views/search/go.html.erb b/app/views/search/go.html.erb index d2bf8f3..ea2dabf 100644 --- a/app/views/search/go.html.erb +++ b/app/views/search/go.html.erb @@ -4,12 +4,24 @@ </div> <div class="expanded"> <h5><a href="#collapse">Advanced Search [hide]</a></h5> - <p>This is where the advancedsearch will go.</p> + <%= form_tag("/search", method: "get") do %> + <div class="form-group"> + <%= label_tag :query, 'Find:' %> + <%= text_field_tag(:query, params[:query]) %> + </div> + <div class="form-group"> + <%= label_tag :game_type, 'Game Type:' %> + <%= select_tag(:game_type, options_from_collection_for_select(@games, 'id', 'name'), :prompt => 'All Games') %> + </div> + <div> + <%= submit_tag("Search", :name=>nil) %> + </div> + <% end %> </div> </div> <%# Show search results if a query was not nill %> -<% if !@query.empty? %> +<% if !@query.nil? and !@query.empty? %> <% if @tournaments.empty? and @players.empty? %> <h3> No results found for "<%= @query %>" </h3> 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 8c74068..2837708 100644 --- a/app/views/tournaments/new.html.erb +++ b/app/views/tournaments/new.html.erb @@ -1,10 +1,10 @@ <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 btn-success btn-xs") %> + <%= submit_tag("Select", :class => "btn") %> <% end %> <div id='ajax-form'> 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 Binary files differdeleted file mode 100644 index 49504ab..0000000 --- a/lib/scoring/.FibonacciPeerWithBlowout.rb.swp +++ /dev/null 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 |