diff options
author | AndrewMurrell <amurrel@purdue.edu> | 2014-04-29 00:59:48 -0400 |
---|---|---|
committer | AndrewMurrell <amurrel@purdue.edu> | 2014-04-29 00:59:48 -0400 |
commit | 35700a053bb802efd01ac0b6d0ebefa0723d7817 (patch) | |
tree | ab379631e1b19dd77e66db6236e5bb1b6ecef6df /app/models | |
parent | a1814bcfddcf2178ef5ccf35d95bc0917f9409fc (diff) | |
parent | cd0c7d73be76feffbaaea9200c485b2316604469 (diff) |
Merge branch 'master' of http://github.com/LukeShu/leaguer
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/bracket.rb | 23 | ||||
-rw-r--r-- | app/models/bracket_match.rb | 4 | ||||
-rw-r--r-- | app/models/match.rb | 6 | ||||
-rw-r--r-- | app/models/statistic.rb | 2 |
4 files changed, 32 insertions, 3 deletions
diff --git a/app/models/bracket.rb b/app/models/bracket.rb index acd33ca..48414c3 100644 --- a/app/models/bracket.rb +++ b/app/models/bracket.rb @@ -4,8 +4,29 @@ class Bracket < ActiveRecord::Base has_many :bracket_matches def create_matches - tournament.stages.first.matches.each do |m| + tournament.stages.order(:id).first.matches.order(:id).each do |m| bracket_matches.create(match: m) end end + + + def predict_winners(predictions) + require 'pp' + puts("<"*80) + pp predictions + puts(">"*80) + (0..bracket_matches.count-1).each do |i| + bracket_matches.order(:match_id)[i].update(predicted_winner: Team.find(predictions[(i+1).to_s])); + end + return true + end + + + def calcResults + results = Array.new + (0..bracket_matches.count-1).each do |i| + results.push(bracket_matches.order(:match_id)[i].predicted_winner == tournament.stages.order(:id).first.matches.order(:id).winner) + end + return results + end end diff --git a/app/models/bracket_match.rb b/app/models/bracket_match.rb index 823bc40..f9a11f0 100644 --- a/app/models/bracket_match.rb +++ b/app/models/bracket_match.rb @@ -1,5 +1,7 @@ class BracketMatch < ActiveRecord::Base belongs_to :bracket belongs_to :match - belongs_to :predicted_winner + belongs_to :predicted_winner, class_name: "Team" + + end diff --git a/app/models/match.rb b/app/models/match.rb index 5c3a022..85084f5 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -46,6 +46,12 @@ class Match < ActiveRecord::Base return html.html_safe end + def start_sampling + method_classes.each do |klass| + klass.new(self).start + end + end + private def figure_sampling_methods if @sampling_methods.nil? diff --git a/app/models/statistic.rb b/app/models/statistic.rb index b4608b8..fefa3a8 100644 --- a/app/models/statistic.rb +++ b/app/models/statistic.rb @@ -16,7 +16,7 @@ class Statistic < ActiveRecord::Base after_save :update_match def update_match - if (self.name == "win") and (self.value > 0) + if (self.name == "win") and (self.value) self.match.winner = self.match.teams.find{|t| t.users.include? self.user} end if (self.match.status == 2) and (self.match.finished?) |