Class: Archaeo::CdxTimeline

Inherits:
Object
  • Object
show all
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

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

Returns:

  • (Boolean)


44
45
46
# File 'lib/archaeo/cdx_timeline.rb', line 44

def empty?
  @buckets.empty?
end

#inspectObject



52
53
54
# File 'lib/archaeo/cdx_timeline.rb', line 52

def inspect
  "#<#{self.class.name} #{total} snapshots in #{@buckets.size} buckets>"
end

#peakObject



29
30
31
# File 'lib/archaeo/cdx_timeline.rb', line 29

def peak
  @buckets.max_by(&:last)
end

#sizeObject



48
49
50
# File 'lib/archaeo/cdx_timeline.rb', line 48

def size
  @buckets.size
end

#spanObject



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_aObject



21
22
23
# File 'lib/archaeo/cdx_timeline.rb', line 21

def to_a
  @buckets.sort_by(&:first)
end

#to_hObject



25
26
27
# File 'lib/archaeo/cdx_timeline.rb', line 25

def to_h
  @buckets.dup
end

#totalObject



33
34
35
# File 'lib/archaeo/cdx_timeline.rb', line 33

def total
  @buckets.values.sum
end