diff options
author | AndrewMurrell <amurrel@purdue.edu> | 2014-04-27 21:30:42 -0400 |
---|---|---|
committer | AndrewMurrell <amurrel@purdue.edu> | 2014-04-27 21:30:42 -0400 |
commit | 55ce0081e6e54c3b9c0d3af23bee3fec501c89a9 (patch) | |
tree | c4e85c576bfb0f72b1b5dede603a31b01029a80f | |
parent | 35e21c339f87c1b0b1ed2c871c83ae9602adadc0 (diff) | |
parent | ee1eaebb77048d3e3537b5f1f9aead5dc379f849 (diff) |
Merge branch 'master' of http://github.com/LukeShu/leaguer
-rw-r--r-- | app/controllers/matches_controller.rb | 142 | ||||
-rw-r--r-- | app/views/matches/show.html.erb | 7 | ||||
-rw-r--r-- | lib/sampling/peer_review.html.erb | 28 | ||||
-rw-r--r-- | lib/sampling/peer_review.rb | 85 |
4 files changed, 116 insertions, 146 deletions
diff --git a/app/controllers/matches_controller.rb b/app/controllers/matches_controller.rb index 8b8e86d..4c92e67 100644 --- a/app/controllers/matches_controller.rb +++ b/app/controllers/matches_controller.rb @@ -10,148 +10,6 @@ class MatchesController < ApplicationController def index end - # For compatability with the router assumptions made by ApplicationController#check_permission - def matches_url - set_tournament - tournament_matches_path(@tournament) - end - - def get_riot - - players_id = Array.new - players = Array.new - - @match.teams.each do |team| - team.users.each do |user| - players_id.push(user.remote_usernames[0].value["id"]) - players.push(user.remote_usernames[0].value["name"]) - end - end - - recent = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/game/by-summoner/#{players_id[0]}/recent?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - - blue = Hash.new - purple = Hash.new - - for i in 0..8 - current_player = players_id[i] - place = players[i] - info = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/game/by-summoner/#{current_player}/recent?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - - if 100 == info["games"][0]["stats"]["team"] - blue.merge!("#{place}" => info["games"][0]["stats"]) - else - purple.merge!("#{place}" => info["games"][0]["stats"]) - end - sleep(1) - end - - #look into this glitch - if 100 == recent["games"][0]["stats"]["team"] - blue.merge!("#{players[9]}" => recent["games"][0]["stats"]) - else - purple.merge!("#{players[9]}" => recent["games"][0]["stats"]) - end - - @purp = purple - @blue = blue - end - - def get_riot_info_fake - pull = "Kaceytron" - #current user information - response = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/by-name/#{pull.downcase}?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - - id = response["#{pull.downcase}"]['id'] - - #recent game information - recent = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/game/by-summoner/#{response["#{pull.downcase}"]['id']}/recent?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - - game_id = recent["games"][0]["gameId"] - - #members of most recent game id's - player1 = recent["games"][0]["fellowPlayers"][0]["summonerId"] - player2 = recent["games"][0]["fellowPlayers"][1]["summonerId"] - player3 = recent["games"][0]["fellowPlayers"][2]["summonerId"] - player4 = recent["games"][0]["fellowPlayers"][3]["summonerId"] - player5 = recent["games"][0]["fellowPlayers"][4]["summonerId"] - player6 = recent["games"][0]["fellowPlayers"][5]["summonerId"] - player7 = recent["games"][0]["fellowPlayers"][6]["summonerId"] - player8 = recent["games"][0]["fellowPlayers"][7]["summonerId"] - player9 = recent["games"][0]["fellowPlayers"][8]["summonerId"] - - players_by_id = [player1, player2, player3, player4, player5, player6, player7, player8, player9] - - #collect summoner names - memb1 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player1}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - memb1 = memb1["#{player1}"] - sleep(1); - - memb2 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player2}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - memb2 = memb2["#{player2}"] - sleep(1); - - memb3 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player3}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - memb3 = memb3["#{player3}"] - sleep(1); - - memb4 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player4}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - memb4 = memb4["#{player4}"] - sleep(1); - - memb5 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player5}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - memb5 = memb5["#{player5}"] - sleep(1); - - memb6 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player6}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - memb6 = memb6["#{player6}"] - sleep(1); - - memb7 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player7}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - memb7 = memb7["#{player7}"] - sleep(1); - - memb8 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player8}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - memb8 = memb8["#{player8}"] - sleep(1); - - memb9 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{player9}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - memb9 = memb9["#{player9}"] - sleep(1); - - memb10 = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/summoner/#{id}/name?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - memb10 = memb10["#{id}"] - - players = ["#{memb1}", "#{memb2}", "#{memb3}", "#{memb4}", "#{memb5}", "#{memb6}", "#{memb7}", "#{memb8}", "#{memb9}", "#{memb10}"] - - sleep(5); - - blue = Hash.new - purple = Hash.new - - for i in 0..8 - current_player = players_by_id[i] - place = players[i] - info = HTTParty.get("https://prod.api.pvp.net/api/lol/na/v1.3/game/by-summoner/#{current_player}/recent?api_key=ad539f86-22fd-474d-9279-79a7a296ac38") - - if 100 == info["games"][0]["stats"]["team"] - blue.merge!("#{place}" => info["games"][0]["stats"]) - else - purple.merge!("#{place}" => info["games"][0]["stats"]) - end - sleep(1) - end - - if 100 == recent["games"][0]["stats"]["team"] - blue.merge!("#{players[9]}" => recent["games"][0]["stats"]) - else - purple.merge!("#{players[9]}" => recent["games"][0]["stats"]) - end - - @purp = purple - @blue = blue - end - # GET /tournaments/1/matches/1 # GET /tournaments/1/matches/1.json def show diff --git a/app/views/matches/show.html.erb b/app/views/matches/show.html.erb index 8344a7a..1c11eb7 100644 --- a/app/views/matches/show.html.erb +++ b/app/views/matches/show.html.erb @@ -21,7 +21,7 @@ function score_peers() { <%= @match.tournament_stage %> </p> -<!-- +<%# Match Status 0 => Created, waiting to start Match Status 1 => Match ready Match Status 2 => Match is running, waiting to finish @@ -34,9 +34,8 @@ function score_peers() { C. The Peer review page that the players will see if status is 3. D. The page everyone will see when status is 4. - Note:- The change of status from 2 to 3 for League of Legends is coming from League Data Pull (RIOT API) - ---> + Note: The change of status from 2 to 3 for League of Legends is coming from League Data Pull (RIOT API) +%> <div> <h2>Teams/users</h2> diff --git a/lib/sampling/peer_review.html.erb b/lib/sampling/peer_review.html.erb new file mode 100644 index 0000000..8ff350e --- /dev/null +++ b/lib/sampling/peer_review.html.erb @@ -0,0 +1,28 @@ +<% if @feedbacks_missing.include? @user %> + <script type="text/javascript"> + function score_peers() { + var list = $('ol#boxes'); + for(var i=0, var len=list.length; i < len; i++) { + if ( i == len-1) { + comma = ""; + } + $('peer_review').value += $('ol#boxes:eq(' + i + ')').text() + comma; + } + } + </script> + <input type="hidden" id="peer_review" name="peer_review" value="" /> + <ol id="peer_review_boxes" class="sortable"> + <% @team.users.reject{|u|u==@user}.each do |user| %><li> + <%= user.user_name %> + <br> + <%# TODO: display more statistics %> + </li><% end %> + </ol> + <%= submit_tag("Submit peer evaluation", :onsubmit => "score_peers()") %> +<% else %> + <p>Still waiting for peer feedback from the following users: + <ul><% @feedbacks_missing.each do |user| %> + <li><%= link_to user %></li> + <% end %></ul> + </p> +<% end %> diff --git a/lib/sampling/peer_review.rb b/lib/sampling/peer_review.rb new file mode 100644 index 0000000..9f1833d --- /dev/null +++ b/lib/sampling/peer_review.rb @@ -0,0 +1,85 @@ +module Sampling + module PeerReview + def self.works_with?(game) + return true + end + + def self.uses_remote? + return false + end + + def self.set_remote_name(user, game, value) + raise "This sampling method doesn't use remote usernames." + end + + def self.get_remote_name(value) + raise "This sampling method doesn't use remote usernames." + end + + def self.sampling_start(match) + # do nothing + end + + def self.sampling_done?(match) + return get_feedbacks_missing(match).empty? + end + + def self.render_user_interaction(match, user) + @user = user + @team = get_team(match) + @feedbacks_missing = get_feedbacks_missing(match) + + require 'erb' + erb_filename = File.join(__FILE__.sub(/\.rb$/, '.svg.erb')) + erb = ERB.new(File.read(erb_filename)) + erb.filename = erb_filename + return erb.result.html_safe + end + + def self.handle_user_interaction(match, 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) + i += 1 + end + end + + private + + def self.get_users(match) + users = [] + match.teams.each{|t| users.concat(t.users)} + return users + end + + def self.get_team(match) + match.teams.find{|t|t.users.include?(@user)} + end + + def self.get_feedbacks(match) + ret = {} + match.statistiscs.where("'name' LIKE 'feedback_from_%'").each do |statistic| + ret[statistic.user] ||= {} + ret[statistic.user][User.find_by_user_name(statistic.name.sub(/^feedback_from_/,''))] = statistic.value + end + return ret + end + + def self.get_feedbacks_missing(match) + require 'set' + ret = Set.new() + + feedback = get_feedbacks(match) + users = get_users(match) + + feedback.each do |feedback| + (users - feedback.keys).each do |user| + ret.push(user) + end + end + + return ret + endx + end +end |