From 819fd70c1285bf5670b68842adad8c77c36d1076 Mon Sep 17 00:00:00 2001 From: nfoy Date: Mon, 28 Apr 2014 21:32:04 -0400 Subject: All the changes. Luke should know what's up. --- app/controllers/matches_controller.rb | 1 + app/models/match.rb | 6 ++++++ 2 files changed, 7 insertions(+) (limited to 'app') diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 81ffcd8..d2dc918 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -31,6 +31,7 @@ class MatchesController < ApplicationController # Scheduled, waiting to start if (@tournament.hosts.include? current_user) and (params[:update_action] == "start") @match.status = 2 + @match.start_sampling respond_to do |format| if @match.save format.html { redirect_to tournament_match_path(@tournament, @match), notice: 'Match has started.' } diff --git a/app/models/match.rb b/app/models/match.rb index 219e662..57b7d36 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? -- cgit v1.2.3-2-g168b From bc8be5e217279012cd4dc62e3fc2fe2bd9308b1c Mon Sep 17 00:00:00 2001 From: tkimia Date: Mon, 28 Apr 2014 22:01:00 -0400 Subject: bracket update works --- app/controllers/brackets_controller.rb | 20 +++++++++++++++---- app/models/bracket.rb | 14 ++++++++++++- app/models/bracket_match.rb | 4 +++- app/views/brackets/show.html.erb | 32 +++++++++++++++--------------- app/views/common/_show_tournament.html.erb | 3 ++- 5 files changed, 50 insertions(+), 23 deletions(-) (limited to 'app') diff --git a/app/controllers/brackets_controller.rb b/app/controllers/brackets_controller.rb index ac34bfe..b91a2c4 100644 --- a/app/controllers/brackets_controller.rb +++ b/app/controllers/brackets_controller.rb @@ -11,7 +11,7 @@ class BracketsController < ApplicationController # GET /brackets/1 # GET /brackets/1.json def show - @matches = @tournament.stages.first.matches_ordered + @matches = @tournament.stages.order(:id).first.matches_ordered @numTeams = @tournament.min_teams_per_match @logBase = @numTeams @@ -53,11 +53,11 @@ class BracketsController < ApplicationController # PATCH/PUT /brackets/1.json def update respond_to do |format| - if @bracket.update(bracket_params) - format.html { redirect_to @tournament, notice: 'Bracket was successfully updated.' } + if @bracket.predict_winners(prediction_params) + format.html { redirect_to @tournament, notice: 'Your bracket was made! Check back when this stage finishes to see how you did!' } format.json { head :no_content } else - format.html { render action: 'edit' } + format.html { redirect_to @tournament, notice: 'bracket was not made... :('} format.json { render json: @bracket.errors, status: :unprocessable_entity } end end @@ -86,9 +86,21 @@ class BracketsController < ApplicationController # Never trust parameters from the scary internet, only allow the white list through. def bracket_params + # bracket[user_id] + # bracket[tournament_id] + # bracket[name] + # bracket[matches][#{i}] params.require(:bracket).permit(:user_id, :tournament_id, :name) end + def prediction_params + require 'pp' + puts ""*80 + params.require(:bracket).require(:matches) + end + def is_owner?(bracket) bracket.user == current_user end diff --git a/app/models/bracket.rb b/app/models/bracket.rb index acd33ca..fc3e10e 100644 --- a/app/models/bracket.rb +++ b/app/models/bracket.rb @@ -4,8 +4,20 @@ 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 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/views/brackets/show.html.erb b/app/views/brackets/show.html.erb index 64e6e6a..a3eb000 100644 --- a/app/views/brackets/show.html.erb +++ b/app/views/brackets/show.html.erb @@ -21,30 +21,30 @@ %> function chooseWinner(matchNum, teamNum, currentBox){ console.log(matchNum, teamNum); - $id = '#match-'+matchNum+'-pred'; - $($id).val(teamNum); + var id = '#bracket_matches_'+matchNum; + $(id).val(teamNum); if (matchNum != 1) { - $parent = parseFloat(matchNum+<%= @logBase%> -2)/<%=@logBase%>; - $textBox = ($parent - Math.floor($parent)) * <%= @logBase %>; - $parent = Math.floor($parent); - $textBox = Math.round($textBox); - $id = "#svg-match-"+$parent+"-team-"+$textBox; + var parent = parseFloat(matchNum+<%= @logBase%> -2)/<%=@logBase%>; + var textBox = (parent - Math.floor(parent)) * <%= @logBase %>; + var parent = Math.floor(parent); + var textBox = Math.round(textBox); + var id = "#svg-match-"+parent+"-team-"+textBox; - console.log($id); + console.log(id); - $($id).text("Team "+teamNum); - $($id).attr("onclick", "chooseWinner("+$parent+", "+teamNum+", "+$textBox+")"); + $(id).text("Team "+teamNum); + $(id).attr("onclick", "chooseWinner("+parent+", "+teamNum+", "+textBox+")"); } else { console.log("final countdown"); for(var i = 0; i < 3; i++){ - $id = "#svg-match-"+matchNum+"-team-"+i; - $($id).attr("fill", "black"); + id = "#svg-match-"+matchNum+"-team-"+i; + $(id).attr("fill", "black"); } - $id = "#svg-match-"+matchNum+"-team-"+currentBox; - $($id).attr("fill", "green"); + id = "#svg-match-"+matchNum+"-team-"+currentBox; + $(id).attr("fill", "green"); $("#bracket-submit").prop('disabled', false); } } @@ -100,9 +100,9 @@ <%= form_tag(tournament_bracket_path(@tournament, @bracket), method: 'put') do %> <% for i in 1..@matches.length %> - <%= hidden_field_tag('match-'+@matches[i].id.to_s+'-pred', value = nil) %> + <%= hidden_field_tag("bracket[matches][#{@matches[i].id.to_s}]", value = nil) %> <% end %> - <%= submit_tag("Sumit Prediction", disabled: true, id: "bracket-submit") %> + <%= submit_tag("Submit Prediction", disabled: true, id: "bracket-submit") %> <% end %> <%= link_to 'Back', tournaments_path %> diff --git a/app/views/common/_show_tournament.html.erb b/app/views/common/_show_tournament.html.erb index 02852cf..f4d02ec 100644 --- a/app/views/common/_show_tournament.html.erb +++ b/app/views/common/_show_tournament.html.erb @@ -33,7 +33,8 @@ <% elsif target.players.include?(current_user)%>

You've signed up for this tournament!

<% end %> - <% if target.status == 1 && target.stages.order(:id).first.scheduling_method == "elimination" && target.stages.order(:id).first.matches.order(:id).first.status < 2 %> + <% @user_bracket = target.brackets.find_by(user: current_user) %> + <% if target.status == 1 && target.stages.order(:id).first.scheduling_method == "elimination" && target.stages.order(:id).first.matches.order(:id).first.status < 2 && !@user_bracket %> <%= form_tag(tournament_brackets_path(target), method: "post") do %> <%= submit_tag("Make Bracket") %> <% end %> -- cgit v1.2.3-2-g168b From 40c112d42922c14063759d381f834724f22a340d Mon Sep 17 00:00:00 2001 From: tkimia Date: Mon, 28 Apr 2014 22:54:35 -0400 Subject: made svg smaller --- app/controllers/brackets_controller.rb | 1 + app/models/bracket.rb | 9 +++++++++ app/views/brackets/show.html.erb | 20 +++++++++++--------- app/views/common/_show_tournament.html.erb | 5 +++++ 4 files changed, 26 insertions(+), 9 deletions(-) (limited to 'app') diff --git a/app/controllers/brackets_controller.rb b/app/controllers/brackets_controller.rb index b91a2c4..e202c96 100644 --- a/app/controllers/brackets_controller.rb +++ b/app/controllers/brackets_controller.rb @@ -11,6 +11,7 @@ class BracketsController < ApplicationController # GET /brackets/1 # GET /brackets/1.json def show + @results = (@tournament.status == 4)? @bracket.calcResult : nil; @matches = @tournament.stages.order(:id).first.matches_ordered @numTeams = @tournament.min_teams_per_match @logBase = @numTeams diff --git a/app/models/bracket.rb b/app/models/bracket.rb index fc3e10e..48414c3 100644 --- a/app/models/bracket.rb +++ b/app/models/bracket.rb @@ -20,4 +20,13 @@ class Bracket < ActiveRecord::Base 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/views/brackets/show.html.erb b/app/views/brackets/show.html.erb index a3eb000..24b19fe 100644 --- a/app/views/brackets/show.html.erb +++ b/app/views/brackets/show.html.erb @@ -1,7 +1,8 @@

<%= @bracket.name %>

-

Make your prediction for the tournament by clicking on the teams you think will win

- +<% if !@results %> +

Make your prediction for the tournament by clicking on the teams you think will win

+<% end %> + <% if @matches[i].teams[t-1] && !@results %> onclick="chooseWinner(<%= @matches[i].id%>, <%= @matches[i].teams[t-1].id %>)" <% end %> > @@ -97,12 +98,13 @@ <% end %> -<%= form_tag(tournament_bracket_path(@tournament, @bracket), method: 'put') do %> - - <% for i in 1..@matches.length %> - <%= hidden_field_tag("bracket[matches][#{@matches[i].id.to_s}]", value = nil) %> +<% if !@results %> + <%= form_tag(tournament_bracket_path(@tournament, @bracket), method: 'put') do %> + + <% for i in 1..@matches.length %> + <%= hidden_field_tag("bracket[matches][#{@matches[i].id.to_s}]", value = nil) %> + <% end %> + <%= submit_tag("Submit Prediction", disabled: true, id: "bracket-submit") %> <% end %> - <%= submit_tag("Submit Prediction", disabled: true, id: "bracket-submit") %> <% end %> - <%= link_to 'Back', tournaments_path %> diff --git a/app/views/common/_show_tournament.html.erb b/app/views/common/_show_tournament.html.erb index f4d02ec..c0237b1 100644 --- a/app/views/common/_show_tournament.html.erb +++ b/app/views/common/_show_tournament.html.erb @@ -38,6 +38,11 @@ <%= form_tag(tournament_brackets_path(target), method: "post") do %> <%= submit_tag("Make Bracket") %> <% end %> + <% elsif @user_bracket && target.status == 4 %> + <%= form_tag(tournament_bracket_path(@tournament, @bracket), method: 'put') do %> + + <%= submit_tag("Bracket Results") %> + <% end %> <% end %> <% end %> -- cgit v1.2.3-2-g168b From 7297cff5b674a61fd57ccc46eb75173011bd205c Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 28 Apr 2014 23:57:48 -0400 Subject: fix riot_api --- app/models/statistic.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app') 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?) -- cgit v1.2.3-2-g168b