Class Admin::StatsController
In: app/controllers/admin/stats_controller.rb
Parent: Admin::BaseController

Controlador para las estadísticas en tiempo real de últimas IPs, últimas búsquedas en Google, últimos referers y páginas más visitadas

Methods

contents   index   midterm  

Public Instance methods

[Source]

     # File app/controllers/admin/stats_controller.rb, line 83
 83:   def contents
 84:     @days = params[:days] ? params[:days].to_i : 100
 85:     
 86:     if @days == 100
 87:       conditions = nil
 88:       created_at_conditions = nil
 89:     elsif @days == 0
 90:       begin
 91:         @start_date = Date.parse("#{params[:start][:year]}-#{params[:start][:month]}-#{params[:start][:day]}")
 92:         @end_date = Date.parse("#{params[:end][:year]}-#{params[:end][:month]}-#{params[:end][:day]}")
 93:         conditions = ["published_at BETWEEN ? AND ?", @start_date, @end_date]
 94:         created_at_conditions = ["created_at BETWEEN ? AND ?", @start_date, @end_date]
 95:         @periodo = "#{I18n.localize(@start_date, :format => :long)} - #{I18n.localize(@end_date, :format => :long)}"
 96:       rescue ArgumentError => err
 97:         flash[:error] = "Las fechas elegidas no son correctas"
 98:         redirect_to contents_admin_stats_path and return
 99:       end
100:     elsif @days > 30
101:       flash[:error] = "El intervalo elegido no es correcto"
102:       redirect_to contents_admin_stats_path and return
103:     else
104:       conditions = ["published_at BETWEEN now()-?::interval AND now()", "#{@days}days"]
105:       created_at_conditions = ["created_at BETWEEN now()-?::interval AND now()", "#{@days}days"]
106:       @periodo = "#{I18n.localize(@days.days.ago.to_date, :format => :long)} - #{I18n.localize(Date.today, :format => :long)}"
107:     end
108:     
109:     @tab = 3
110:     @news_counter = News.count(:conditions => conditions)
111:     @shared_events_counter = Event.count(:conditions => conditions)
112:     @private_events_counter = ScheduleEvent.count(:conditions => created_at_conditions)
113:     @pages_counter = Page.count(:conditions => conditions)
114:     @posts_counter = Post.count(:conditions => conditions)
115:     @links_counter = Link.count(:conditions => conditions)
116:     @proposals_counter = Proposal.approved.count(:conditions => conditions)
117:     @comments_counter = Comment.count(:conditions => created_at_conditions)
118:   end

[Source]

    # File app/controllers/admin/stats_controller.rb, line 4
 4:   def index
 5:     @tab = 1
 6:     
 7:     @last_ips_counter = Stats.last_ips_counter
 8:     @streaming_watchers = Stats.streaming_watchers
 9:     
10:     @dep_id = 0
11:     @hours = params[:hours] ? params[:hours].to_i : 2
12:         
13:     @referers = Stats.last_referers(@hours)
14: 
15:     @googles = Stats.last_googles
16: 
17:     @top_pages = Stats.top_pages(@hours)
18:     
19:     @comments = Comment.find :all, 
20:       :select => "commentable_id, commentable_type, count(id)", 
21:       :conditions => ["created_at between now()-?::interval and now()", "#{@hours} hours"],
22:       :group => "commentable_id, commentable_type",
23:       :order => "count desc",
24:       :limit => 10
25:   end

[Source]

    # File app/controllers/admin/stats_controller.rb, line 27
27:   def midterm
28:     @tab = 2
29:     @days = params[:days] ? params[:days].to_i : 1
30:     @actual_days = @days
31:     
32:     if @days == 0
33:       begin
34:         @start_date = Date.parse("#{params[:start][:year]}-#{params[:start][:month]}-#{params[:start][:day]}")
35:         @end_date = Date.parse("#{params[:end][:year]}-#{params[:end][:month]}-#{params[:end][:day]}")
36:         @actual_days = (@end_date-@start_date).to_i
37:         if @actual_days > 60
38:           flash[:notice] = "Sólo se puede consultar un máximo de 2 meses atrás"
39:           redirect_to contents_admin_stats_path and return
40:         end
41:         @periodo = "#{I18n.localize(@start_date, :format => :long)} - #{I18n.localize(@end_date, :format => :long)}"
42:       rescue ArgumentError => err
43:         flash[:error] = "Las fechas elegidas no son correctas"
44:         redirect_to contents_admin_stats_path and return
45:       end
46:     elsif @days > 30
47:       flash[:error] = "El intervalo elegido no es correcto"
48:       redirect_to contents_admin_stats_path and return
49:     else
50:       @periodo = "#{I18n.localize(@days.days.ago.to_date, :format => :long)} - #{I18n.localize(Date.today, :format => :long)}"
51:     end
52:     
53:     
54:     
55:     
56:     
57:     # @last_ips_counter = Stats.last_ips_counter
58:     top_videos = Stats.top_videos(@actual_days)
59:     @top_videos = top_videos[:videos]
60:     @videos_sum = top_videos[:sum]        
61:     
62:     top_rsss = Stats.top_rsss(@actual_days)
63:     @top_rsss = top_rsss[:videos]
64:     @rsss_sum = top_rsss[:sum]
65:     
66:     @top_rated_comments = Comment.find :all, 
67:       :select => "comments.id, substring(comments.body from 0 for 50) as body, commentable_id, count(rating)",
68:       :joins => :ratings,
69:       :conditions => ["rating=1 AND created_at BETWEEN now()-?::interval AND now()", "#{@actual_days}days"],
70:       :group => "comments.id, comments.body, commentable_id",
71:       :order => "count DESC",
72:       :limit => 10
73:       
74:     @bottom_rated_comments = Comment.find :all, 
75:       :select => "comments.id, substring(comments.body from 0 for 50) as body, commentable_id, count(rating)",
76:       :joins => :ratings,
77:       :conditions => ["rating=0 AND created_at BETWEEN now()-?::interval AND now()", "#{@actual_days}days"],
78:       :group => "comments.id, comments.body, commentable_id",
79:       :order => "count DESC",
80:       :limit => 10    
81:   end

[Validate]