Permalink
Browse files

Add stats motherflipper

  • Loading branch information...
wakeless committed May 18, 2012
1 parent fbefc34 commit 8b93d2f43ee680dc40af0a8996c0081cc31d1fcf
Showing with 15 additions and 1 deletion.
  1. +5 −0 app/controllers/stats_controller.rb
  2. +7 −0 app/models/game.rb
  3. +2 −1 app/views/layouts/application.html.erb
  4. +1 −0 config/routes.rb
@@ -0,0 +1,5 @@
+class StatsController < ApplicationController
+ def index
+ @stats = Game.by_player_week_day
+ end
+end
View
@@ -57,5 +57,12 @@ def update_twitter
def to_twitter
"#{winner.to_twitter} beat #{loser.to_twitter} at #{sport.to_twitter}"
end
+
+ def self.by_player_week_day
+
+ select("player_id, count(player_id) as cnt, strftime('%w', created_at)").from("(select distinct winner_id as player_id, id, created_at from games union select distinct loser_id as player_id, id, created_at from games)").group("player_id, strftime('%w', created_at)").order("strftime('%w', created_at)")
+ #select("winner_id, loser_id, strftime('%w', created_at) as day, count(*) as cnt").group("winner_id, loser_id, strftime('%w', created_at)")
+ end
+
end
@@ -19,6 +19,7 @@
<link href="images/apple-touch-icon.png" rel="apple-touch-icon">
<link href="images/apple-touch-icon-72x72.png" rel="apple-touch-icon" sizes="72x72">
<link href="images/apple-touch-icon-114x114.png" rel="apple-touch-icon" sizes="114x114">
+ <%= javascript_include_tag "application" %>
</head>
<body>
@@ -37,6 +38,7 @@
<li><%= link_to "Leaderboard", leaderboard_path %></li>
<li><%= link_to "Sports", sports_path %></li>
<li><%= link_to "Players", players_path %></li>
+ <li><%= link_to "Stats", stats_path %></li>
</ul>
</div><!--/.nav-collapse -->
</div>
@@ -74,7 +76,6 @@
<!-- Le javascript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
- <%= javascript_include_tag "application" %>
</body>
</html>
View
@@ -4,6 +4,7 @@
resources :games
resources :players
+ resources :stats
match "/leaderboard/(:id)" => "leaderboard#index", :as => 'leaderboard'
root :to => "leaderboard#index"

0 comments on commit 8b93d2f

Please sign in to comment.