Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Basic statistics support - no graphing
  • Loading branch information
Michael Pearson committed May 16, 2009
1 parent 0c5953a commit a10cefb
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/controllers/statuses_controller.rb
Expand Up @@ -51,6 +51,12 @@ def search
render_tweets
end

def statistics
@top_ten_twats = Tweet.top_ten_updaters

@twats_per_hour = Tweet.updates_per_hour
end

def user_timeline
limit = params[:all] ? 100000000000 : 25
@tweets = @user.public_tweets.find(:all,:include => :user,:limit => limit)
Expand Down
20 changes: 20 additions & 0 deletions app/models/tweet.rb
Expand Up @@ -30,4 +30,24 @@ def to_map(include_user=true)
end
ret
end

def self.top_ten_updaters
find_by_sql(<<-EOF)
SELECT count(tweets.tweet) AS updates, users.username AS name
FROM tweets
INNER JOIN users ON tweets.user_id = users.id
WHERE tweets.tweet_type != 'direct'
GROUP BY user_id ORDER BY updates DESC LIMIT 10
EOF
end

def self.updates_per_hour
hours = {}
all(:conditions => "tweet_type != 'direct'").each do |tweet|
hours[tweet.created_at.hour] ||= 1
hours[tweet.created_at.hour] += 1
end
hours
end

end
4 changes: 4 additions & 0 deletions app/views/statuses/_sidebar.html.erb
Expand Up @@ -29,6 +29,10 @@
<a href="/favorites" id="favorites_tab">Favorites</a></li>
<li>
<a href="/public_timeline" id="public_timeline_tab">Everyone</a></li>
<li>
<a href="/statistics" id="search_tab">POPULARITY CONTEST</a></li>
</li>

</ul>

<div class="section last">
Expand Down
17 changes: 17 additions & 0 deletions app/views/statuses/statistics.html.erb
@@ -0,0 +1,17 @@
<% setup(:title=>"Statistics", :body_id=>"replies", :body_classes=>"status replyable", :css=>['timeline']) %>

<h2 class="timeline-header">Statistics and Graphs</h2>
<h3 class="timeline-subheader">Top Ten Twats</h3>
<ol>
<% @top_ten_twats.each do |twat|%>
<li><%= twat[:name] %>: <%= twat[:updates] %> updates
<% end %>
</ol>
<h3 class="timeline-subheader">Twats Per Hour</h3>
<ol>
<% @twats_per_hour.keys.sort.each do |hour|%>
<li><%= hour %>: <%= @twats_per_hour[hour] %> updates
<% end %>
</ol>

<%= render :partial => "statuses/sidebar" %>
1 change: 1 addition & 0 deletions config/routes.rb
Expand Up @@ -8,6 +8,7 @@
map.connect "/friends", :controller => "statuses",:action => "friends"
map.connect "/followers", :controller => "statuses",:action => "followers"
map.connect "/search", :controller => "statuses",:action => "search"
map.connect "/statistics", :controller => "statuses",:action => "statistics"
map.connect "/public_timeline", :controller => "statuses",:action => "public_timeline"

map.connect "/statuses/public_timeline.:format", :controller => "statuses", :action => "friends_timeline"
Expand Down

0 comments on commit a10cefb

Please sign in to comment.