Module: PredictabilityEngine::Calculators::Cfd
- Defined in:
- lib/predictability_engine/calculators/cfd.rb
Class Method Summary collapse
- .calculate(work_items, start_date: nil, end_date: nil) ⇒ Object
- .collect_events(work_items) ⇒ Object
- .forecast_series(items) ⇒ Object
- .forecast_summary(items) ⇒ Object
- .to_coordinates(cfd, start_date) ⇒ Object
- .with_forecast(work_items, percentiles: PredictabilityEngine::DEFAULT_PERCENTILES) {|{ summary: forecast, max_days: percentiles.map { |p| forecast[:"p#{p}"] }.max }| ... } ⇒ Object
Class Method Details
.calculate(work_items, start_date: nil, end_date: nil) ⇒ Object
8 9 10 11 12 13 14 |
# File 'lib/predictability_engine/calculators/cfd.rb', line 8 def self.calculate(work_items, start_date: nil, end_date: nil) events = collect_events(work_items) return [] if events.empty? results = process_events(events) fill_daily_gaps(results, start_date, end_date) end |
.collect_events(work_items) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/predictability_engine/calculators/cfd.rb', line 16 def self.collect_events(work_items) arrival_data = work_items.map do |i| { date: i.start_date || i.end_date || PredictabilityEngine.today, type: :arrived } end departure_data = work_items.select(&:completed?).map { |i| { date: i.end_date, type: :departed } } (arrival_data + departure_data).sort_by { |e| [e[:date], e[:type] == :arrived ? 0 : 1] } end |
.forecast_series(items) ⇒ Object
28 29 30 |
# File 'lib/predictability_engine/calculators/cfd.rb', line 28 def self.forecast_series(items, **) CfdForecaster.forecast_series(items, **) end |
.forecast_summary(items) ⇒ Object
24 25 26 |
# File 'lib/predictability_engine/calculators/cfd.rb', line 24 def self.forecast_summary(items, **) CfdForecaster.forecast_summary(items, **) end |
.to_coordinates(cfd, start_date) ⇒ Object
71 72 73 74 75 |
# File 'lib/predictability_engine/calculators/cfd.rb', line 71 def self.to_coordinates(cfd, start_date) { dates: cfd.map { |d| (d[:date] - start_date).to_i }, arrived: cfd.map { |d| d[:arrived] }, departed: cfd.map { |d| d[:departed] } } end |
.with_forecast(work_items, percentiles: PredictabilityEngine::DEFAULT_PERCENTILES) {|{ summary: forecast, max_days: percentiles.map { |p| forecast[:"p#{p}"] }.max }| ... } ⇒ Object
64 65 66 67 68 69 |
# File 'lib/predictability_engine/calculators/cfd.rb', line 64 def self.with_forecast(work_items, percentiles: PredictabilityEngine::DEFAULT_PERCENTILES) forecast = forecast_summary(work_items, percentiles: percentiles) return yield(nil) unless forecast yield({ summary: forecast, max_days: percentiles.map { |p| forecast[:"p#{p}"] }.max }) end |