summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
Diffstat (limited to 'app/models')
-rw-r--r--app/models/bracket.rb23
-rw-r--r--app/models/bracket_match.rb4
-rw-r--r--app/models/match.rb6
-rw-r--r--app/models/statistic.rb2
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?)