class BaseVelocitator

Attributes

date_range[R]

modifiers on the end result image being rendered. Essentially these are the boundries of the graph

gem_name[RW]
max_value[R]

modifiers on the end result image being rendered. Essentially these are the boundries of the graph

min_value[R]

modifiers on the end result image being rendered. Essentially these are the boundries of the graph

root[R]

modifiers on the end result image being rendered. Essentially these are the boundries of the graph

versions[RW]

Public Class Methods

create(options) click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 13
def self.create(options)
  Factory.new(options).velocitator
end

Public Instance Methods

built_at(version)
Alias for: time_built
date_range=(args) click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 39
def date_range=(args); @passed_date_range = args && args.map{|t| time_format_str(t) } ;end
effective_date_range() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 44
def effective_date_range
  @passed_date_range || default_date_range
end
effective_days_in_range() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 51
def effective_days_in_range
  compute_day_range_from_start_end(effective_start_time,effective_end_time)
end
effective_end_time() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 49
def effective_end_time; effective_date_range.last ;end
effective_max_value() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 55
def effective_max_value
  @passed_max_value || default_max_value
end
effective_min_value() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 59
def effective_min_value
  @passed_min_value || default_min_value
end
effective_start_time() click to toggle source

some sugar

# File lib/gem_velocity/velocitators/base_velocitator.rb, line 48
def effective_start_time; effective_date_range.first ;end
graph(root_arg = root, range = effective_date_range, min = effective_min_value, max = effective_max_value) click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 17
def graph(root_arg = root, range = effective_date_range, min = effective_min_value, max = effective_max_value)
  set_overwritable_attrs(root_arg,range,min,max)
  file = gruff_builder(root, graph_options).write
  puts "Wrote graph to #{file}"
  file
end
graph_options() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 24
def graph_options
  opts = {
    :title => title,
    :labels => ({1 => time_format_str_small(effective_start_time), (line_datas.first.size-2) => time_format_str_small(effective_end_time) }),
    :max_value => effective_max_value,
    :min_value => effective_min_value,
    :line_datas => line_datas,
    :hide_legend => hide_legend?,
    :type => self.class.to_s
  }
end
max_value=(max) click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 40
def max_value=(max); @passed_max_value = max ;end
min_value=(min) click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 41
def min_value=(min); @passed_min_value = min ;end
num_downloads() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 72
def num_downloads
  sum_of_all_versions = totals_map_by_version.values.map {|t| t[:version_downloads]}.sum
  ActiveSupport::NumberHelper.number_to_delimited(sum_of_all_versions)
end
root=(path) click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 42
def root=(path); @root = path ;end
time_built(version) click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 77
def time_built(version)
  gem_data.versions_built_at[version]
end
Also aliased as: built_at
totals_map_by_version() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 63
def totals_map_by_version
  h = {}
  versions.map do |v|
    total_for_version = gem_data.total_for_version(v)
    h.merge!(v => total_for_version)
  end
  h
end

Private Instance Methods

after_init() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 84
def after_init
  raise ArgumentError, "Need to pass a gem name!" if (gem_name.nil? || gem_name.empty?)
  raise ArgumentError, "Need to pass versions!" if versions.compact.empty?
  validate_correct_gem
  validate_correct_versions
  gem_data.parallel_fetch_for(versions)
end
base_max_for(verzionz) click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 132
def base_max_for(verzionz)
  totals = []
  verzionz.each {|v|
    totals << downloads_per_day(v).map {|day,total| total}
  }
  totals.flatten.compact.max
end
default_date_range() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 114
def default_date_range
  [ default_start, default_end ]
end
default_end() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 110
def default_end
  default_end = time_format_str(Time.now)
end
default_min_value() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 118
def default_min_value
  0
end
downloads_per_day(version) click to toggle source

returns # “2013-10-10” => 45

# File lib/gem_velocity/velocitators/base_velocitator.rb, line 141
def downloads_per_day(version)
  @downloads_per_day ||= Hash.new
  return @downloads_per_day[version] if @downloads_per_day[version]
  ret = Hash.new(0)
  from_api = gem_data.prefetched_downloads_metadata(version, default_start, default_end)
  from_api.each_cons(2) do |p,n|
    #day,total pairs
    curr_total = n.last
    day = n.first
    previous_day = p.first
    ret[day] = curr_total + ret[previous_day]
  end
  @downloads_per_day[version] = ret
end
gem_data() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 156
def gem_data
  # need this memoized so the gem_data memoization works for the same instance
  @gem_data ||= GemData.new(@gem_name)
end
gruff_builder(path,graph_opts) click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 161
def gruff_builder(path,graph_opts)
  GruffBuilder.new(path || Dir.pwd, nil, versions_for_legends, gem_name, graph_opts)
end
line_datas() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 122
def line_datas
  # aggregated and single are both just one, just line_data, but default to this
  # because of the multiplexer, since it does have line_datas
  [line_data]
end
set_overwritable_attrs(root_arg,range,min,max) click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 103
def set_overwritable_attrs(root_arg,range,min,max)
  self.date_range = range
  self.root = root_arg
  self.max_value = max
  self.min_value = min
end
validate_correct_gem() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 98
def validate_correct_gem
  # this will bomb out if bad version is passed.
  gem_data.versions_metadata
end
validate_correct_versions() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 92
def validate_correct_versions
  versions.each do |v|
    gem_data.versions.include?(v) || raise(NoSuchVersion,"version #{v} not found for #{gem_name}.")
  end
end
versions_for_legends() click to toggle source
# File lib/gem_velocity/velocitators/base_velocitator.rb, line 128
def versions_for_legends
  [version]
end