summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortkimia <tkimia@purdue.edu>2014-04-29 16:41:35 -0400
committertkimia <tkimia@purdue.edu>2014-04-29 16:41:35 -0400
commit42d6e3b1cc05ef5172081682b53675e4827254d3 (patch)
tree240743892a6f0948774f1b89bf5bf58ed49f6416
parent0d6f7a3bfbf4c87510a1bcf967b618f98e149d49 (diff)
elimination works SOMETIMES... other times it just can't put down a damned winner
-rw-r--r--app/controllers/matches_controller.rb2
-rw-r--r--app/models/match.rb9
-rw-r--r--app/models/statistic.rb2
-rw-r--r--app/views/brackets/show.html.erb1
-rw-r--r--app/views/matches/index.html.erb9
-rw-r--r--lib/sampling/manual.html.erb30
-rw-r--r--lib/sampling/manual.rb28
-rw-r--r--lib/scheduling/elimination.rb30
-rw-r--r--lib/scoring/winner_takes_all.rb10
9 files changed, 86 insertions, 35 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index dbd3e68..f24b95d 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -39,7 +39,7 @@ class MatchesController < ApplicationController
end
when 2
# Started, waiting to finish
- @match.handle_sampling(@current_user, params)
+ @match.handle_sampling(current_user, params)
# The @match.status will be updated by Statistic's after_save hook
if @match.status == 3
notice = 'Match has finished'
diff --git a/app/models/match.rb b/app/models/match.rb
index 7b36777..65e2047 100644
--- a/app/models/match.rb
+++ b/app/models/match.rb
@@ -20,7 +20,9 @@ class Match < ActiveRecord::Base
def finished?
ok = true
tournament_stage.scoring.stats_needed.each do |stat|
- ok &= !statistics.where(match: self, name: stat).nil?
+ self.users.each do |user|
+ ok &= statistics.where(match: self, user: user, name: stat)
+ end
end
ok
end
@@ -46,6 +48,11 @@ class Match < ActiveRecord::Base
# Delagates PUT/PATCH HTTP params to the appropriate sampling
# methods.
def handle_sampling(user, params)
+ require 'pp'
+ puts('>'*80)
+ pp user
+ pp params
+ puts('<'*80)
method_classes.each do |klass|
klass.new(self).handle_user_interaction(user, params)
end
diff --git a/app/models/statistic.rb b/app/models/statistic.rb
index d62d413..8abf1f4 100644
--- a/app/models/statistic.rb
+++ b/app/models/statistic.rb
@@ -23,8 +23,8 @@ class Statistic < ActiveRecord::Base
self.match.winner = self.match.teams.find{|t| t.users.include? self.user}
end
if (self.match.status == 2) and (self.match.finished?)
- #self.match.tournament_stage.scoring.score(self.match)
self.match.status = 3
+ self.match.tournament_stage.scheduling.finish_match(self.match)
end
self.match.save!
end
diff --git a/app/views/brackets/show.html.erb b/app/views/brackets/show.html.erb
index 96eb0ec..1eabcaf 100644
--- a/app/views/brackets/show.html.erb
+++ b/app/views/brackets/show.html.erb
@@ -103,4 +103,5 @@
<% end %>
<%= submit_tag("Submit Prediction", disabled: true, id: "bracket-submit") %>
<% end %>
+
<%= link_to 'Back', tournaments_path %>
diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb
index 784d7db..e0e69b5 100644
--- a/app/views/matches/index.html.erb
+++ b/app/views/matches/index.html.erb
@@ -18,12 +18,13 @@
<td><%= "Match #{match.id}" %></td>
<td><%= match.status %></td>
<td><%= (match.winner.nil? ? "-" : "Team #{match.winner.id}") %></td>
- <td><%= link_to "Show", tournament_match_path(@tournament, match) %>
- <td> <%# If user is the host, let them start the tournment %>
- <% if @tournament.hosts.include?(current_user) %>
+ <td><%= link_to "See Match", tournament_match_path(@tournament, match) %>
+ <td>
+ <%# NOTE: - fix this permission, if split up by match, this does not work %>
+ <% if @tournament.check_permission(current_user, :edit) %>
<%= form_tag(tournament_match_path(@tournament, match), method: "put") do %>
<input type="hidden" name="update_action" value="start">
- <% @startable = (match.status == 0) and (match.teams.count >= @tournament.min_teams_per_match) %>
+ <% @startable = (match.status == 1) and (match.teams.count >= @tournament.min_teams_per_match) %>
<%= submit_tag("Start Match", :disabled => ! @startable) %>
<% end %>
<% end %>
diff --git a/lib/sampling/manual.html.erb b/lib/sampling/manual.html.erb
index 187f002..2bbd6da 100644
--- a/lib/sampling/manual.html.erb
+++ b/lib/sampling/manual.html.erb
@@ -1,12 +1,30 @@
<% if @tournament.hosts.include? @current_user %>
- <input type="hidden" name="update_action" value="finish" >
+ <fieldset><legend>Winner</legend>
+ <ul>
+ <% @match.teams.each do |team| %>
+ <li><label>
+ <input type="radio" name="manual[winner]" value="<%= team.id %>">
+ Team <%= team.id %>
+ </label></li>
+ <% end %>
+ </ul>
+ </fieldset>
<% @match.teams.each do |team| %>
- <label>
- <input type="radio", name="win", value="<%= team.id %>" >
- <%= "Team #{team.id} Won" %>
- </label>
+ <fieldset><legend>Statistics for Team <%= team.id %></legend>
+ <% team.users.each do |user| %>
+ <fieldset><legend><%= user.name %></legend>
+ <% @stats.reject{|s|s=="win"}.each do |stat| %>
+ <p>
+ <label>
+ <%= stat.titleize %>
+ <input type="numeric" name="manual[statistics][<%= user.id %>][<%= stat %>]">
+ </label>
+ </p>
+ <% end %>
+ </fieldset>
+ <% end %>
+ </fieldset>
<% end %>
- <br>
<input type="submit", value="Finish match" >
<% else %>
<p>The match is running; the host has yet to post the scores of the match.</p>
diff --git a/lib/sampling/manual.rb b/lib/sampling/manual.rb
index 01f6835..a9f9de4 100644
--- a/lib/sampling/manual.rb
+++ b/lib/sampling/manual.rb
@@ -33,7 +33,6 @@ module Sampling
def render_user_interaction(user)
@tournament = @match.tournament_stage.tournament
@current_user = user
- @users = @match.users
@stats = @match.stats_from(self.class)
require 'erb'
@@ -43,11 +42,28 @@ module Sampling
return erb.result(binding).html_safe
end
- def handle_user_interaction(user, sampling_params)
+ def handle_user_interaction(user, params)
# => Save sampling_params as statistics
- sampling_params.select {|name, value| @match.stats_from(self.class).include? name }.each do |name, value|
- Statistic.create(name: value, user: user, match: @match)
- end
- end
+ require 'pp'
+ puts('>'*80)
+ pp @match
+ puts('>'*80)
+ if (@match.tournament_stage.tournament.hosts.include? user)
+ manual_params = params.require(:manual)
+ winner = Team.find(manual_params[:winner])
+ @match.users.each do |user|
+ puts('>'*80)
+ pp "MAKING statistics BIIIIIIIITCH"
+ puts('>'*80)
+ Statistic.create(match: @match, user: user,
+ name: "win", value: winner.users.include?(user))
+ @match.stats_from(self.class).reject{|s|s=="win"}.each do |stat|
+ Statistic.create(match: @match, user: user,
+ name: stat, value: manual_params[:statistics][user.id][stat].to_i)
+ end # stats
+ end # users
+ end # permission
+ end # def
+
end
end
diff --git a/lib/scheduling/elimination.rb b/lib/scheduling/elimination.rb
index 44ce81e..a95101c 100644
--- a/lib/scheduling/elimination.rb
+++ b/lib/scheduling/elimination.rb
@@ -7,6 +7,7 @@ module Scheduling
@tournament_stage = tournament_stage
end
+
def create_matches
num_teams = (tournament.players.count/tournament.min_players_per_team).floor
num_matches = (Float(num_teams - tournament.min_teams_per_match)/(tournament.min_teams_per_match - 1)).ceil + 1
@@ -15,29 +16,42 @@ module Scheduling
end
match_num = num_matches-1
- team_num = 0
+ team_num = 1
tournament.players.shuffle
# for each grouping of min_players_per_team
tournament.players.each_slice(tournament.min_players_per_team) do |team_members|
+ # create a new team in the current match
+ tournament_stage.matches.order(:id)[match_num].teams.push(Team.create(users: team_members))
+
# if the match is full, move to the next match, otherwise move to the next team
if (team_num == tournament.min_teams_per_match)
+ tournament_stage.matches[match_num].update(status: 1);
match_num -= 1
team_num = 1
else
team_num += 1
end
- # create a new team in the current match
- tournament_stage.matches[match_num].teams.push(Team.create(users: team_members))
end
end
def finish_match(match)
+ require 'pp'
+ puts('>'*80)
+ pp match
+ puts('>'*80)
+ logBase = match.tournament_stage.tournament.min_teams_per_match
matches = match.tournament_stage.matches_ordered
cur_match_num = matches.invert[match]
unless cur_match_num == 1
- match.winner.matches.push(matches[cur_match_num/2])
+ match.winner.matches.push(matches[(cur_match_num+logBase-2)/logBase])
+ end
+ if matches[(cur_match_num+logBase-2)/logBase].teams.count == match.tournament_stage.tournament.min_teams_per_match
+ puts(80*'><')
+ puts "making the status 1"
+ puts(80*'><')
+ matches[(cur_match_num+logBase-2)/logBase].status = 1
end
end
@@ -89,16 +103,16 @@ module Scheduling
str += "\t\t<rect height=\"#{rh}%\" width=\"#{rw}%\" x=\"#{rx}%\" y=\"#{ry}%\" fill=\"url(#gradMatch)\" rx=\"5px\" stroke-width=\"2\""
case matches[i].status
when 0
- if matches[i].teams.count < @tournament_stage.tournament.min_teams_per_match
+ if matches[i].teams.count == 0
str += ' stroke="red"'
str += ' fill-opacity="0.6"'
else
- str += ' stroke="green"'
+ str += 'stroke="orange"'
end
when 1
- str += ' stroke="orange"'
+ str += ' stroke="green"'
when 2
- str += ' stroke="yellow"'
+ str += ' stroke="lightblue"'
when 3
str += ' stroke="grey"'
end
diff --git a/lib/scoring/winner_takes_all.rb b/lib/scoring/winner_takes_all.rb
index 9c83fb9..c807cba 100644
--- a/lib/scoring/winner_takes_all.rb
+++ b/lib/scoring/winner_takes_all.rb
@@ -1,22 +1,16 @@
module Scoring
module WinnerTakesAll
def self.stats_needed
- #return ["win"]
- ["win", "numDeaths", "turretsKilled", "championsKilled", "minionsKilled", "assists"]
+ return ["win"]
end
def self.score(match)
scores = {}
match.users.each do |user|
stats = Statistic.where(user: user, match: match)
- scores[user] = score_user(stats.where(name: "win").first.value)
+ scores[user] = stats.where(name: "win").first.value ? 1 : 0
end
scores
end
-
- private
- def self.score_user(win)
- win.nil? ? 0.5 : win ? 1 : 0
- end
end
end