From 241fced528cecfc4c181c24b3563d56d81bf44a9 Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Tue, 22 Apr 2014 17:39:11 -0400 Subject: Added default PairingAlgorithm --- lib/pairing/PairingAlgorithm.rb | 6 ++++++ lib/playing/.keep | 0 2 files changed, 6 insertions(+) create mode 100644 lib/pairing/PairingAlgorithm.rb create mode 100644 lib/playing/.keep diff --git a/lib/pairing/PairingAlgorithm.rb b/lib/pairing/PairingAlgorithm.rb new file mode 100644 index 0000000..778e2ae --- /dev/null +++ b/lib/pairing/PairingAlgorithm.rb @@ -0,0 +1,6 @@ +module Leaguer + class PairingAlgorithm + def pair(matches, players) + end + end +end diff --git a/lib/playing/.keep b/lib/playing/.keep new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3-2-g168b From 42aa0fe7fdfc51f79cda90c4d71621a797995a6c Mon Sep 17 00:00:00 2001 From: guntasgrewal Date: Tue, 22 Apr 2014 17:41:11 -0400 Subject: Did a thing --- lib/pairing/PairingAlgorithm.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pairing/PairingAlgorithm.rb b/lib/pairing/PairingAlgorithm.rb index 778e2ae..c3d7f7b 100644 --- a/lib/pairing/PairingAlgorithm.rb +++ b/lib/pairing/PairingAlgorithm.rb @@ -1,6 +1,6 @@ module Leaguer class PairingAlgorithm - def pair(matches, players) + def self.pair(matches, players) end end end -- cgit v1.2.3-2-g168b From bb53f8ac2ab52301b32fe65ddc10a32f6bc730e8 Mon Sep 17 00:00:00 2001 From: tkimia Date: Tue, 22 Apr 2014 17:42:57 -0400 Subject: prelim search --- app/controllers/search_controller.rb | 11 ++++++++++ app/views/common/_show_tournament.html.erb | 32 ++++++++++++++++++++++++++++ app/views/layouts/application.html.erb | 12 ++++++++--- app/views/search/go.html.erb | 6 ++++++ app/views/tournaments/index.html.erb | 34 +----------------------------- config/routes.rb | 6 ++++++ 6 files changed, 65 insertions(+), 36 deletions(-) create mode 100644 app/views/common/_show_tournament.html.erb create mode 100644 app/views/search/go.html.erb diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index ee61487..9da649d 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -1,2 +1,13 @@ class SearchController < ApplicationController + + def go + @query = params[:query] + + if (@query.nil?) return; + + @tournaments = Tournament.where("name LIKE '#{@query}'") + @players = User.where("name LIKE '#{@query}") + + end + end diff --git a/app/views/common/_show_tournament.html.erb b/app/views/common/_show_tournament.html.erb new file mode 100644 index 0000000..89d8f53 --- /dev/null +++ b/app/views/common/_show_tournament.html.erb @@ -0,0 +1,32 @@ +
+
<%= image_tag ('http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(target.hosts.first.email) + '?s=100&d=mm') %>
+
+ <%# "header" %> + <%= link_to(target) do %>

<%= target.name %>

<% end %> +
+
+ Hosted by: <%= target.hosts.first.name %> +
+
+

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

+

Players signed up: <%= target.players.count %>

+
+
+

<%= (target.randomized_teams)? "Teams are Random" : "Teams are Chosen" %>

+

Players signed up: <%= target.players.count %>

+
+
+
+
+ <% if signed_in? %> + <% if !target.players.include?(current_user) %> + <%= form_tag(tournament_path(target), method: "put") do %> + + <%= submit_tag("Join")%> + <% end %> + <% else %> +

You've signed up for this tournament!

+ <% end %> + <% end %> +
+
\ No newline at end of file diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index e6b5b25..fb5c1c5 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -13,15 +13,20 @@ BetterDragSort.makeListSortable(document.getElementById("boxes")); }; -
+
<% if notice %>

<%= notice %>

<% end %> diff --git a/app/views/search/go.html.erb b/app/views/search/go.html.erb new file mode 100644 index 0000000..12a76c8 --- /dev/null +++ b/app/views/search/go.html.erb @@ -0,0 +1,6 @@ +

Showing results for: <%= @query %>

+ + +<% if @tounaments.empty? and @players.empty %> +

No results found for "<%= @query %>"

