module Resque::Plugins::Analytics::Server::Helpers

Public Instance Methods

chart_data(data, kpi) click to toggle source
# File lib/resque-analytics/server.rb, line 27
def chart_data(data, kpi)
  legend_keys.map { |key| @data[kpi][key].to_i || 0 }
end
chart_it(title, legend, data) click to toggle source
# File lib/resque-analytics/server.rb, line 31
def chart_it(title, legend, data)
  Gchart.bar(
    data: data,
    title: title,
    format: "image_tag",
    size: "1000x300",
    axis_with_labels: ['x,y'],
    bar_width_and_spacing: '6',
    axis_range: [[-90,0,-5], [0, data.map(&:max).sum ]],
    legend: legend,
    legend_position: 'top',
    bar_colors: ['000000', '0088FF']
  )
end
counters_for(job, kpi) click to toggle source
# File lib/resque-analytics/server.rb, line 11
def counters_for(job, kpi)
  kpi_keys = Resque.redis.keys("resque-analytics:*").sort { |a,b| a <=> b }
  kpi_keys.inject({}) { |res, key| res[key.split(':').last] = Resque.redis.hget(key, "#{job}:#{kpi}"); res}
end
legend_keys() click to toggle source
# File lib/resque-analytics/server.rb, line 23
def legend_keys
  @legend_keys ||= (-90..0).map { |number| number.days.from_now.strftime("%y_%m_%d")}
end
measured_jobs() click to toggle source
# File lib/resque-analytics/server.rb, line 16
def measured_jobs
  yesterday = 1.day.ago.strftime("%y_%m_%d")
  today = Time.now.strftime("%y_%m_%d")
  fields = Resque.redis.hkeys("resque-analytics:#{yesterday}") + Resque.redis.hkeys("resque-analytics:#{today}")
  fields.map { |field| field.split(':').first }.uniq.sort { |a,b| a <=> b }
end