class Sidekiq::History::Charts

Public Class Methods

new(days_previous, start_date = nil) click to toggle source
# File lib/sidekiq/history/charts.rb, line 4
def initialize(days_previous, start_date = nil)
  @start_date = start_date || Time.now.utc.to_date
  @end_date = @start_date - days_previous
end

Public Instance Methods

color_for(worker) click to toggle source
# File lib/sidekiq/history/charts.rb, line 25
def color_for(worker)
  Digest::MD5.hexdigest(worker)[0..5]
    .scan(/../)
    .map{ |color| color.to_i(16) }
    .join ','
end
dates() click to toggle source
# File lib/sidekiq/history/charts.rb, line 32
def dates
  @dates ||= redis_statistic.hash.flat_map(&:keys)
end
information_for(type) click to toggle source
# File lib/sidekiq/history/charts.rb, line 9
def information_for(type)
  redis_statistic.worker_names.map do |worker|
    color = color_for(worker)
    {
      label: worker,
      fillColor: "rgba(#{color},0.2)",
      strokeColor: "rgba(#{color},0.9)",
      pointColor: "rgba(#{color},0.2)",
      pointStrokeColor: '#fff',
      pointHighlightFill: '#fff',
      pointHighlightStroke: 'rgba(220,220,220,1)',
      data: redis_statistic.for_worker(worker).map{ |val| val.fetch(type, 0) }
    }
  end
end

Private Instance Methods

redis_statistic() click to toggle source
# File lib/sidekiq/history/charts.rb, line 38
def redis_statistic
  RedisStatistic.new(@start_date, @end_date)
end