+<% else %> \ No newline at end of file diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb index eef9577..129f3de 100644 --- a/app/views/tournaments/index.html.erb +++ b/app/views/tournaments/index.html.erb @@ -4,39 +4,7 @@ <% if @tournaments.length > 0 %> <%# Each tournament has a div for its listing %> <% @tournaments.each do |t| %> -
-
<%= image_tag 'http://www.gravatar.com/avatar/' + Digest::MD5.hexdigest(t.hosts.first.email) + '?s=100&d=mm' %>
-
- <%# "header" %> - <%= link_to(t) do %>

<%= t.name %>

<% end %> -
-
- Hosted by: <%= t.hosts.first.name %> -
-
-

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

-

Players signed up: <%= t.players.count %>

-
-
-

<%= (t.randomized_teams)? "Teams are Random" : "Teams are Chosen" %>

-

Players signed up: <%= t.players.count %>

-
-
-
-
- <% if signed_in? %> - <% if !t.players.include?(current_user) %> - <%= form_tag(tournament_path(t), method: "put") do %> - - <%= submit_tag("Join") - %> - <% end %> - <% else %> -

You've signed up for this tournament!

- <% end %> - <% end %> -
-
+ <%= render "common/show_tournament", :target => t %> <% end %> <% else %>

No tournaments going on right now... diff --git a/config/routes.rb b/config/routes.rb index f94bd2f..c1bbf52 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -24,8 +24,14 @@ Leaguer::Application.routes.draw do end root to: 'static#homepage' + get '/testsvg', to: 'static#test' + + get '/search', to: 'search#go' + end + + Leaguer::Application.routes.named_routes.module.module_eval do def match_path(match, options={}) tournament_match_path(match.tournament_stage.tournament, match, options) -- cgit v1.2.3-2-g168b From 266602ea1e97d886f031b80add7a760034221f76 Mon Sep 17 00:00:00 2001 From: tkimia Date: Tue, 22 Apr 2014 18:04:41 -0400 Subject: basic search complete --- app/controllers/search_controller.rb | 8 +++++--- app/views/search/go.html.erb | 25 +++++++++++++++++++++---- app/views/tournaments/index.html.erb | 4 ++++ 3 files changed, 30 insertions(+), 7 deletions(-) diff --git a/app/controllers/search_controller.rb b/app/controllers/search_controller.rb index 9da649d..51aee9e 100644 --- a/app/controllers/search_controller.rb +++ b/app/controllers/search_controller.rb @@ -3,10 +3,12 @@ class SearchController < ApplicationController def go @query = params[:query] - if (@query.nil?) return; + if (@query.nil?) then + return + end - @tournaments = Tournament.where("name LIKE '#{@query}'") - @players = User.where("name LIKE '#{@query}") + @tournaments = Tournament.where("name LIKE '%#{@query}%'") + @players = User.where("name LIKE '%#{@query}%'") end diff --git a/app/views/search/go.html.erb b/app/views/search/go.html.erb index 12a76c8..6d5826f 100644 --- a/app/views/search/go.html.erb +++ b/app/views/search/go.html.erb @@ -1,6 +1,23 @@ -

Showing results for: <%= @query %>

+<%# Show search results if a query was not nill %> +<% if !@query.empty? %> +

Showing results for: <%= @query %>

+ <% if @tournaments.empty? and @players.empty? %> +

No results found for "<%= @query %>"

+ <% else %> + <% if @tournaments.length > 0 %> +

Tournaments

+ <% end %> + <% @tournaments.each do |t| %> + <%= render "common/show_tournament", :target => t %> + <% end %> -<% if @tounaments.empty? and @players.empty %> -

No results found for "<%= @query %>"

-<% else %> \ No newline at end of file + <% if @players.length > 0 %> +

Players

+ <% end %> + <% @players.each do |p| %> + <%= render "common/show_player", :target => p %> + <% end %> + + <% end %> +<% end %> \ No newline at end of file diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb index 129f3de..06e1b25 100644 --- a/app/views/tournaments/index.html.erb +++ b/app/views/tournaments/index.html.erb @@ -2,16 +2,20 @@
<% if @tournaments.length > 0 %> + <%# Each tournament has a div for its listing %> <% @tournaments.each do |t| %> <%= render "common/show_tournament", :target => t %> <% end %> + <% else %> +

No tournaments going on right now... <% if current_user.can?(:create_tournament) %> Why not start your own? <% end %>

