summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/matches_controller.rb34
-rw-r--r--app/models/tournament.rb9
-rw-r--r--app/views/matches/index.html.erb80
-rw-r--r--app/views/tournaments/index.html.erb14
-rw-r--r--app/views/tournaments/show.html.erb4
5 files changed, 94 insertions, 47 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb
index e773667..e9fe727 100644
--- a/app/controllers/matches_controller.rb
+++ b/app/controllers/matches_controller.rb
@@ -5,15 +5,18 @@ class MatchesController < ApplicationController
# GET /matches.json
require 'httparty'
require 'json'
+ require 'delayed_job'
def index
@matches = @tournament.matches
# width of SVG
- @width = 300 * (Math.log2(@matches.count).floor + 1) + 300;
+ @width = 300 * (Math.log2(@matches.count).floor + 1);
# height of SVG
@height = 200 * 2**Math.log2(@matches.count).floor + 100;
end
+
+
def get_riot_info
if signed_in?
@@ -118,14 +121,41 @@ class MatchesController < ApplicationController
end #end def
# GET /matches/1
# GET /matches/1.json
+
+ def is_match_over
+ response = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/by-name/#{@first}?api_key=ad539f86-22fd-474d-9279-79a7a296ac38")
+ riot_id = response["#{@first}"]['id']
+ #recent game information
+ game_info = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/game/by-summoner/#{riot_id}/recent?api_key=ad539f86-22fd-474d-9279-79a7a296ac38")
+ first_id = game_info["games"][0]["gameId"]
+
+ while true do
+ sleep(240) #wait four minutes
+
+ recent = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/game/by-summoner/#{riot_id}/recent?api_key=ad539f86-22fd-474d-9279-79a7a296ac38")
+ current_id = recent["games"][0]["gameId"]
+
+ if current_id != first_id
+ @match.status = 2
+ end
+ end #while
+ end
+ handle_asynchronously :is_match_over
+
def show
+ if @match.id == 1
+ is_match_over
+ end
+
+
end
private
# Use callbacks to share common setup or constraints between actions.
def set_match
set_tournament
- @match = @tournament.matches.find(params[:id]);
+ @match = @tournament.matches.find(params[:id])
+ @first = @match.teams.first.users.first.user_name.downcase
end
def set_tournament
@tournament = Tournament.find(params[:tournament_id])
diff --git a/app/models/tournament.rb b/app/models/tournament.rb
index 0029de7..72c3ac8 100644
--- a/app/models/tournament.rb
+++ b/app/models/tournament.rb
@@ -34,16 +34,17 @@ class Tournament < ActiveRecord::Base
match_num = num_matches-1
team_num = 0
#for each grouping of min_players_per_team
- self.players.each_slice(min_players_per_team) do |players|
- #create a new team in the current match
- self.matches[match_num].teams.push(Team.create(users: players))
+ players.each_slice(min_players_per_team) do |players|
+
#if the match is full, move to the next match, otherwise move to the next team
- if (team_num != 0 and team_num % max_teams_per_match == 0)
+ if (team_num == min_teams_per_match)
match_num -= 1
team_num = 0
else
team_num += 1
end
+ #create a new team in the current match
+ self.matches[match_num].teams.push(Team.create(users: players))
end
end
end
diff --git a/app/views/matches/index.html.erb b/app/views/matches/index.html.erb
index 031b2a9..6fd831f 100644
--- a/app/views/matches/index.html.erb
+++ b/app/views/matches/index.html.erb
@@ -27,38 +27,50 @@
<br>
<div id="match-tree">
-<SVG version="1.1"
- baseProfile="full"
- width="<%= @width %>" height="<%= @height = [@height, 500].max %>"
- xmlns="http://www.w3.org/2000/svg">
- <line x1="300" y1="0" x2="300" y2="<%= @height %>" stroke="black" />
- <% (1..@matches.count).each do |i| %>
- <g class="svg-match">
- <rect height="120px" width="213px"
- x="<%= @width - (i-1)*50 - 250*(Math.log2(i).floor+1) %>"
- y="<%= (@height/(Math.log2(i).floor+2)) - 60 + 250*(i - 2**(Math.log2(i).floor)) %>"
- fill="#ffd281"
- rx="20px"
- stroke-width="2"
- <% case @matches[i-1].status %>
- <% when 0 %>
- <% if @matches[i-1].teams.count < @tournament.min_teams_per_match %>
- stroke="red"
- fill-opacity="0.6"
- <% else %>
- stroke="green"
- <% end %>
- <% when 1 %>
- stroke="orange"
- <% when 2 %>
- stroke="yellow"
- <% when 3 %>
- stroke="grey"
- <% end %>
- />
- </g>
- <% end %>
-
-
+ <SVG version="1.1"
+ baseProfile="full"
+ width="<%= @width %>" height="<%= @height = [@height, 500].max %>"
+ xmlns="http://www.w3.org/2000/svg">
+ <script type="text/ecmascript"><![CDATA[
+ function redirect(i){
+ window.location.replace("<%= request.original_url %>"+"/"+i);
+ }
+ ]]>
+ </script>
+ <% (1..@matches.count).each do |i| %>
+ <g id="svg-match-<%= i %>" onmouseover="dispStats(<%= i %>)" onclick="redirect(<%= @matches[i-1].id %>)" cursor="pointer">
+ <rect height="120px" width="213px"
+ x="<%= @width - (i-1)*50 - 250*(Math.log2(i).floor+1) %>"
+ y="<%= (@height/(Math.log2(i).floor+2)) - 60 + 250*(i - 2**(Math.log2(i).floor)) %>"
+ fill="#ffd281"
+ rx="20px"
+ stroke-width="2"
+ <% case @matches[i-1].status %>
+ <% when 0 %>
+ <% if @matches[i-1].teams.count < @tournament.min_teams_per_match %>
+ stroke="red"
+ fill-opacity="0.6"
+ <% else %>
+ stroke="green"
+ <% end %>
+ <% when 1 %>
+ stroke="orange"
+ <% when 2 %>
+ stroke="yellow"
+ <% when 3 %>
+ stroke="grey"
+ <% end %>
+ />
+ </g>
+ <% if i > 1 %>
+ <line
+ stroke="black"
+ x1="<%= @width - (i-2)*50 - 250*(Math.log2(i-1).floor+1) %>"
+ y1="<%= (@height/(Math.log2(i-1).floor+2)) - 60 + 250*((i-1) - 2**(Math.log2(i-1).floor)) + 60 %>"
+ x2="<%= @width - (i-1)*50 - 250*(Math.log2(i).floor+1) + 213 %>"
+ y2="<%= (@height/(Math.log2(i).floor+2)) - 60 + 250*(i - 2**(Math.log2(i).floor)) + 60 %>"
+ />
+ <% end %>
+ <% end %>
</SVG>
-</div> \ No newline at end of file
+</div>
diff --git a/app/views/tournaments/index.html.erb b/app/views/tournaments/index.html.erb
index e174de7..72eacba 100644
--- a/app/views/tournaments/index.html.erb
+++ b/app/views/tournaments/index.html.erb
@@ -15,13 +15,17 @@
<h3><%= t.name %></h3>
<% end %>
- <div class="row">
+ <div class="row" style="margin-left:2%;">
<div class="col-md-4 host">
Hosted by: <%= t.hosts.first.name %>
</div>
- <div class="col-md-8 things">
- <p> Players per team </p>
- <p> two </p>
+ <div class="col-md-4 things">
+ <p> Players per team: <%= t.min_players_per_team %></p>
+ <p> Players signed up: <%= t.players.count %> </p>
+ </div>
+ <div class="col-md-4 things">
+ <p> <%= (t.randomized_teams)? "Teams are Random" : "Teams are Chosen" %></p>
+ <p> Players signed up: <%= t.players.count %> </p>
</div>
</div>
@@ -36,7 +40,7 @@
<%= submit_tag("Join") %>
<% end %>
<% else %>
- <p> You've signed up for this tournament! </p>
+ <p style="margin-top:10px;"> You've signed up for this tournament! </p>
<% end %>
</div>
diff --git a/app/views/tournaments/show.html.erb b/app/views/tournaments/show.html.erb
index b654804..e80e0e8 100644
--- a/app/views/tournaments/show.html.erb
+++ b/app/views/tournaments/show.html.erb
@@ -66,13 +66,13 @@
<% if @tournament.joinable_by?(current_user) && !@tournament.players.include?(current_user) %>
<%= form_tag(tournament_path(@tournament), method: "put") do %>
<input type="hidden" name="update_action" value="join">
- <%= submit_tag("Join Tournamnet") %>
+ <%= submit_tag("Join Tournament") %>
<% end %>
<% elsif @tournament.players.include?(current_user) %>
<%= form_tag(tournament_path(@tournament), method: "put") do %>
<input type="hidden" name="update_action" value="leave">
- <%= submit_tag("Leave Tournamnet") %>
+ <%= submit_tag("Leave Tournament") %>
<% end %>
<% end %>