Class: Timeline
- Inherits:
-
Object
- Object
- Timeline
- Defined in:
- lib/math/time_line.rb
Overview
This class collects all data values of the z dimension of a DataSeries for a given pair of coordinates (x,y). For a given resolution size the values are assigned to the nearest value of value_boundaries to be drawn in a terminal or window.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#extrema ⇒ Hash
readonly
private
The extreme values of the timeline.
-
#lines ⇒ Integer
readonly
private
Resolution of the value scale.
-
#mapped_values ⇒ Hash
readonly
The occurence of a boundary value in the z dimension as the result of being the nearest index for a collected value at position z.
-
#value_bondaries ⇒ Array
readonly
private
The values for each output line.
Instance Method Summary collapse
-
#check_and_set_ysize(y_size) ⇒ Object
private
method to check and set the number of values for the y-dimension constraint: at least 5 values in y.
-
#check_dataset_dimension(meta_data) ⇒ Object
private
method to check for correct dataset dimensions.
-
#check_extrema(value) ⇒ Array
private
method to determine if the value is an extreme value and return the value if it is an extreme value.
-
#collect_values(meta_data, data_series, x, y) ⇒ Array
private
this method collects all data values d(x,y) in z.
-
#create_output(mapped_values) ⇒ Object
private
this method creates the basic output which can be visualized.
-
#determine_extrema(values) ⇒ Object
private
this method determines the extreme values of the collected data d(x,y).
-
#determine_nearest_index(values) ⇒ Hash
private
this method calculates for every collected value the index of the interval values @value_boundaries with the least distance.
-
#determine_value_boundaries ⇒ Object
private
this method determines the value boundaries based on the vertical number of lines.
-
#get_nearest_index(value) ⇒ Integer
private
helper methode to calculate the nearest index for the collected data values.
-
#initialize(meta_data, data_series, parameters) ⇒ Timeline
constructor
initialization.
Constructor Details
#initialize(meta_data, data_series, parameters) ⇒ Timeline
initialization
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/math/time_line.rb', line 21 def initialize(, data_series, parameters) check_and_set_ysize(parameters[:y_size]) check_dataset_dimension() values = collect_values(, data_series, parameters[:x], parameters[:y]) determine_extrema(values) # extrema of time values determine_value_boundaries # ordinate values for each line create_output(determine_nearest_index(values)) end |
Instance Attribute Details
#extrema ⇒ Hash (readonly, private)
Returns the extreme values of the timeline.
39 40 41 |
# File 'lib/math/time_line.rb', line 39 def extrema @extrema end |
#lines ⇒ Integer (readonly, private)
Returns resolution of the value scale.
41 42 43 |
# File 'lib/math/time_line.rb', line 41 def lines @lines end |
#mapped_values ⇒ Hash (readonly)
Returns the occurence of a boundary value in the z dimension as the result of being the nearest index for a collected value at position z.
15 16 17 |
# File 'lib/math/time_line.rb', line 15 def mapped_values @mapped_values end |
#value_bondaries ⇒ Array (readonly, private)
Returns the values for each output line.
37 38 39 |
# File 'lib/math/time_line.rb', line 37 def value_bondaries @value_bondaries end |
Instance Method Details
#check_and_set_ysize(y_size) ⇒ Object (private)
method to check and set the number of values for the y-dimension constraint: at least 5 values in y
47 48 49 50 51 52 |
# File 'lib/math/time_line.rb', line 47 def check_and_set_ysize(y_size) if (y_size < 5) raise RangeError, ' Error : invalid y_value of timeline (min.: 5)'.red end @lines = y_size end |
#check_dataset_dimension(meta_data) ⇒ Object (private)
method to check for correct dataset dimensions
57 58 59 60 61 62 |
# File 'lib/math/time_line.rb', line 57 def check_dataset_dimension() if (!TerminalVis.data_repo.dataset_dimension_correct?()) raise RangeError, ' Error: dimension of at least one dataset is incorrect'.red end end |
#check_extrema(value) ⇒ Array (private)
method to determine if the value is an extreme value and return the value if it is an extreme value
167 168 169 170 171 |
# File 'lib/math/time_line.rb', line 167 def check_extrema(value) return [:minimum, value] if (value == @extrema[:minimum]) return [:maximum, value] if (value == @extrema[:maximum]) return [:hit] end |
#collect_values(meta_data, data_series, x, y) ⇒ Array (private)
this method collects all data values d(x,y) in z
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/math/time_line.rb', line 70 def collect_values(, data_series, x, y) values = Array.new() data_series.series.each { |data_set| values << TerminalVis::Interpolation::BilinearInterpolation. bilinear_interpolation(,data_set, x, y) } return values end |
#create_output(mapped_values) ⇒ Object (private)
this method creates the basic output which can be visualized.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/math/time_line.rb', line 144 def create_output(mapped_values) output = Hash.new(@lines) @value_bondaries.each_index { |index| line = Array.new() mapped_values.values.each { |value| if (value[0] == index) line << value[1] else line << [:miss] end } output[@value_bondaries[index]] = line } @mapped_values = output end |
#determine_extrema(values) ⇒ Object (private)
this method determines the extreme values of the collected data d(x,y)
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/math/time_line.rb', line 83 def determine_extrema(values) @extrema = { :maximum => values[0], :minimum => values[0] } values.each { |value| @extrema[:maximum] = value if (value > @extrema[:maximum]) @extrema[:minimum] = value if (value < @extrema[:minimum]) } end |
#determine_nearest_index(values) ⇒ Hash (private)
this method calculates for every collected value the index of the interval values @value_boundaries with the least distance
114 115 116 117 118 119 120 121 122 |
# File 'lib/math/time_line.rb', line 114 def determine_nearest_index(values) mapped_values = Hash.new() values.each { |value| mapped_values[value] = [get_nearest_index(value), check_extrema(value)] } return mapped_values end |
#determine_value_boundaries ⇒ Object (private)
this method determines the value boundaries based on the vertical number of lines
97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/math/time_line.rb', line 97 def determine_value_boundaries delta = (@extrema[:maximum] - @extrema[:minimum]).abs upper_boundary = @extrema[:maximum] + delta / 20.0 # 5 % variance lower_boundary = @extrema[:minimum] - delta / 20.0 # 5 % variance delta = (upper_boundary - lower_boundary).abs / @lines @value_bondaries = [lower_boundary.round(5)] while (lower_boundary.round(5) < upper_boundary.round(5)) lower_boundary += delta @value_bondaries << lower_boundary.round(5) end end |
#get_nearest_index(value) ⇒ Integer (private)
helper methode to calculate the nearest index for the collected data values
127 128 129 130 131 132 133 134 135 136 137 138 139 140 |
# File 'lib/math/time_line.rb', line 127 def get_nearest_index(value) delta = value nearest_index = 0 @value_bondaries.each_index { |index| tmp_delta = (@value_bondaries[index] - value).abs if (tmp_delta < delta) delta = tmp_delta nearest_index = index end } return nearest_index end |