added segments to stats
This commit is contained in:
parent
76b34ec75d
commit
673397508f
2 changed files with 40 additions and 12 deletions
|
|
@ -32,8 +32,19 @@ class AdminsController < ApplicationController
|
|||
def stats
|
||||
@popular_tags = ActsAsTaggableOn::Tagging.joins(:tag).limit(15).count(:group => :tag, :order => 'count(taggings.id) DESC')
|
||||
|
||||
case params[:range]
|
||||
when "week"
|
||||
range = 1.week
|
||||
when "2weeks"
|
||||
range = 2.weeks
|
||||
when "month"
|
||||
range = 1.month
|
||||
else
|
||||
range = 1.day
|
||||
end
|
||||
|
||||
[Post, Comment, AspectMembership, User].each do |model|
|
||||
create_hash(model)
|
||||
create_hash(model, :range => range)
|
||||
end
|
||||
|
||||
@posts_per_day = Post.count(:group => "DATE(created_at)", :conditions => ["created_at >= ?", Date.today - 21.days], :order => "DATE(created_at) ASC")
|
||||
|
|
@ -49,13 +60,13 @@ class AdminsController < ApplicationController
|
|||
sprintf( "%0.02f", ((today-yesterday) / yesterday.to_f)*100).to_f
|
||||
end
|
||||
|
||||
def create_hash(model)
|
||||
def create_hash(model, opts={})
|
||||
opts[:range] ||= 1.day
|
||||
plural = model.to_s.underscore.pluralize
|
||||
eval(<<DATA
|
||||
@#{plural} = {
|
||||
:day_before => #{model}.where(:created_at => ((Time.now.midnight - 2.days)..Time.now.midnight - 1.day)).count,
|
||||
:yesterday => #{model}.where(:created_at => ((Time.now.midnight - 1.day)..Time.now.midnight)).count,
|
||||
:today => #{model}.where(:created_at => ((Time.now.midnight)..Time.now)).count
|
||||
:day_before => #{model}.where(:created_at => ((Time.now.midnight - #{opts[:range]*2})..Time.now.midnight - #{opts[:range]})).count,
|
||||
:yesterday => #{model}.where(:created_at => ((Time.now.midnight - #{opts[:range]})..Time.now.midnight)).count
|
||||
}
|
||||
@#{plural}[:change] = percent_change(@#{plural}[:yesterday], @#{plural}[:day_before])
|
||||
DATA
|
||||
|
|
|
|||
|
|
@ -13,8 +13,25 @@
|
|||
|
||||
.span-24.last
|
||||
|
||||
%div{:style => "float:right;"}
|
||||
= form_tag('/admins/stats', :method => 'get') do
|
||||
%select{:name => 'range'}
|
||||
%option{:value => 'daily', :selected => ('selected' if params[:range] == 'daily')}
|
||||
Daily
|
||||
%option{:value => 'week', :selected => ('selected' if params[:range] == 'week')}
|
||||
Week
|
||||
%option{:value => '2weeks', :selected => ('selected' if params[:range] == '2weeks')}
|
||||
2 Weeks
|
||||
%option{:value => 'month', :selected => ('selected' if params[:range] == 'month')}
|
||||
Month
|
||||
|
||||
= submit_tag 'go'
|
||||
|
||||
%h3
|
||||
Yesterday's results
|
||||
Results from the
|
||||
%b
|
||||
= params[:range]
|
||||
segment
|
||||
|
||||
- [:posts, :comments, :aspect_memberships, :users].each do |name|
|
||||
- model = eval("@#{name.to_s}")
|
||||
|
|
@ -40,13 +57,13 @@
|
|||
%br
|
||||
%br
|
||||
|
||||
%h3
|
||||
Posts over time
|
||||
/%h3
|
||||
/ Posts over time
|
||||
|
||||
#stats_graph{:style => "text-align:right;position:relative;vertical-align:bottom;background-color:#eee;"}
|
||||
= @posts_per_day.inspect
|
||||
/- @posts_per_day.each do |key, val|
|
||||
/ .asdo{:style => "display:inline-block;width:35px;vertical-align:bottom;background-color:#666;height:#{(val/@most_posts_within)*200}px;"}
|
||||
/#stats_graph{:style => "text-align:right;position:relative;vertical-align:bottom;background-color:#eee;"}
|
||||
/ = @posts_per_day.inspect
|
||||
/ /- @posts_per_day.each do |key, val|
|
||||
/ / .asdo{:style => "display:inline-block;width:35px;vertical-align:bottom;background-color:#666;height:#{(val/@most_posts_within)*200}px;"}
|
||||
|
||||
|
||||
%br
|
||||
|
|
|
|||
Loading…
Reference in a new issue