Class: Archaeo::CdxTimeline
- Inherits:
-
Object
- Object
- Archaeo::CdxTimeline
- Defined in:
- lib/archaeo/cdx_timeline.rb
Overview
Time-bucketed snapshot frequency analysis.
Groups snapshots by configurable time buckets (day, week, month, year) for frequency analysis and coverage reporting.
Constant Summary collapse
- BUCKET_FORMATS =
{ day: "%Y%m%d", week: "%YW%V", month: "%Y%m", year: "%Y", }.freeze
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(snapshots, bucket_size: :month) ⇒ CdxTimeline
constructor
A new instance of CdxTimeline.
- #inspect ⇒ Object
- #peak ⇒ Object
- #size ⇒ Object
- #span ⇒ Object
- #to_a ⇒ Object
- #to_h ⇒ Object
- #total ⇒ Object
Constructor Details
#initialize(snapshots, bucket_size: :month) ⇒ CdxTimeline
Returns a new instance of CdxTimeline.
16 17 18 19 |
# File 'lib/archaeo/cdx_timeline.rb', line 16 def initialize(snapshots, bucket_size: :month) @bucket_size = bucket_size @buckets = build_buckets(snapshots) end |
Instance Method Details
#empty? ⇒ Boolean
44 45 46 |
# File 'lib/archaeo/cdx_timeline.rb', line 44 def empty? @buckets.empty? end |
#inspect ⇒ Object
52 53 54 |
# File 'lib/archaeo/cdx_timeline.rb', line 52 def inspect "#<#{self.class.name} #{total} snapshots in #{@buckets.size} buckets>" end |
#peak ⇒ Object
29 30 31 |
# File 'lib/archaeo/cdx_timeline.rb', line 29 def peak @buckets.max_by(&:last) end |
#size ⇒ Object
48 49 50 |
# File 'lib/archaeo/cdx_timeline.rb', line 48 def size @buckets.size end |
#span ⇒ Object
37 38 39 40 41 42 |
# File 'lib/archaeo/cdx_timeline.rb', line 37 def span keys = @buckets.keys return nil if keys.empty? [keys.first, keys.last] end |
#to_a ⇒ Object
21 22 23 |
# File 'lib/archaeo/cdx_timeline.rb', line 21 def to_a @buckets.sort_by(&:first) end |
#to_h ⇒ Object
25 26 27 |
# File 'lib/archaeo/cdx_timeline.rb', line 25 def to_h @buckets.dup end |
#total ⇒ Object
33 34 35 |
# File 'lib/archaeo/cdx_timeline.rb', line 33 def total @buckets.values.sum end |