Module: RoundhouseUi::History
- Defined in:
- lib/roundhouse_ui/history.rb
Constant Summary collapse
- RANGES =
{ "7" => "1 week", "30" => "1 month", "90" => "3 months", "180" => "6 months" }.freeze
- DEFAULT_DAYS =
30- MAX_DAYS =
180
Class Method Summary collapse
- .clamp(count) ⇒ Object
-
.days(count = DEFAULT_DAYS, backend: RoundhouseUi.backend) ⇒ Object
Oldest first, so a chart can plot it without reversing.
-
.typical_failure_rate(days) ⇒ Object
A baseline to compare today against.
Class Method Details
.clamp(count) ⇒ Object
42 |
# File 'lib/roundhouse_ui/history.rb', line 42 def clamp(count) = count.to_i.clamp(1, MAX_DAYS) |
.days(count = DEFAULT_DAYS, backend: RoundhouseUi.backend) ⇒ Object
Oldest first, so a chart can plot it without reversing.
33 34 35 36 37 38 39 40 |
# File 'lib/roundhouse_ui/history.rb', line 33 def days(count = DEFAULT_DAYS, backend: RoundhouseUi.backend) return [] unless backend.respond_to?(:history) && backend.supports?(:history) backend.history(clamp(count)) rescue StandardError => e Rails.logger&.warn("[roundhouse] history unavailable: #{e.}") if defined?(Rails) [] end |
.typical_failure_rate(days) ⇒ Object
A baseline to compare today against. The median rather than the mean: one incident day would drag a mean up and make the following week look calm.
46 47 48 49 50 51 52 |
# File 'lib/roundhouse_ui/history.rb', line 46 def typical_failure_rate(days) rates = days.reject(&:quiet?).map(&:failure_rate).sort return nil if rates.empty? mid = rates.size / 2 rates.size.odd? ? rates[mid] : (rates[mid - 1] + rates[mid]) / 2.0 end |