Class: TimelineScaling

Inherits:
Timeline show all
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

Attributes inherited from Timeline

#extrema, #lines, #mapped_values, #value_bondaries

Instance Method Summary collapse

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

Parameters:

  • meta_data (VisMetaData)

    the meta information of the regarded data series

  • data_series (DataSeries)

    the data series which should be used

  • parameters (Hash)

    a hash containing the required parameter



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

#columnsInteger (readonly, private)

Returns the number of fields per row of the used terminal.

Returns:

  • (Integer)

    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_metaVisMetaData (readonly)

Returns the scaled meta data based on the terminal size.

Returns:

  • (VisMetaData)

    the scaled meta data based on the terminal size



17
18
19
# File 'lib/scaling/timeline_scaling.rb', line 17

def scaled_meta
  @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

Parameters:

  • index_old (Integer)

    the lower index representing the last unused value

  • index_new (Float)

    the current value based on the calculated delta

  • values (Array)

    the collected values d(x,y)

Returns:

  • (Float)

    the determined value that should be added



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

Parameters:

Returns:

  • (Array)

    an array containing the string values for the given domain



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

Parameters:

  • index_old (Integer)

    the lower index representing the last unused value

  • index_new (Float)

    the current value based on the calculated delta

  • values (Array)

    the collected values d(x,y)

Returns:

  • (Float)

    the mean value of the values from index_old to index_new



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_sizeObject (private)

method to set the available lines and columns based on the terminal size

Raises:

  • (RangeError)

    if the value of one dimension undercut the given threshold value



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

Parameters:

  • meta_data (VisMetaData)

    the meta information of the regarded data series



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)
  meta_string = [.name]
  meta_string.concat(add_domain_information(.domain_x,
                                            .domain_x.step))
  meta_string.concat(add_domain_information(.domain_y,
                                            .domain_y.step))
  meta_string.concat(add_domain_information(.domain_z, delta_z))
  # return the new meta data object
  @scaled_meta = MetaData::VisMetaData.new(meta_string)
end

#scale_values(values, meta_data) ⇒ Array (private)

method to scale the calculated values if required

Parameters:

  • values (Array)

    the collected values d(x,y)

  • meta_data (VisMetaData)

    the meta information of the regarded data series

Returns:

  • (Array)

    the scaled values d(x,y)



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

Parameters:

  • values (Array)

    the collected values d(x,y)

  • meta_data (VisMetaData)

    the meta information of the regarded data series

Returns:

  • (Array)

    the scaled values d(x,y)



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