Sha256: 5b3051d21e6361734c2c700b6049fee14195ff48eef9c8e6dc2d5bb250b348ed
Contents?: true
Size: 1 KB
Versions: 6
Compression:
Stored size: 1 KB
Contents
module Tabs module Helpers extend self def timestamp_range(period, resolution, default_value=0) period = normalize_period(period, resolution) dt = period.first Hash[([].tap do |arr| arr << dt while (dt = dt + 1.send(resolution)) <= period.last arr << dt.utc end end).map { |ts| [ts, default_value] }] end def normalize_period(period, resolution) period_start = Tabs::Resolution.normalize(resolution, period.first) period_end = Tabs::Resolution.normalize(resolution, period.last) (period_start..period_end) end def extract_date_from_key(stat_key, resolution) date_str = stat_key.split(":").last Tabs::Resolution.deserialize(resolution, date_str) end def fill_missing_dates(period, date_value_pairs, resolution, default_value=0) all_timestamps = timestamp_range(period, resolution, default_value) merged = all_timestamps.merge(Hash[date_value_pairs]) merged.to_a end end end
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
tabs-0.5.6 | lib/tabs/helpers.rb |
tabs-0.5.5 | lib/tabs/helpers.rb |
tabs-0.5.4 | lib/tabs/helpers.rb |
tabs-0.5.3 | lib/tabs/helpers.rb |
tabs-0.5.2 | lib/tabs/helpers.rb |
tabs-0.5.0 | lib/tabs/helpers.rb |