Class: Metrify::MetrifyController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- Metrify::MetrifyController
- Defined in:
- app/controllers/metrify/metrify_controller.rb
Instance Method Summary collapse
-
#chart_data ⇒ Object
chart_data.json?filters[]=letters&filters[]=animals&filters[]=not_furry.
-
#get_stat_arr(stat, historical_stats = @historical_site_stats) ⇒ Object
def set_metrify_model; end.
- #graph_stats ⇒ Object
-
#index ⇒ Object
def self.included(base) base.class_eval do before_filter :set_metrify_class end base.extend ClassMethods base.send :include, InstanceMethods base.helper MetrifyHelper end.
- #number_of_stats ⇒ Object
- #parsed_stat_names ⇒ Object
- #set_metrify_class ⇒ Object
- #setup_historical_stats ⇒ Object
- #unit ⇒ Object
Instance Method Details
#chart_data ⇒ Object
chart_data.json?filters[]=letters&filters[]=animals&filters[]=not_furry
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'app/controllers/metrify/metrify_controller.rb', line 57 def chart_data @stat_names = @metrified_class.stat_names(parsed_stat_names, params[:filters]) @unit = params[:unit] || unit @number_of_stats = params[:number_of_stats] || number_of_stats @historical_site_stats = @metrified_class.historical_values(Time.zone.now.beginning_of_week, number_of_stats, unit) json = @stat_names.map{|s| {:name => @metrified_class.display_name(s), :pointInterval => (1.send(@unit) * 1000), :pointStart => (@number_of_stats.send(@unit).ago.to_i * 1000), :data => @historical_site_stats.map{|h| h.send(s)}}} setup_historical_stats respond_to do |format| format.json { render :layout => false , :json => @stat_names.map{|s| {:name => @metrified_class.display_name(s), :pointInterval => (1.send(@unit) * 1000), :pointStart => (@number_of_stats.send(@unit).ago.to_i * 1000), :data => get_stat_arr(s, @historical_site_stats)}}.to_json } end end |
#get_stat_arr(stat, historical_stats = @historical_site_stats) ⇒ Object
def set_metrify_model; end
84 85 86 87 88 89 90 91 92 |
# File 'app/controllers/metrify/metrify_controller.rb', line 84 def get_stat_arr(stat, historical_stats = @historical_site_stats) stat_over_time = [] historical_stats.each do |s| value = s.send(stat) value = 0 if !value stat_over_time << value end stat_over_time end |
#graph_stats ⇒ Object
46 47 48 49 50 |
# File 'app/controllers/metrify/metrify_controller.rb', line 46 def graph_stats prepare_for_graph @stat_names = parsed_stat_names end |
#index ⇒ Object
def self.included(base)
base.class_eval do
before_filter :set_metrify_class
end
base.extend ClassMethods
base.send :include, InstanceMethods
base.helper MetrifyHelper
end
15 16 17 18 19 |
# File 'app/controllers/metrify/metrify_controller.rb', line 15 def index setup_historical_stats @stat_names = @metrified_class.stat_names @historical_site_stats.reverse! end |
#number_of_stats ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'app/controllers/metrify/metrify_controller.rb', line 31 def number_of_stats number = case unit.to_sym when :month then 12 when :week then 52 when :day then 30 else 48 #hour end end |
#parsed_stat_names ⇒ Object
52 53 54 |
# File 'app/controllers/metrify/metrify_controller.rb', line 52 def parsed_stat_names !params[:stat_names].blank? ? params[:stat_names].split(',') : @metrified_class.stat_names end |
#set_metrify_class ⇒ Object
21 22 23 |
# File 'app/controllers/metrify/metrify_controller.rb', line 21 def set_metrify_class @metrified_class = metrify_model end |
#setup_historical_stats ⇒ Object
25 26 27 28 29 |
# File 'app/controllers/metrify/metrify_controller.rb', line 25 def setup_historical_stats @unit = unit @number_of_stats = number_of_stats @historical_site_stats = @metrified_class.historical_values(Time.zone.now.beginning_of_week, number_of_stats, unit) end |
#unit ⇒ Object
42 43 44 |
# File 'app/controllers/metrify/metrify_controller.rb', line 42 def unit params[:unit] || :week end |