Class: TimelineScaling
- Defined in:
- lib/scaling/timeline_scaling.rb
Overview
This class collects all data values of the z dimension of a DataSeries for a given pair of coordinates (x,y) in the same way its parent class Timeline does. It uses the dimension of the calling terminal to determine the number of values. If the datasize exceeds the number of columns the dataset will be scaled.
Instance Attribute Summary collapse
-
#columns ⇒ Integer
readonly
private
The number of fields per row of the used terminal.
-
#scaled_meta ⇒ VisMetaData
readonly
The scaled meta data based on the terminal size.
Attributes inherited from Timeline
#extrema, #lines, #mapped_values, #value_bondaries
Instance Method Summary collapse
-
#add_data_entry(index_old, index_new, values) ⇒ Float
private
method to determine which value needs to be added at the actual index.
-
#add_domain_information(data_domain, new_step) ⇒ Array
private
method to add the required parameter to the MetaData::VisMetaData string.
-
#calculate_mean_value(index_old, index_new, values) ⇒ Float
private
method to calculate the mean value for the values between the indices.
-
#get_and_set_size ⇒ Object
private
method to set the available lines and columns based on the terminal size.
-
#initialize(meta_data, data_series, parameters) ⇒ TimelineScaling
constructor
initialization.
-
#scale_meta_data(meta_data) ⇒ Object
private
method to adjust the MetaData::VisMetaData and replace the z-dimension.
-
#scale_values(values, meta_data) ⇒ Array
private
method to scale the calculated values if required.
-
#scale_with_mean_values(values, meta_data) ⇒ Array
private
method to generate a mapping where all available values are mapped on the number of columns specified by the terminal size.
Methods inherited from Timeline
#check_and_set_ysize, #check_dataset_dimension, #check_extrema, #collect_values, #create_output, #determine_extrema, #determine_nearest_index, #determine_value_boundaries, #get_nearest_index
Constructor Details
#initialize(meta_data, data_series, parameters) ⇒ TimelineScaling
initialization
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/scaling/timeline_scaling.rb', line 23 def initialize(, data_series, parameters) get_and_set_size check_dataset_dimension() values = collect_values(, data_series, parameters[:x], parameters[:y]) values = scale_values(values, ) 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
#columns ⇒ Integer (readonly, private)
Returns the number of fields per row of the used terminal.
40 41 42 |
# File 'lib/scaling/timeline_scaling.rb', line 40 def columns @columns end |
#scaled_meta ⇒ VisMetaData (readonly)
Returns the scaled meta data based on the terminal size.
17 18 19 |
# File 'lib/scaling/timeline_scaling.rb', line 17 def @scaled_meta end |
Instance Method Details
#add_data_entry(index_old, index_new, values) ⇒ Float (private)
method to determine which value needs to be added at the actual index
99 100 101 102 103 104 105 |
# File 'lib/scaling/timeline_scaling.rb', line 99 def add_data_entry(index_old, index_new, values) if (index_new.round - index_old > 1) return calculate_mean_value(index_old, index_new, values) else return values[index_old] end end |
#add_domain_information(data_domain, new_step) ⇒ Array (private)
method to add the required parameter to the MetaData::VisMetaData string
144 145 146 |
# File 'lib/scaling/timeline_scaling.rb', line 144 def add_domain_information(data_domain, new_step) [data_domain.name, data_domain.lower, data_domain.upper, new_step] end |
#calculate_mean_value(index_old, index_new, values) ⇒ Float (private)
method to calculate the mean value for the values between the indices
113 114 115 116 117 118 119 120 121 |
# File 'lib/scaling/timeline_scaling.rb', line 113 def calculate_mean_value(index_old, index_new, values) temp = index_old means = Array.new() while (temp < index_new.round) means << values[temp] temp += 1 end Statistic.mean_value(means) end |
#get_and_set_size ⇒ Object (private)
method to set the available lines and columns based on the terminal size
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/scaling/timeline_scaling.rb', line 45 def get_and_set_size ts = TerminalSize::TerminalSize.new() @lines = ts.lines - 8 @columns = ts.columns - 10 if (@lines < 5) raise RangeError, ' Error : invalid y_size of timeline (min.: 5)'.red end if (@columns < 10) raise RangeError, ' Error : invalid x_size of timeline (min.: 10)'.red end end |
#scale_meta_data(meta_data) ⇒ Object (private)
method to adjust the MetaData::VisMetaData and replace the z-dimension
125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/scaling/timeline_scaling.rb', line 125 def () delta_z = ((.domain_z.number_of_values) / Float(@columns)).round(5) = [.name] .concat(add_domain_information(.domain_x, .domain_x.step)) .concat(add_domain_information(.domain_y, .domain_y.step)) .concat(add_domain_information(.domain_z, delta_z)) # return the new meta data object @scaled_meta = MetaData::VisMetaData.new() end |
#scale_values(values, meta_data) ⇒ Array (private)
method to scale the calculated values if required
61 62 63 64 65 66 67 68 69 |
# File 'lib/scaling/timeline_scaling.rb', line 61 def scale_values(values, ) if (values.length > @columns) () scale_with_mean_values(values, ) else @scaled_meta = return values end end |
#scale_with_mean_values(values, meta_data) ⇒ Array (private)
method to generate a mapping where all available values are mapped on the number of columns specified by the terminal size
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/scaling/timeline_scaling.rb', line 76 def scale_with_mean_values(values, ) scaled_values = Array.new() delta_x = ((.domain_z.number_of_values) / Float(@columns)).round(5) index_old = 0 index_new = delta_x while (index_new.round < values.length) scaled_values << add_data_entry(index_old, index_new, values) index_old = Integer(index_new.round) index_new += delta_x end scaled_values << values[index_old] return scaled_values end |