Class: GerbilCharts::Models::MonotonousGraphModel
- Inherits:
-
GraphModel
- Object
- GraphModel
- GerbilCharts::Models::MonotonousGraphModel
- Defined in:
- lib/gerbilcharts/models/monotonous_graph_model.rb
Overview
MonotonousGraphModel
simple graph model (x increases monotonously) All timeseries models are derived from this class
Direct Known Subclasses
Instance Attribute Summary collapse
-
#aggregation_factor ⇒ Object
readonly
how to aggregate? bits/bytes*bucketsize.
-
#rounderx ⇒ Object
readonly
rounded ranges according to presets.
-
#roundery ⇒ Object
readonly
rounded ranges according to presets.
-
#xarr ⇒ Object
readonly
the x values.
-
#xrange ⇒ Object
readonly
raw ranges.
-
#yarr ⇒ Object
readonly
the y values.
-
#yrange ⇒ Object
readonly
raw ranges.
Attributes inherited from GraphModel
#altname, #href, #href_pivot, #name, #transformer, #userdata, #userlabel1, #userlabel2
Instance Method Summary collapse
-
#add(x_val, y_val) ⇒ Object
add a tuple, apply a transformer lambda is supplied by the user.
-
#add_tuples(tarr) ⇒ Object
add an array of values at once (just a convenience method).
- #clear ⇒ Object
- #count ⇒ Object
-
#crop_at(cutoff) ⇒ Object
crop all tuples less than an absolute cutoff [
cutoff] Cutoff value. -
#crop_window(cutoffwindow) ⇒ Object
crop all tuples older than a cutoff window.
- #each_tuple ⇒ Object
- #each_tuple_reverse ⇒ Object
- #first {|, | ... } ⇒ Object
- #formatted_val(rawval) ⇒ Object
-
#get_statistical_analysis ⇒ Object
statistical analysis standard deviation and 95th percentile go here.
-
#initialize(name, opt = {}) ⇒ MonotonousGraphModel
constructor
A new instance of MonotonousGraphModel.
- #latest {|@xarr.last, @yarr.last| ... } ⇒ Object
- #latest_formatted_val ⇒ Object
- #latest_val ⇒ Object
- #latest_x ⇒ Object
- #latest_x_dbtime ⇒ Object
-
#randomizeLastValue ⇒ Object
for test purposes.
- #ranges {|@xrange, @yrange| ... } ⇒ Object
- #round_given_x(rx) ⇒ Object
- #round_given_y(ry) ⇒ Object
- #round_ranges ⇒ Object
-
#tuples_since(x_last) ⇒ Object
all data points newer than a cut off.
Methods inherited from GraphModel
#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, opt = {}) ⇒ MonotonousGraphModel
Returns a new instance of MonotonousGraphModel.
15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 15 def initialize(name,opt={}) super(name) @xrange = RawRange.new @yrange = RawRange.new @rounderx = RoundRange @roundery = RoundRange @xarr=[] @yarr=[] @aggregation_factor=1 end |
Instance Attribute Details
#aggregation_factor ⇒ Object (readonly)
how to aggregate? bits/bytes*bucketsize
13 14 15 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 13 def aggregation_factor @aggregation_factor end |
#rounderx ⇒ Object (readonly)
rounded ranges according to presets
12 13 14 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 12 def rounderx @rounderx end |
#roundery ⇒ Object (readonly)
rounded ranges according to presets
12 13 14 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 12 def roundery @roundery end |
#xarr ⇒ Object (readonly)
the x values
9 10 11 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 9 def xarr @xarr end |
#xrange ⇒ Object (readonly)
raw ranges
11 12 13 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 11 def xrange @xrange end |
#yarr ⇒ Object (readonly)
the y values
10 11 12 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 10 def yarr @yarr end |
#yrange ⇒ Object (readonly)
raw ranges
11 12 13 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 11 def yrange @yrange end |
Instance Method Details
#add(x_val, y_val) ⇒ Object
add a tuple, apply a transformer lambda is supplied by the user
A new datapoint must have a x_val greater than the previous one
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 29 def add(x_val,y_val) if @xarr.length > 0 and @xarr.last > x_val # ignoring out of order data # raise "Expecting monotonous series data" return end # x updates @xrange.update x_val @xarr << x_val # y updates y_val = @transformer.xform(y_val) if @transformer @yarr << y_val @yrange.update y_val end |
#add_tuples(tarr) ⇒ Object
add an array of values at once (just a convenience method)
49 50 51 52 53 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 49 def add_tuples tarr tarr.each do |t| add t[0],t[1] end end |
#clear ⇒ Object
55 56 57 58 59 60 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 55 def clear @xrange.reset @yrange.reset @xarr=[] @yarr=[] end |
#count ⇒ Object
62 63 64 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 62 def count @xarr.size end |
#crop_at(cutoff) ⇒ Object
crop all tuples less than an absolute cutoff [cutoff] Cutoff value
139 140 141 142 143 144 145 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 139 def crop_at(cutoff) until @xarr.empty? or @xarr.first >= cutoff @xarr.shift @yarr.shift end recompute_ranges end |
#crop_window(cutoffwindow) ⇒ Object
crop all tuples older than a cutoff window
cutoffwindow-
older than a number of seconds
131 132 133 134 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 131 def crop_window(cutoffwindow) xcutoff = latest_x - cutoffwindow crop_at(xcutoff) end |
#each_tuple ⇒ Object
115 116 117 118 119 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 115 def each_tuple for i in (0 .. @xarr.length-1) yield @xarr[i],@yarr[i] end end |
#each_tuple_reverse ⇒ Object
121 122 123 124 125 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 121 def each_tuple_reverse @xarr.length.downto(1) do |i| yield @xarr[i-1],@yarr[i-1] end end |
#first {|, | ... } ⇒ Object
82 83 84 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 82 def first yield @xarr[0],@yarr[0] end |
#formatted_val(rawval) ⇒ Object
90 91 92 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 90 def formatted_val rawval return @yrange.format_value(rawval) end |
#get_statistical_analysis ⇒ Object
statistical analysis standard deviation and 95th percentile go here
mode => :normal or :ninety_fifth
returns array 0 = min, 1 = max, 2 = avg, 3 = total, 4 = latest, 5=95th
todo : 5 = stddev
todo : support :ninety_fifth
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 170 def get_statistical_analysis() return [0,0,0,0,0,0] if @yarr.size==0 a = [] a[0]= @yrange.rmin a[1]= @yrange.rmax a[3]=0 @yarr.each do |v| a[3] = a[3] + v end a[2] = a[3]/@yarr.size a[3] = a[3] * @aggregation_factor a[4] = latest_val # 95th statistical rank=(@yarr.size * 0.95).round a[5] = @yarr.sort()[rank-1] return a end |
#latest {|@xarr.last, @yarr.last| ... } ⇒ Object
66 67 68 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 66 def latest yield @xarr.last, @yarr.last end |
#latest_formatted_val ⇒ Object
86 87 88 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 86 def latest_formatted_val return @yrange.format_value(@yarr.last) end |
#latest_val ⇒ Object
74 75 76 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 74 def latest_val return @yarr.last end |
#latest_x ⇒ Object
70 71 72 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 70 def latest_x return @xarr.last end |
#latest_x_dbtime ⇒ Object
78 79 80 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 78 def latest_x_dbtime return (@xarr.last.tv_sec) << 32 end |
#randomizeLastValue ⇒ Object
for test purposes
156 157 158 159 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 156 def randomizeLastValue v=@yarr.last @yarr[@yarr.size-1]=v * ( 0.5 + rand()) end |
#ranges {|@xrange, @yrange| ... } ⇒ Object
94 95 96 97 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 94 def ranges yield @xrange, @yrange if block_given? return @xrange,@yrange end |
#round_given_x(rx) ⇒ Object
107 108 109 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 107 def round_given_x(rx) return @rounderx.new(rx) end |
#round_given_y(ry) ⇒ Object
111 112 113 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 111 def round_given_y(ry) return @roundery.new(ry) end |
#round_ranges ⇒ Object
99 100 101 102 103 104 105 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 99 def round_ranges if block_given? yield @rounderx.new(@xrange), @roundery.new(@yrange) else return @rounderx.new(@xrange), @roundery.new(@yrange) end end |
#tuples_since(x_last) ⇒ Object
all data points newer than a cut off
148 149 150 151 152 153 |
# File 'lib/gerbilcharts/models/monotonous_graph_model.rb', line 148 def tuples_since(x_last) istart = binarySearch(@xarr,x_last,0,@xarr.length) for i in istart..@xarr.length-1 yield @xarr[i],@yarr[i] end end |