diff options
-rw-r--r-- | Gemfile | 2 | ||||
-rw-r--r-- | Gemfile.lock | 5 | ||||
-rw-r--r-- | app/controllers/matches_controller.rb | 34 | ||||
-rw-r--r-- | app/models/tournament.rb | 9 | ||||
-rw-r--r-- | app/views/matches/index.html.erb | 80 | ||||
-rw-r--r-- | app/views/tournaments/index.html.erb | 14 | ||||
-rw-r--r-- | app/views/tournaments/show.html.erb | 4 | ||||
-rwxr-xr-x | bin/delayed_job | 5 | ||||
-rw-r--r-- | db/migrate/20140406195921_create_simple_captcha_data.rb (renamed from db/migrate/20140406131442_create_simple_captcha_data.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140406235927_create_delayed_jobs.rb | 22 | ||||
-rw-r--r-- | db/migrate/20140406235933_create_servers.rb (renamed from db/migrate/20140406171445_create_servers.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140406235940_create_matches.rb (renamed from db/migrate/20140406171448_create_matches.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140406235946_create_teams.rb (renamed from db/migrate/20140406171451_create_teams.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140406235952_create_alerts.rb (renamed from db/migrate/20140406171453_create_alerts.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140406235958_create_pms.rb (renamed from db/migrate/20140406171456_create_pms.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140407000005_create_tournaments.rb (renamed from db/migrate/20140406171459_create_tournaments.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140407000011_create_games.rb (renamed from db/migrate/20140406171502_create_games.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140407000017_create_users.rb (renamed from db/migrate/20140406171505_create_users.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140407000024_create_sessions.rb (renamed from db/migrate/20140406171508_create_sessions.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140407000030_create_server_settings.rb (renamed from db/migrate/20140406171510_create_server_settings.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140407000036_create_game_settings.rb (renamed from db/migrate/20140406171513_create_game_settings.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140407000042_create_tournament_preferences.rb (renamed from db/migrate/20140406171516_create_tournament_preferences.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140407000048_create_scores.rb (renamed from db/migrate/20140406171519_create_scores.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140407000054_create_remote_usernames.rb (renamed from db/migrate/20140406171522_create_remote_usernames.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140407000100_create_tournament_players_join_table.rb (renamed from db/migrate/20140406171525_create_tournament_players_join_table.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140407000106_create_tournament_hosts_join_table.rb (renamed from db/migrate/20140406171527_create_tournament_hosts_join_table.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140407000112_create_team_user_join_table.rb (renamed from db/migrate/20140406171530_create_team_user_join_table.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140407000118_create_match_team_join_table.rb (renamed from db/migrate/20140406171532_create_match_team_join_table.rb) | 0 | ||||
-rw-r--r-- | db/migrate/20140407000143_add_hidden_attrs_to_user.rb (renamed from db/migrate/20140406171543_add_hidden_attrs_to_user.rb) | 0 | ||||
-rw-r--r-- | db/schema.rb | 18 | ||||
-rwxr-xr-x | generate.sh | 1 |
31 files changed, 144 insertions, 50 deletions
@@ -48,7 +48,7 @@ gem 'turbolinks' gem 'jbuilder', '~> 1.2' # Asynchronously handle longer or delayed tasks -gem 'delayed_job' +gem 'delayed_job_active_record' group :doc do # bundle exec rake doc:rails generates the API under doc/api. diff --git a/Gemfile.lock b/Gemfile.lock index 51e29e7..fd03576 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -40,6 +40,9 @@ GEM coffee-script-source (1.7.0) delayed_job (4.0.0) activesupport (>= 3.0, < 4.1) + delayed_job_active_record (4.0.0) + activerecord (>= 3.0, < 4.1) + delayed_job (>= 3.0, < 4.1) erubis (2.7.0) execjs (2.0.2) hike (1.2.3) @@ -128,7 +131,7 @@ DEPENDENCIES bcrypt-ruby (= 3.1.2) bootstrap-sass coffee-rails (~> 4.0.0) - delayed_job + delayed_job_active_record httparty jbuilder (~> 1.2) jquery-rails 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 %> diff --git a/bin/delayed_job b/bin/delayed_job new file mode 100755 index 0000000..edf1959 --- /dev/null +++ b/bin/delayed_job @@ -0,0 +1,5 @@ +#!/usr/bin/env ruby + +require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment')) +require 'delayed/command' +Delayed::Command.new(ARGV).daemonize diff --git a/db/migrate/20140406131442_create_simple_captcha_data.rb b/db/migrate/20140406195921_create_simple_captcha_data.rb index 4573b20..4573b20 100644 --- a/db/migrate/20140406131442_create_simple_captcha_data.rb +++ b/db/migrate/20140406195921_create_simple_captcha_data.rb diff --git a/db/migrate/20140406235927_create_delayed_jobs.rb b/db/migrate/20140406235927_create_delayed_jobs.rb new file mode 100644 index 0000000..ec0dd93 --- /dev/null +++ b/db/migrate/20140406235927_create_delayed_jobs.rb @@ -0,0 +1,22 @@ +class CreateDelayedJobs < ActiveRecord::Migration + def self.up + create_table :delayed_jobs, :force => true do |table| + table.integer :priority, :default => 0, :null => false # Allows some jobs to jump to the front of the queue + table.integer :attempts, :default => 0, :null => false # Provides for retries, but still fail eventually. + table.text :handler, :null => false # YAML-encoded string of the object that will do work + table.text :last_error # reason for last failure (See Note below) + table.datetime :run_at # When to run. Could be Time.zone.now for immediately, or sometime in the future. + table.datetime :locked_at # Set when a client is working on this object + table.datetime :failed_at # Set when all retries have failed (actually, by default, the record is deleted instead) + table.string :locked_by # Who is working on this object (if locked) + table.string :queue # The name of the queue this job is in + table.timestamps + end + + add_index :delayed_jobs, [:priority, :run_at], :name => 'delayed_jobs_priority' + end + + def self.down + drop_table :delayed_jobs + end +end diff --git a/db/migrate/20140406171445_create_servers.rb b/db/migrate/20140406235933_create_servers.rb index fbe1b02..fbe1b02 100644 --- a/db/migrate/20140406171445_create_servers.rb +++ b/db/migrate/20140406235933_create_servers.rb diff --git a/db/migrate/20140406171448_create_matches.rb b/db/migrate/20140406235940_create_matches.rb index 31eea12..31eea12 100644 --- a/db/migrate/20140406171448_create_matches.rb +++ b/db/migrate/20140406235940_create_matches.rb diff --git a/db/migrate/20140406171451_create_teams.rb b/db/migrate/20140406235946_create_teams.rb index fdf9a68..fdf9a68 100644 --- a/db/migrate/20140406171451_create_teams.rb +++ b/db/migrate/20140406235946_create_teams.rb diff --git a/db/migrate/20140406171453_create_alerts.rb b/db/migrate/20140406235952_create_alerts.rb index 68a8e10..68a8e10 100644 --- a/db/migrate/20140406171453_create_alerts.rb +++ b/db/migrate/20140406235952_create_alerts.rb diff --git a/db/migrate/20140406171456_create_pms.rb b/db/migrate/20140406235958_create_pms.rb index 93bb5c6..93bb5c6 100644 --- a/db/migrate/20140406171456_create_pms.rb +++ b/db/migrate/20140406235958_create_pms.rb diff --git a/db/migrate/20140406171459_create_tournaments.rb b/db/migrate/20140407000005_create_tournaments.rb index c0d8929..c0d8929 100644 --- a/db/migrate/20140406171459_create_tournaments.rb +++ b/db/migrate/20140407000005_create_tournaments.rb diff --git a/db/migrate/20140406171502_create_games.rb b/db/migrate/20140407000011_create_games.rb index 5e4f56f..5e4f56f 100644 --- a/db/migrate/20140406171502_create_games.rb +++ b/db/migrate/20140407000011_create_games.rb diff --git a/db/migrate/20140406171505_create_users.rb b/db/migrate/20140407000017_create_users.rb index 8032870..8032870 100644 --- a/db/migrate/20140406171505_create_users.rb +++ b/db/migrate/20140407000017_create_users.rb diff --git a/db/migrate/20140406171508_create_sessions.rb b/db/migrate/20140407000024_create_sessions.rb index f667f1e..f667f1e 100644 --- a/db/migrate/20140406171508_create_sessions.rb +++ b/db/migrate/20140407000024_create_sessions.rb diff --git a/db/migrate/20140406171510_create_server_settings.rb b/db/migrate/20140407000030_create_server_settings.rb index dfdd91b..dfdd91b 100644 --- a/db/migrate/20140406171510_create_server_settings.rb +++ b/db/migrate/20140407000030_create_server_settings.rb diff --git a/db/migrate/20140406171513_create_game_settings.rb b/db/migrate/20140407000036_create_game_settings.rb index b1caf5d..b1caf5d 100644 --- a/db/migrate/20140406171513_create_game_settings.rb +++ b/db/migrate/20140407000036_create_game_settings.rb diff --git a/db/migrate/20140406171516_create_tournament_preferences.rb b/db/migrate/20140407000042_create_tournament_preferences.rb index 991d659..991d659 100644 --- a/db/migrate/20140406171516_create_tournament_preferences.rb +++ b/db/migrate/20140407000042_create_tournament_preferences.rb diff --git a/db/migrate/20140406171519_create_scores.rb b/db/migrate/20140407000048_create_scores.rb index 4ca0b0b..4ca0b0b 100644 --- a/db/migrate/20140406171519_create_scores.rb +++ b/db/migrate/20140407000048_create_scores.rb diff --git a/db/migrate/20140406171522_create_remote_usernames.rb b/db/migrate/20140407000054_create_remote_usernames.rb index e265985..e265985 100644 --- a/db/migrate/20140406171522_create_remote_usernames.rb +++ b/db/migrate/20140407000054_create_remote_usernames.rb diff --git a/db/migrate/20140406171525_create_tournament_players_join_table.rb b/db/migrate/20140407000100_create_tournament_players_join_table.rb index be240e8..be240e8 100644 --- a/db/migrate/20140406171525_create_tournament_players_join_table.rb +++ b/db/migrate/20140407000100_create_tournament_players_join_table.rb diff --git a/db/migrate/20140406171527_create_tournament_hosts_join_table.rb b/db/migrate/20140407000106_create_tournament_hosts_join_table.rb index 7521d89..7521d89 100644 --- a/db/migrate/20140406171527_create_tournament_hosts_join_table.rb +++ b/db/migrate/20140407000106_create_tournament_hosts_join_table.rb diff --git a/db/migrate/20140406171530_create_team_user_join_table.rb b/db/migrate/20140407000112_create_team_user_join_table.rb index f3b57fc..f3b57fc 100644 --- a/db/migrate/20140406171530_create_team_user_join_table.rb +++ b/db/migrate/20140407000112_create_team_user_join_table.rb diff --git a/db/migrate/20140406171532_create_match_team_join_table.rb b/db/migrate/20140407000118_create_match_team_join_table.rb index c2ed1b7..c2ed1b7 100644 --- a/db/migrate/20140406171532_create_match_team_join_table.rb +++ b/db/migrate/20140407000118_create_match_team_join_table.rb diff --git a/db/migrate/20140406171543_add_hidden_attrs_to_user.rb b/db/migrate/20140407000143_add_hidden_attrs_to_user.rb index 9b5c505..9b5c505 100644 --- a/db/migrate/20140406171543_add_hidden_attrs_to_user.rb +++ b/db/migrate/20140407000143_add_hidden_attrs_to_user.rb diff --git a/db/schema.rb b/db/schema.rb index 53bc413..f4612b8 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20140406171543) do +ActiveRecord::Schema.define(version: 20140407000143) do create_table "alerts", force: true do |t| t.integer "author_id" @@ -22,6 +22,22 @@ ActiveRecord::Schema.define(version: 20140406171543) do add_index "alerts", ["author_id"], name: "index_alerts_on_author_id" + create_table "delayed_jobs", force: true do |t| + t.integer "priority", default: 0, null: false + t.integer "attempts", default: 0, null: false + t.text "handler", null: false + t.text "last_error" + t.datetime "run_at" + t.datetime "locked_at" + t.datetime "failed_at" + t.string "locked_by" + t.string "queue" + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority" + create_table "game_settings", force: true do |t| t.integer "game_id" t.integer "stype" diff --git a/generate.sh b/generate.sh index 18d0f63..e3e07f9 100755 --- a/generate.sh +++ b/generate.sh @@ -13,6 +13,7 @@ git rm -rf -- app test config/routes.rb db/migrate || true git checkout clean-start -- app test config/routes.rb bundle exec rails generate simple_captcha +bundle exec rails generate delayed_job:active_record # The whole shebang, models, views, and controllers bundle exec rails generate scaffold server default_user_permissions:integer |