+ <% end %>
-- cgit v1.2.3-2-g168b From 7deb9c1c7acadf9a5b638313f51ba9dc60624672 Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Tue, 22 Apr 2014 18:17:13 -0400 Subject: made naming conventions consistent --- lib/scoring/FibonacciPeerWithBlowout.rb | 16 ---------------- lib/scoring/MarginalPeer.rb | 15 --------------- lib/scoring/ScoringAlgorithm.rb | 8 -------- lib/scoring/WinnerTakesAll.rb | 16 ---------------- lib/scoring/fibonacci_peer_with_blowout.rb | 16 ++++++++++++++++ lib/scoring/marginal_peer.rb | 15 +++++++++++++++ lib/scoring/scoring_algorithm.rb | 8 ++++++++ lib/scoring/winner_takes_all.rb | 16 ++++++++++++++++ 8 files changed, 55 insertions(+), 55 deletions(-) delete mode 100644 lib/scoring/FibonacciPeerWithBlowout.rb delete mode 100644 lib/scoring/MarginalPeer.rb delete mode 100644 lib/scoring/ScoringAlgorithm.rb delete mode 100644 lib/scoring/WinnerTakesAll.rb create mode 100644 lib/scoring/fibonacci_peer_with_blowout.rb create mode 100644 lib/scoring/marginal_peer.rb create mode 100644 lib/scoring/scoring_algorithm.rb create mode 100644 lib/scoring/winner_takes_all.rb diff --git a/lib/scoring/FibonacciPeerWithBlowout.rb b/lib/scoring/FibonacciPeerWithBlowout.rb deleted file mode 100644 index 19ac9a7..0000000 --- a/lib/scoring/FibonacciPeerWithBlowout.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'ScoringAlgorithm' - -class FibonacciPeerWithBlowout < ScoringAlgorithm - - 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) - 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) - end -end \ No newline at end of file diff --git a/lib/scoring/MarginalPeer.rb b/lib/scoring/MarginalPeer.rb deleted file mode 100644 index 0e1cfa8..0000000 --- a/lib/scoring/MarginalPeer.rb +++ /dev/null @@ -1,15 +0,0 @@ -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)) - end - scores - end - - def self.score(rating) - rating - end -end \ No newline at end of file diff --git a/lib/scoring/ScoringAlgorithm.rb b/lib/scoring/ScoringAlgorithm.rb deleted file mode 100644 index 6277da8..0000000 --- a/lib/scoring/ScoringAlgorithm.rb +++ /dev/null @@ -1,8 +0,0 @@ -module Leaguer - module Scoring - class ScoringAlgorithm - def self.score(match, interface) - end - end - end -end \ No newline at end of file diff --git a/lib/scoring/WinnerTakesAll.rb b/lib/scoring/WinnerTakesAll.rb deleted file mode 100644 index ad2471b..0000000 --- a/lib/scoring/WinnerTakesAll.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'ScoringAlgorithm' - -class WinnerTakesAll < ScoringAlgorithm - - def self.score(match, interface) - match.players.each do |player| - scores[player.user_name] = scoreUser(match.win?(player)) - end - scores - end - - - def self.score(win) - win.nil? ? 0.5 : win ? 1 : 0 - end -end \ No newline at end of file diff --git a/lib/scoring/fibonacci_peer_with_blowout.rb b/lib/scoring/fibonacci_peer_with_blowout.rb new file mode 100644 index 0000000..19ac9a7 --- /dev/null +++ b/lib/scoring/fibonacci_peer_with_blowout.rb @@ -0,0 +1,16 @@ +require 'ScoringAlgorithm' + +class FibonacciPeerWithBlowout < ScoringAlgorithm + + 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) + 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) + end +end \ No newline at end of file diff --git a/lib/scoring/marginal_peer.rb b/lib/scoring/marginal_peer.rb new file mode 100644 index 0000000..0e1cfa8 --- /dev/null +++ b/lib/scoring/marginal_peer.rb @@ -0,0 +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)) + end + scores + end + + def self.score(rating) + rating + end +end \ No newline at end of file diff --git a/lib/scoring/scoring_algorithm.rb b/lib/scoring/scoring_algorithm.rb new file mode 100644 index 0000000..6277da8 --- /dev/null +++ b/lib/scoring/scoring_algorithm.rb @@ -0,0 +1,8 @@ +module Leaguer + module Scoring + class ScoringAlgorithm + def self.score(match, interface) + end + end + end +end \ No newline at end of file diff --git a/lib/scoring/winner_takes_all.rb b/lib/scoring/winner_takes_all.rb new file mode 100644 index 0000000..ad2471b --- /dev/null +++ b/lib/scoring/winner_takes_all.rb @@ -0,0 +1,16 @@ +require 'ScoringAlgorithm' + +class WinnerTakesAll < ScoringAlgorithm + + def self.score(match, interface) + match.players.each do |player| + scores[player.user_name] = scoreUser(match.win?(player)) + end + scores + end + + + def self.score(win) + win.nil? ? 0.5 : win ? 1 : 0 + end +end \ No newline at end of file -- cgit v1.2.3-2-g168b