Class: TeaLeaves::SeasonalComponents

Inherits:
Object
  • Object
show all
Defined in:
lib/tealeaves/seasonal_components.rb

Instance Method Summary collapse

Constructor Details

#initialize(period, data) ⇒ SeasonalComponents

Returns a new instance of SeasonalComponents.



3
4
5
6
# File 'lib/tealeaves/seasonal_components.rb', line 3

def initialize(period, data)
  @period = period
  @data = data
end

Instance Method Details

#seasonal_averagesObject



8
9
10
11
12
# File 'lib/tealeaves/seasonal_components.rb', line 8

def seasonal_averages
  @seasonal_averages ||= seasonal_groups.map do |group| 
    group.inject(&:+) / group.size.to_f
  end
end

#seasonal_factors(operation = :-) ⇒ Object



14
15
16
# File 'lib/tealeaves/seasonal_components.rb', line 14

def seasonal_factors(operation = :-)
  @seasonal_factors ||= seasonal_averages.map {|i| i.send(operation, avg) }
end