Class: GerbilCharts::Models::SampledTimeSeriesGraphModel

Inherits:
TimeSeriesGraphModel show all
Defined in:
lib/gerbilcharts/models/sampled_timeseries_graph_model.rb

Overview

SampledTimeSeriesGraphModel

Time series graph model with sample polling interval we expect discrete points at approx regular intervals a missing interval implies zero value !

This class is mainly used for its sweep methods. TODO: Example here

Instance Attribute Summary collapse

Attributes inherited from MonotonousGraphModel

#aggregation_factor, #rounderx, #roundery, #xarr, #xrange, #yarr, #yrange

Attributes inherited from GraphModel

#altname, #href, #href_pivot, #name, #transformer, #userdata, #userlabel1, #userlabel2

Instance Method Summary collapse

Methods inherited from TimeSeriesGraphModel

#add, #crop_older, #is_timeseries?, #normalize_time_input

Methods inherited from MonotonousGraphModel

#add, #add_tuples, #clear, #count, #crop_at, #crop_window, #each_tuple, #each_tuple_reverse, #first, #formatted_val, #get_statistical_analysis, #latest, #latest_formatted_val, #latest_val, #latest_x, #latest_x_dbtime, #randomizeLastValue, #ranges, #round_given_x, #round_given_y, #round_ranges, #tuples_since

Methods inherited from GraphModel

#count, #each_value_pair, #hasHref?, #hasHrefPivot?, #hasUserData?, #hasUserTips?, #is_timeseries?, #min_max_x, #min_max_y, #recreate, #setHref, #setHrefPivot, #setUserData, #setUserTip1, #setUserTip2, #updateOptions

Constructor Details

#initialize(name, bucketsize, opt = {}) ⇒ SampledTimeSeriesGraphModel

Returns a new instance of SampledTimeSeriesGraphModel.



16
17
18
19
20
# File 'lib/gerbilcharts/models/sampled_timeseries_graph_model.rb', line 16

def initialize(name,bucketsize,opt={})
  super(name,opt)
  raise "Sampled time series model : required param bucketsize missing" unless opt[:bucketsize]
  @bucketsize = opt[:bucketsize] 
end

Instance Attribute Details

#bucketsizeObject (readonly)

sample interval (polling interval)



14
15
16
# File 'lib/gerbilcharts/models/sampled_timeseries_graph_model.rb', line 14

def bucketsize
  @bucketsize
end

Instance Method Details

#begin_sweepObject

begin a sweep session



27
28
29
# File 'lib/gerbilcharts/models/sampled_timeseries_graph_model.rb', line 27

def begin_sweep
    @last_sweep_pos=0
end

#bucket_diff(tv1, tv2) ⇒ Object

how many buckets separate the two buckettimes



73
74
75
# File 'lib/gerbilcharts/models/sampled_timeseries_graph_model.rb', line 73

def bucket_diff(tv1,tv2)
  return (tv2-tv1).abs / @bucketsize
end

#bucket_size_secsObject



77
78
79
# File 'lib/gerbilcharts/models/sampled_timeseries_graph_model.rb', line 77

def bucket_size_secs
	return @bucketsize
end

#sweep(tval) ⇒ Object

sweep this bucket



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/gerbilcharts/models/sampled_timeseries_graph_model.rb', line 49

def sweep(tval)

  return 0 if @xarr.length == 0
  return 0 if @last_sweep_pos >= @xarr.length
  
  
  xv=@xarr[@last_sweep_pos]
  
  if tval < xv
      return 0
  end
  
  nBucks=bucket_diff(xv,tval)
  if nBucks <= 1
      @last_sweep_pos+=1
      rval = @yarr[@last_sweep_pos-1]
  else 
      @last_sweep_pos+= nBucks
  end    
  return rval.nil? ? 0:rval
 
end

#sweep2(tval) ⇒ Object

sweep this bucket



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/gerbilcharts/models/sampled_timeseries_graph_model.rb', line 32

def sweep2(tval)
  
  return 0 if @xarr.length == 0
  return 0 if @last_sweep_pos >= @xarr.length
  
  p "Sweep at tval = #{tval}"
  
  xv=@xarr[@last_sweep_pos]
  if bucket_diff(tval,xv) < 1
      @last_sweep_pos+=1
      return @yarr[@last_sweep_pos-1]
  else 
      return 0
  end    
end

#sweep_intervalObject



22
23
24
# File 'lib/gerbilcharts/models/sampled_timeseries_graph_model.rb', line 22

def sweep_interval
    return @bucketsize
end