summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authortkimia <tkimia@purdue.edu>2014-04-26 16:57:26 -0400
committertkimia <tkimia@purdue.edu>2014-04-26 16:57:26 -0400
commit59d8a08232ae7872e2777ac42756fa259e1d1f6f (patch)
tree7a6f6819ca4d3226f33017c22de1e55a65e1fd6c /app
parentfedc51fb2d95d1e67c06e560448563a64fa458b1 (diff)
parent2aaaf29ae291edc34d0512ce9a812fc0de14f76b (diff)
Merge branch 'master' of https://github.com/LukeShu/leaguer
Diffstat (limited to 'app')
-rw-r--r--app/controllers/matches_controller.rb23
-rw-r--r--app/models/match.rb2
-rw-r--r--app/models/user.rb14
-rw-r--r--app/views/matches/show.html.erb34
4 files changed, 44 insertions, 29 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/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..d87f988 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -23,17 +23,23 @@ class User < ActiveRecord::Base
self.permissions ||= Server.first.default_user_permissions
end
- def scores
- self.statistics.find_by_name(:score)
+ 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 find_remote_username(game)
+ 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
diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb
index e1fe29e..7a82527 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 %>
<li><%= user.user_name %></li>
<% else %>
- <li><%= user.user_name %> - SCORE: <%= Statistic.where(:name => "score", :user => user, :match => @match).first.value %></li>
+ <% score = user.statistics.where(:name => "score", :match => @match).first %>
+ <li><%= user.user_name %> - SCORE: <%= score ? score.value : 0 %></li>
<% end %>
<% end %>
</ul></li>
@@ -76,21 +77,24 @@ function score_peers() {
<% when 1 %>
<!-- Started, waiting to finish -->
<!-- This will depend on the Sampling Method Eventually instead of always being Manual -->
- <% if @tournament.hosts.include? current_user %>
- <input type="hidden" name="update_action" value="finish">
- <% @match.teams.each do |team| %>
- <fieldset><legend>Team <%= team.id.to_s %></legend>
- <% team.users.collect{|u| u.user_name}.each do |k| %><label>
- Score for <%= k %><br>
- <% @player_score = 0 %>
- <% current_user.statistics.where(:match => @match, :user => current_user).each{ |s| @player_score+=s.value } %>
- <%= text_field_tag("scores[#{k}]", @player_score, size: 3) %>
- </label><% end %>
- </fieldset>
+
+ <% case @tournament.sampling_method %>
+ <% when "Manual" %>
+ <% if @tournament.hosts.include? current_user %>
+ <input type="hidden" name="update_action" value="finish">
+ <% @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 %>
+ <p>The match is running; the host has yet to post the scores of the match.</p>
<% end %>
- <%= submit_tag("Finish match") %>
- <% else %>
- <p>The match is running; the host has yet to post the scores of the match.</p>
+ <% when "Double Blind" %>
+ <p>Double Blind isn't implemented yet.</p>
+ <% when "RiotAPI" %>
+ <p>Riot API is being called for Statistics. Results will appear shortly.</p>
<% end %>
<% when 2 %>
<!-- Finished, waiting for peer reviews -->