From 919ba959bbc782315b0a8b171aa96e2118a43067 Mon Sep 17 00:00:00 2001 From: tkimia Date: Mon, 28 Apr 2014 00:00:47 -0400 Subject: fixed the db seeds. They can now be started --- app/models/match.rb | 1 + app/views/common/_show_tournament.html.erb | 6 ++++-- db/seeds.rb | 11 ++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/models/match.rb b/app/models/match.rb index d4c0ce5..ff81d68 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -12,6 +12,7 @@ class Match < ActiveRecord::Base ok = true tournament_stage.scoring_method.stats_needed.each do |stat| ok &= statistics.where(match: self, name: stat).nil? + end ok end diff --git a/app/views/common/_show_tournament.html.erb b/app/views/common/_show_tournament.html.erb index 151e5d2..12a7fea 100644 --- a/app/views/common/_show_tournament.html.erb +++ b/app/views/common/_show_tournament.html.erb @@ -33,8 +33,10 @@ <% else %>

You've signed up for this tournament!

<% end %> - <%= form_tag(tournament_brackets_path(target), method: "post") do %> - <%= submit_tag("Make Bracket") %> + <% if target.status == 1 %> + <%= form_tag(tournament_brackets_path(target), method: "post") do %> + <%= submit_tag("Make Bracket") %> + <% end %> <% end %> <% end %> diff --git a/db/seeds.rb b/db/seeds.rb index a66cc4b..ea0338d 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -95,6 +95,7 @@ if Rails.env.development? rps = Tournament.create(game_id: 4, status: 0, name: "Rock, Paper, Scissors Seed", min_players_per_team: 1, max_players_per_team: 3, min_teams_per_match: 2, max_teams_per_match: 2, sampling_method: "manual") + rps.stages.create(scheduling_method: "elimination" , seeding_method: "random_seeding") rps.hosts.push(davis) rps.join(davis) rps.join(foy) @@ -109,6 +110,7 @@ if Rails.env.development? end tourn5.join(players_for_league[i]) end + tourn5.stages.create(scheduling_method: "elimination" , seeding_method: "random_seeding") tourn5.join(players_for_league[9]) tourn6 = Tournament.create(game_id: 1, status: 0, name: "3 teams per match", min_players_per_team: 1, max_players_per_team: 1, min_teams_per_match: 3, @@ -120,6 +122,7 @@ if Rails.env.development? end tourn6.join(players_for_league[i]) end + tourn6.stages.create(scheduling_method: "elimination" , seeding_method: "random_seeding") tourn6.join(players_for_league[9]) tourn6.join(davis) tourn6.join(foy) @@ -138,7 +141,13 @@ if Rails.env.development? hash4 = {:username => "NalfeinX", :id => id} hash5 = {:username => "GTBPhoenix", :id => id} hash6 = {:username => , :id => id} - hash7 = {:username => username, :id => id} + hash7 = {:username => username, :id => id}ages.first.create_matchesages.first.create_matches +end +if success +format.html { redirect_to @tournament, +end +if success +format.html { redirect_to @tournament, hash8 = {:username => username, :id => id} hash9 = {:username => username, :id => id} hash10 = {:username => username, :id => id} -- cgit v1.2.3 From 33fcf6de9feaaa6f90dfe5082e08d280c930dae1 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 28 Apr 2014 00:04:30 -0400 Subject: Re-jigger the sampling interface --- app/models/match.rb | 10 ++++++++++ generate.sh | 4 ++-- lib/sampling/README.md | 30 +++++++++++++++++++----------- lib/sampling/manual.html.erb | 1 + lib/sampling/manual.rb | 21 ++++++++++++++------- lib/sampling/peer_review.rb | 20 +++++++++++++++----- lib/sampling/riot_api.rb | 35 +++++++++++++++++------------------ lib/scheduling/README.md | 4 ++-- lib/scoring/README.md | 4 ++-- 9 files changed, 82 insertions(+), 47 deletions(-) create mode 100644 lib/sampling/manual.html.erb diff --git a/app/models/match.rb b/app/models/match.rb index c2df6e0..1edac8f 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -9,6 +9,16 @@ class Match < ActiveRecord::Base winner.players.include? player end + def users + ret = [] + self.teams.each{|t| ret.concat(t.users)} + return ret + end + + def stats_from(sampling_class) + # TODO + end + def handle_sampling(params) # TODO end diff --git a/generate.sh b/generate.sh index 3837ddb..6a6c502 100755 --- a/generate.sh +++ b/generate.sh @@ -44,8 +44,8 @@ bundle exec rails generate scaffold match status:integer tournament_stage:refere bundle exec rails generate scaffold team bundle exec rails generate scaffold alert author:references message:text bundle exec rails generate scaffold pm author:references recipient:references message:text subject:text conversation:references -bundle exec rails generate scaffold tournament game:references status:integer name:string:uniq min_players_per_team:integer max_players_per_team:integer min_teams_per_match:integer max_teams_per_match:integer sampling_method:string scoring_method:string -bundle exec rails generate scaffold game parent:references name:string:uniq min_players_per_team:integer max_players_per_team:integer min_teams_per_match:integer max_teams_per_match:integer sampling_method:string scoring_method:string +bundle exec rails generate scaffold tournament game:references status:integer name:string:uniq min_players_per_team:integer max_players_per_team:integer min_teams_per_match:integer max_teams_per_match:integer scoring_method:string +bundle exec rails generate scaffold game parent:references name:string:uniq min_players_per_team:integer max_players_per_team:integer min_teams_per_match:integer max_teams_per_match:integer scoring_method:string bundle exec rails generate scaffold user name:string email:string:uniq user_name:string:uniq bundle exec rails generate scaffold session user:references token:string:uniq bundle exec rails generate scaffold bracket user:references tournament:references name:string diff --git a/lib/sampling/README.md b/lib/sampling/README.md index bde84cd..5e0a53c 100644 --- a/lib/sampling/README.md +++ b/lib/sampling/README.md @@ -1,42 +1,50 @@ Sampling interface ================== -Files in this directory should be _modules_ implementing the following +Files in this directory should be _classes_ implementing the following interface: - - `works_with?(Game) => Boolean` + - `self.works_with?(Game) => Boolean` Returns whether or not this sampling method works with the specified game. - - `can_get?(User, String setting_name) => Fixnum` + - `self.can_get?(String setting_name) => Fixnum` Returns whether or nat this sampling method can get a specifed statistic; 0 means 'false', positive integers mean 'true', where higher numbers are higher priority. - - `uses_remote?() => Boolean` + - `self.uses_remote?() => Boolean` Return whether or not this sampling method requires remote IDs for users. - - `set_remote_name(User, Game, String)` + + - `self.set_remote_name(User, Game, String)` Set the remote ID for a user for the specified game. It is safe to assume that this sampling method `works_with?` that game. - - `get_remote_name(Object)` + + - `self.get_remote_name(Object)` When given an object from `RemoteUsername#value`, give back a - human-readable/editable name to display. + human-readable/editable name to display + +---- + + - `initialize(Match)` + + Construct new Sampling object for the specified match. - - `sampling_start(Match, Array[]={:user=>User,:stat=>String})` + - `start()` - Fetch the statistics for a match. + Begin fetching the statistics. - - `render_user_interaction(Match, User) => String` + - `render_user_interaction(User) => String` Returns HTML to render on a page. - - `handle_user_interaction(Match, User, Hash params)` + - `handle_user_interaction(User, Hash params)` Handles params from the form generated by `#user_interaction_render`. diff --git a/lib/sampling/manual.html.erb b/lib/sampling/manual.html.erb new file mode 100644 index 0000000..cf873b4 --- /dev/null +++ b/lib/sampling/manual.html.erb @@ -0,0 +1 @@ + diff --git a/lib/sampling/manual.rb b/lib/sampling/manual.rb index b5c97c4..a190bd2 100644 --- a/lib/sampling/manual.rb +++ b/lib/sampling/manual.rb @@ -1,10 +1,10 @@ module Sampling - module Manual + class Manual def self.works_with?(game) return true end - def can_get?(user, setting_name) + def can_get?(setting_name) return 1 end @@ -20,12 +20,20 @@ module Sampling raise "This sampling method doesn't use remote usernames." end - def self.sampling_start(match, statistics) + #### + + def initialize(match) + @match = match + end + + def start # do nothing end - def self.render_user_interaction(match, user) - # TODO + def render_user_interaction(user) + @current_user = user + @users = @match.users + @stats = @match.stats_from(self.class) require 'erb' erb_filename = File.join(__FILE__.sub(/\.rb$/, '.svg.erb')) @@ -34,9 +42,8 @@ module Sampling return erb.result.html_safe end - def self.handle_user_interaction(match, user, sampling_params) + def handle_user_interaction(user, sampling_params) # TODO - #match.statistics.create(user: nil, name: "blowout", end end end diff --git a/lib/sampling/peer_review.rb b/lib/sampling/peer_review.rb index cbbd2f9..dd456c9 100644 --- a/lib/sampling/peer_review.rb +++ b/lib/sampling/peer_review.rb @@ -1,9 +1,13 @@ module Sampling - module PeerReview + class PeerReview def self.works_with?(game) return true end + def self.can_get?(setting_name) + return setting_name.start_with?("feedback_from_") + end + def self.uses_remote? return false end @@ -16,11 +20,17 @@ module Sampling raise "This sampling method doesn't use remote usernames." end - def self.sampling_start(match) + #### + + def initialize(match) + @match = match + end + + def start # do nothing end - def self.render_user_interaction(match, user) + def render_user_interaction(user) @user = user @team = get_team(match) @feedbacks_missing = get_feedbacks_missing(match) @@ -32,11 +42,11 @@ module Sampling return erb.result.html_safe end - def self.handle_user_interaction(match, reviewing_user, params) + def handle_user_interaction(reviewing_user, params) i = 0 params[:peer_review].to_s.split(',').each do |user_name| reviewed_user = User.find_by_user_name(user_name) - user.statistics.create(match: match, value: i) + user.statistics.create(match: @match, value: i) i += 1 end end diff --git a/lib/sampling/riot_api.rb b/lib/sampling/riot_api.rb index 8c34fc4..7e14551 100644 --- a/lib/sampling/riot_api.rb +++ b/lib/sampling/riot_api.rb @@ -1,5 +1,5 @@ module Sampling - module RiotApi + class RiotApi protected def self.api_name "prod.api.pvp.net/api/lol" @@ -87,21 +87,12 @@ module Sampling # Return whether or not the API can get a given statistic for # a given user. public - def self.can_get?(user, stat) - if user.nil? + def self.can_get?(stat) + if stats_available.include?(stat) + return 2 + else return 0 end - summoner = user.get_remote_username(match.tournament_stage.tournament.game) - if summoner.nil? - return 0 - end - if summoner["id"].nil? - return 0 - end - unless stats_available.include?(stat) - return 0 - end - return 2 end ## @@ -149,13 +140,20 @@ module Sampling data["name"] end + #### + + public + def initialize(match) + @match = match + end + ## # Fetch all the statistics for a match. public - def self.sampling_start(match, stats) + def start @match.teams.each do |team| team.users.each do |user| - Delayed::Job.enqueue(MatchJob.new(user, match, stats.map{|stat|stat[:name]}, nil), :queue => api_name) + Delayed::Job.enqueue(MatchJob.new(user, @match, @match.stats_from(self.class), nil), :queue => api_name) end end end @@ -191,12 +189,13 @@ module Sampling end public - def self.render_user_interaction(match, user) + def render_user_interaction(user) return "" end public - def self.handle_user_interaction(match, user) + def handle_user_interaction(user) + # do nothing end end end diff --git a/lib/scheduling/README.md b/lib/scheduling/README.md index 8b21164..fe6aba1 100644 --- a/lib/scheduling/README.md +++ b/lib/scheduling/README.md @@ -4,7 +4,7 @@ Scheduling interface Files in this directory should be _classes_ implementing the following interface: - - `initialize(tournament_stage)` + - `initialize(TournamentStage)` Construct new Scheduling object from tournament_stage. @@ -12,7 +12,7 @@ interface: Creates all the matches of the current round. - - `finish_match(match)` + - `finish_match(Match)` Progresses the match through the schedule. diff --git a/lib/scoring/README.md b/lib/scoring/README.md index 5beb0a2..dce71d0 100644 --- a/lib/scoring/README.md +++ b/lib/scoring/README.md @@ -4,12 +4,12 @@ Scoring interface Files in this directory should be _modules_ implementing the following interface: - - `stats_needed() => Array[i]=Symbol` + - `stats_needed(Match) => Array[]=Symbol` Returns which statistics need to be collected for this scoring algorithm. - - `score(match) => Hash[User]=Integer` + - `score(Match) => Hash[User]=Integer` User scores for this match, assuming statistics have been collected. -- cgit v1.2.3 From 952387be24043e76dfd9b7a461ee31d1246fa58e Mon Sep 17 00:00:00 2001 From: nfoy Date: Mon, 28 Apr 2014 00:07:57 -0400 Subject: Messages and alerts play together more nicely now. --- app/views/pms/index.html.erb | 69 +++++++++++++++++++++++++++++++++++++------- app/views/pms/show.html.erb | 1 + 2 files changed, 60 insertions(+), 10 deletions(-) diff --git a/app/views/pms/index.html.erb b/app/views/pms/index.html.erb index 056b371..fec6db2 100644 --- a/app/views/pms/index.html.erb +++ b/app/views/pms/index.html.erb @@ -23,6 +23,9 @@ <% if conversation.is_unread?(current_user) && receipts.last.message.sender != current_user %> <% message = receipts.last.message %> + <% if conversation.subject == "Pay Attention!" %> + <% conversation.mark_as_read(current_user) %> + <% end %> <% people = conversation.participants %> <% people.each do |person| %> @@ -65,17 +68,63 @@ <% if conversation.is_read?(current_user) || receipts.last.message.sender == current_user %> <% message = receipts.last.message %> - - <% people = conversation.participants %> - <% people.each do |person| %> - <% unless person == current_user %> - <%= truncate(person.user_name, length: 20) %> + <% if conversation.subject != "Pay Attention!" %> + + <% people = conversation.participants %> + <% people.each do |person| %> + <% unless person == current_user %> + <%= truncate(person.user_name, length: 20) %> + <% end %> <% end %> - <% end %> - - <%= truncate(conversation.subject, length: 30) %> - <%= truncate(message.body, length: 42) %> - <%= link_to 'View', @pms.find_by(conversation: conversation) %> + + <%= truncate(conversation.subject, length: 30) %> + <%= truncate(message.body, length: 42) %> + <%= link_to 'View', @pms.find_by(conversation: conversation) %> + <% end %> + + <% end %> + <% end %> + + <% #else %> + + <% #end %> + + + +
+

Alerts

+<% conversations = current_user.mailbox.conversations %> + + + + + + + <%# if conversations.reject { |c| c.is_read?(current_user) || (c.receipts_for current_user).last.message.sender == current_user }.empty? %> + + + + + + + <% conversations.each do |conversation| %> + <% receipts = conversation.receipts_for current_user %> + <% if conversation.is_read?(current_user) || receipts.last.message.sender == current_user %> + <% message = receipts.last.message %> + + <% if conversation.subject == "Pay Attention!" %> + + + + + <% end %> <% end %> <% end %> diff --git a/app/views/pms/show.html.erb b/app/views/pms/show.html.erb index ca8d9bf..2c93102 100644 --- a/app/views/pms/show.html.erb +++ b/app/views/pms/show.html.erb @@ -31,6 +31,7 @@

________________________________________________

+ <% @pm.message = "" %> <%= form_for(@pm) do |f| %>

<%= f.text_area :message %> -- cgit v1.2.3 From ee238dbbca6ee979aa886a4f4cebad41e6f79cce Mon Sep 17 00:00:00 2001 From: AndrewMurrell Date: Mon, 28 Apr 2014 00:17:33 -0400 Subject: 30 minutes to add a single line --- app/views/tournaments/_form.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/tournaments/_form.html.erb b/app/views/tournaments/_form.html.erb index 2a871ea..a5eba7a 100644 --- a/app/views/tournaments/_form.html.erb +++ b/app/views/tournaments/_form.html.erb @@ -17,6 +17,7 @@ <% else %> <%= form_for(@tournament, url: tournaments_path, method: "post") do |f| %> + <%= f.hidden_field(:game_id) %>

<%= f.label :name %> <%= f.text_field :name %> -- cgit v1.2.3 From d43213dfcf1f1d73d76ae2d2aa59cee3597c06da Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 28 Apr 2014 00:25:18 -0400 Subject: implement most of the TODOs in Match --- app/models/match.rb | 63 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/app/models/match.rb b/app/models/match.rb index fa15980..460e7c4 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -27,18 +27,73 @@ class Match < ActiveRecord::Base end def stats_from(sampling_class) - # TODO + figure_sampling_methods.map{|stat,klass| (sampling_class==klass) ? stat : nil}.select{|s| not s.nil?} end - def handle_sampling(params) - # TODO + def handle_sampling(user, params) + method_classes.each do |klass| + klass.new(self).handle_user_interaction(user, params) + end end def render_sampling(user) - # TODO + require 'set' + html = '' + + method_classes.each do |klass| + html += '

' + html += klass.new(self).render_user_interaction(user) + html += '
' + end + + return html.html_safe end def finished? # TODO end + + private + def figure_sampling_methods + if @sampling_methods.nil? + data = {} + needed = self.tournament_stage.scoring.stats_needed + methods_names = self.tournament_stage.tournament.sampling_methods + methods_names.each do |method_name| + method_class = "Sampling::#{sampling_name.camelcase}".constantize + if method_class.works_with(self.tournament_stage.tournament.game) + needed.each do |stat| + data[stat] ||= {} + data[stat][method] = method.can_get?(user, stat) + end + end + end + + needed.each do |stat| + max_val = nil + max_pri = 0 + data[stat].each do |method,priority| + if priority > max_pri + max_val = method + max_pri = priority + end + end + data[stat] = max_val + end + @sampling_methods = data + end + return @sampling_methods + end + + def method_classes + if @method_classes.nil? + data = Set.new + figure_sampling_methods.each do |stat,method| + data.push(method) + end + @method_classes = data + end + return @method_classes + end + end -- cgit v1.2.3 From 0a5242c3a460d0b99be0adc4593774a58b68154a Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Mon, 28 Apr 2014 00:29:11 -0400 Subject: fix bad merge --- app/models/match.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/models/match.rb b/app/models/match.rb index 460e7c4..3cbe0da 100644 --- a/app/models/match.rb +++ b/app/models/match.rb @@ -49,10 +49,6 @@ class Match < ActiveRecord::Base return html.html_safe end - def finished? - # TODO - end - private def figure_sampling_methods if @sampling_methods.nil? -- cgit v1.2.3
WithSubjectBody
+ <% people = conversation.participants %> + <% people.each do |person| %> + <% unless person == current_user %> + <%= truncate(person.user_name, length: 20) %> + <% end %> + <% end %> + <%= truncate(conversation.subject, length: 30) %><%= truncate(message.body, length: 42) %><%= link_to 'View', @pms.find_by(conversation: conversation) %>