Sha256: a9e791290cf3ed393dd3addf56464f48022f471b356a0b586ef6382a1b669134
Contents?: true
Size: 1.06 KB
Versions: 1
Compression:
Stored size: 1.06 KB
Contents
# helpers for parsing and validating input module BatsdDash module GraphHelper ## # This method works directly against values def collect_for_graph(values, opts = {}) values.tap do |pts| # remap the values pts.map! { |pt| [pt['timestamp'].to_i * 1000, pt['value'].to_f] } # apply zerofill zero_fill!(pts, opts[:range], opts[:interval]) unless pts.empty? || !opts[:zero_fill] end end ## # The data better be normalized to the interval otherwise # this method may get pissed def zero_fill!(values, range, step) return values if step.zero? # convert to milisec step *= 1000 values.tap do |data| # start from the first timestamp time = data.first.first + step index = 0 while obj = data[index += 1] current = obj.first next if current <= time if current == time time += step next end data.insert(index, [time, 0]) time += step end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
batsd-dash-0.2.0 | lib/batsd-dash/graph.rb |