Module: HowAreWeDoing::ActsAsAnalytical::SingletonMethods

Defined in:
lib/how_are_we_doing/acts_as_analytical.rb

Instance Method Summary collapse

Instance Method Details

#json_data_for_bar_graph(params) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/how_are_we_doing/acts_as_analytical.rb', line 38

def json_data_for_bar_graph(params)
  start_date = params[:start_date]
  end_date = params[:end_date]
  analytical_class = params[:analytical_type].classify.constantize
  analytical_ids = params[:analytical_ids] ? params[:analytical_ids].split(",") : nil
  
  objects = analytical_ids ? analytical_class.where(:id => analytical_ids) : analytical_class.limit(params[:analytical_limit]||6).where(:created_at => start_date.beginning_of_day.to_date..(end_date+1.day).beginning_of_day.to_date)
  
  returning arr = [] do
    objects.each_with_index do |object,i|
      arr << [i,object.send("#{self.name.underscore.pluralize}".to_sym).where("#{self.name.underscore.pluralize}".to_sym => {:created_at => start_date.beginning_of_day.to_date..(end_date+1.day).beginning_of_day.to_date}).count]
    end
  end
end

#json_data_for_line_graph(params) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/how_are_we_doing/acts_as_analytical.rb', line 24

def json_data_for_line_graph(params)
  start_date = params[:start_date]
  end_date = params[:end_date]
  parent_type = params[:parent_type]
  parent_id = params[:parent_id]
  assoc = parent_type.classify.constantize.find(parent_id) if parent_id and parent_type
  arr = []
  start_date.to_date.upto(end_date.to_date) do |day|
    objects = (assoc ? assoc.send("#{self.name.underscore.pluralize}") : self).where("#{self.name.underscore.pluralize}".to_sym => {:created_at => day.beginning_of_day..day.end_of_day})
    arr << ["#{day.beginning_of_day.to_time.to_i}000",objects.count]
  end
  arr
end

#json_labels_for_bar_graph(params) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/how_are_we_doing/acts_as_analytical.rb', line 53

def json_labels_for_bar_graph(params)
  start_date = params[:start_date]
  end_date = params[:end_date]
  analytical_class = params[:analytical_type].classify.constantize
  analytical_ids = params[:analytical_ids] ? params[:analytical_ids].split(",") : nil
  
  objects = analytical_ids ? analytical_class.where(:id => analytical_ids) : analytical_class.limit(params[:analytical_limit]||6).where(:created_at => start_date.beginning_of_day.to_date..(end_date+1.day).beginning_of_day.to_date)
  
  returning arr = [] do
    objects.each_with_index do |object,i|
      arr << [i,object.send("to_#{self.name.underscore}_chart_label")]
    end
  end
end

#json_labels_for_line_graph(params) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/how_are_we_doing/acts_as_analytical.rb', line 68

def json_labels_for_line_graph(params)
  start_date = params[:start_date]
  end_date = params[:end_date]
  parent_type = params[:parent_type]
  parent_id = params[:parent_id]
  assoc = parent_type.classify.constantize.find(parent_id) if parent_id and parent_type
  
  objects = (assoc ? assoc.send("#{self.name.underscore.pluralize}") : self).where("#{self.name.underscore.pluralize}".to_sym => {:created_at => start_date.beginning_of_day..end_date.end_of_day})
  count = objects.count
  objects = objects.where("#{self.name.underscore}able_id".to_sym.not_eq => nil)
  label = objects.first.nil? ? "" : objects.first.send("#{self.name.underscore}able").send("to_#{self.name.underscore}_chart_label")

  [count,label]
end