Class: GerbilCharts::Models::TimeSeriesGraphModel

Inherits:
MonotonousGraphModel show all
Defined in:
lib/gerbilcharts/models/time_series_graph_model.rb

Overview

TimeSeriesGraphModel

time series graph model (special case of monotonous) we expect discrete points, mainly the x_values are interpreted as timestamp therefore we can construct the appropriate preset axis labels.

Eg. We can create round labels such as 8:15 instead of 8:16:47

Instance Attribute Summary

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 MonotonousGraphModel

#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?, #min_max_x, #min_max_y, #recreate, #setHref, #setHrefPivot, #setUserData, #setUserTip1, #setUserTip2, #updateOptions

Constructor Details

#initialize(name, opt = {}) ⇒ TimeSeriesGraphModel

Returns a new instance of TimeSeriesGraphModel.



12
13
14
15
16
# File 'lib/gerbilcharts/models/time_series_graph_model.rb', line 12

def initialize(name,opt={})
  super(name,opt)
  @rounderx=RoundTimeRange
  @roundery=RoundRange
end

Instance Method Details

#add(timeobj, val) ⇒ Object

we add Timeval objects (those that respond to tv_sec)



19
20
21
# File 'lib/gerbilcharts/models/time_series_graph_model.rb', line 19

def add(timeobj, val)
  super normalize_time_input(timeobj),val 
end

#crop_older(cutofftime) ⇒ Object

crop older than the given timestamp



24
25
26
# File 'lib/gerbilcharts/models/time_series_graph_model.rb', line 24

def crop_older(cutofftime)
    crop_at(normalize_time_input(cutofftime))
end

#is_timeseries?Boolean

just a check if we need time series

Returns:

  • (Boolean)


29
30
31
# File 'lib/gerbilcharts/models/time_series_graph_model.rb', line 29

def is_timeseries?
  return true
end

#normalize_time_input(tin) ⇒ Object

normalize input timestamp



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

def normalize_time_input(tin)
  if tin.is_a? Time
return tin
  elsif tin.is_a? Integer
if tin > 0xffffffff
  return Time.at(tin>>32)
else
  return Time.at(tin)
end
  end

  raise "Timeseries graph model expects Time, or Integer represent time"
end