Skip to content

Commit

Permalink
player log
Browse files Browse the repository at this point in the history
  • Loading branch information
Fredrik Evertsson committed Jan 27, 2012
2 parents c98ef79 + a52788d commit 6810f66
Show file tree
Hide file tree
Showing 15 changed files with 3,947 additions and 102 deletions.
13 changes: 12 additions & 1 deletion app/controllers/matches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ def create
respond_to do |format|
if @match.save
MatchLog.create({:match_id => @match.id, :msg => "<strong class='log_home_team'>#{@match.home_team.display_name}</strong> just played against <strong class='log_away_team'>#{@match.away_team.display_name}</strong> and it ended #{@match.home_score} - #{@match.away_score}"})


write_to_player_log (all_players)

gm = GameManager.new
gm.EvaluateMatch(@match)
@match.points_trace = gm.points_trace
Expand Down Expand Up @@ -109,4 +111,13 @@ def get_all_teams
@teams = Team.all
end

def write_to_player_log (match_players)
players = Player.all.to_a
standings = players.sort_by{|p| p.score}.reverse

match_players.each do |player|
PlayerLog.create({:player_id => player.id, :msg => "", :score => player.score, :standing => (standings.index(player) + 1)})
end
end

end
13 changes: 11 additions & 2 deletions app/controllers/matches_controller.rb~
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ class MatchesController < ApplicationController

all_players.each do |player|
if all_players.select{|p| p.id == player.id}.length > 1
raise 'Samma spelare i båda lagen'
raise 'Samma spelare i bada lagen'
end
end

respond_to do |format|
if @match.save
MatchLog.create({:match_id => @match.id, :msg => "<strong class='log_home_team'>#{@match.home_team.display_name}</strong> just played against <strong class='log_away_team'>#{@match.away_team.display_name}</strong> and it ended #{@match.home_score} - #{@match.away_score}"})

gm = GameManager.new
gm.EvaluateMatch(@match)
@match.points_trace = gm.points_trace
Expand Down Expand Up @@ -109,4 +109,13 @@ class MatchesController < ApplicationController
@teams = Team.all
end

def write_to_player_log (match_players)
players = Player.all.to_a
standings = players.sort_by{|p| p.score}.reverse

match_players.each do |player|
PlayerLog.create({:player_id => player.id, :msg => "", :score => player.score, :standing => (standings.index(player) + 1)})
end
end

end
29 changes: 28 additions & 1 deletion app/controllers/players_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,39 @@ def show
end

@player_matches.sort_by!{|m| m.created_at}.reverse!

get_player_statistics

respond_to do |format|
format.html # show.html.erb
format.json { render json: @player }
end
end

def get_player_statistics

@players_games_won = 0
@players_games_lost = 0
@players_games_draw = 0

@player.teams.each do |team|
team.matches.each do |m|
winner_team = nil
if(m.home_score > m.away_score)
winner_team = m.home_team
elsif(m.home_score < m.away_score)
winner_team = m.away_team
else
@players_games_draw += 1
end

if(!winner_team.nil? && winner_team.players.include?(@player))
@players_games_won += 1
else
@players_games_lost += 1
end
end
end
end

# GET /players/new
# GET /players/new.json
Expand Down
31 changes: 29 additions & 2 deletions app/controllers/players_controller.rb~
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,40 @@ class PlayersController < ApplicationController
end
end

@player_matches.sort_by!{|m| m.created_at}

@player_matches.sort_by!{|m| m.created_at}.reverse!
get_player_statistics

respond_to do |format|
format.html # show.html.erb
format.json { render json: @player }
end
end

def get_player_statistics

@players_games_won = 0
@players_games_lost = 0
@players_games_draw = 0

@player.teams.each do |team|
team.matches.each do |m|
winner_team = nil
if(m.home_score > m.away_score)
winner_team = m.home_team
elsif(m.home_score < m.away_score)
winner_team = m.away_team
else
@players_games_draw += 1
end

if(winner_team.players.include?(@player))
@players_games_won += 1
else
@players_games_lost += 1
end
end
end
end

# GET /players/new
# GET /players/new.json
Expand Down
6 changes: 5 additions & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@

</head>
<body style="background:#fff">

<% if content_for?(:body_full) %>
<%= yield :body_full %>
<% else %>
<div data-role="page" class="type-index" style="background:#fff">
<a href="#" id="top"></a>
<%= yield :body %>

</div>
<% end %>

</body>
</html>

8 changes: 6 additions & 2 deletions app/views/layouts/application.html.erb~
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<script src="/ui/teams.js"></script>
<script src="/ui/jqm_helper.js"></script>
<script src="/ui/general.js"></script>
<link rel="stylesheet" href="/crap/main.css" />
<link rel="stylesheet" href="/ui/main.css" />

<style>
.hidden {display:none}
Expand All @@ -25,12 +25,16 @@

</head>
<body style="background:#fff">

<% if content_for?(:body_full) %>
<%= yield :body_full %>
<% else %>
<div data-role="page" class="type-index" style="background:#fff">
<a href="#" id="top"></a>
<%= yield :body %>

</div>
<% end %>

</body>
</html>

45 changes: 45 additions & 0 deletions app/views/players/_historic_ranking.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<div data-role="content">


<script>


$(function () {
var d = [[-373597200000, 1000], [-370918800000, 1200], [-368326800000, 1220], [-363056400000, 800], [-360378000000, 780], [-357699600000, 700]];

$.plot($("#placeholder"), [d], { colors: ["#f1375e","#7bd234", "#afb0af"], xaxis: { mode: "time" } });

$("#whole").click(function () {
$.plot($("#placeholder"), [d], { colors: ["#f1375e","#7bd234", "#afb0af"], xaxis: { mode: "time" } });
});

$("#nineties").click(function () {
$.plot($("#placeholder"), [d], {
xaxis: {
mode: "time",
min: (new Date(1990, 1, 1)).getTime(),
max: (new Date(2000, 1, 1)).getTime()
}
});
});

$("#ninetynine").click(function () {
$.plot($("#placeholder"), [d], {
xaxis: {
mode: "time",
minTickSize: [1, "month"],
min: (new Date(1999, 1, 1)).getTime(),
max: (new Date(2000, 1, 1)).getTime()
}
});
});
});



</script>

<div id="placeholder" style="width:300px;height:200px;"></div>
<br />
<br />
</div>
Loading

0 comments on commit 6810f66

Please sign in to comment.