Class: DatasetScaling

Inherits:
Object
  • Object
show all
Defined in:
lib/scaling/dataset_scaling.rb

Overview

Helper class to generate a scaled DataSet from a (MetaData::VisMetaData, DataSet) pair with the scaling based on the size of the terminal where the script is started.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(meta_data, data_set) ⇒ DatasetScaling

initialization

Parameters:

  • meta_data (VisMetaData)

    the MetaData::VisMetaData of the DataSet that should be scaled

  • data_set (DataSet)

    the data set which should be visualized



22
23
24
25
26
27
28
29
30
# File 'lib/scaling/dataset_scaling.rb', line 22

def initialize(, data_set)
  @meta_data = 
  ts = TerminalSize::TerminalSize.new()
  @lines = ts.lines - 14
  @columns = ts.columns - 10
  check_value_boundaries
  calculate_new_resolution_meta
  @scaled_data_set = calculate_scaled_dataset(data_set)
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



38
39
40
# File 'lib/scaling/dataset_scaling.rb', line 38

def columns
  @columns
end

#linesInteger (readonly, private)

Returns the number of lines of the used terminal.

Returns:

  • (Integer)

    the number of lines of the used terminal



36
37
38
# File 'lib/scaling/dataset_scaling.rb', line 36

def lines
  @lines
end

#meta_dataVisMetaData (readonly, private)

Returns the original MetaData::VisMetaData of the DataSet.

Returns:



34
35
36
# File 'lib/scaling/dataset_scaling.rb', line 34

def 
  @meta_data
end

#scaled_data_setDataSet (readonly)

Returns the scaled DataSet.

Returns:

  • (DataSet)

    the scaled DataSet



16
17
18
# File 'lib/scaling/dataset_scaling.rb', line 16

def scaled_data_set
  @scaled_data_set
end

#scaled_metaVisMetaData (readonly)

Returns the VisMetaData of the scaled DataSet.

Returns:

  • (VisMetaData)

    the VisMetaData of the scaled DataSet



14
15
16
# File 'lib/scaling/dataset_scaling.rb', line 14

def scaled_meta
  @scaled_meta
end

Instance Method Details

#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



89
90
91
# File 'lib/scaling/dataset_scaling.rb', line 89

def add_domain_information(data_domain, new_step)
  [data_domain.name, data_domain.lower, data_domain.upper, new_step]
end

#calculate_new_resolution_metaObject (private)

method to create the meta data object for the scaled dataset



52
53
54
55
56
57
58
59
60
# File 'lib/scaling/dataset_scaling.rb', line 52

def calculate_new_resolution_meta
  # determine new meta information and create ne meta object
  meta_string = [@meta_data.name]
  meta_string.concat(create_new_data_dimensions)
  meta_string.concat(add_domain_information(@meta_data.domain_z,
                                            @meta_data.domain_z.step))
  # return the new meta data object
  @scaled_meta = MetaData::VisMetaData.new(meta_string)
end

#calculate_scaled_dataset(data_set) ⇒ Dataset (private)

method to create the scaled dataset by interpolating new data values

Parameters:

  • data_set (DataSet)

    the data set which should be visualized

Returns:

  • (Dataset)

    the scaled dataset



43
44
45
46
47
48
49
# File 'lib/scaling/dataset_scaling.rb', line 43

def calculate_scaled_dataset(data_set)
  coordinates = determine_coordinates
  values = determine_values

  TerminalVis::Interpolation.region_interpolation(@meta_data, data_set,
                                                  coordinates, values)
end

#calculated_dimension_delta(data_domain) ⇒ Float (private)

method to calculate the half distance of a data domain

Parameters:

Returns:

  • (Float)

    the middle distance of the given data domain



118
119
120
# File 'lib/scaling/dataset_scaling.rb', line 118

def calculated_dimension_delta(data_domain)
  ((data_domain.upper - data_domain.lower) / 2).round(3)
end

#check_value_boundariesObject (private)

method to check if the dimensions of the terminal are big enough to create a useful result



64
65
66
67
68
69
# File 'lib/scaling/dataset_scaling.rb', line 64

def check_value_boundaries
  if (@lines < 9 || @columns < 20)
    raise ArgumentError,
          ' Error: The terminal size is to small for scaled output'.red
  end
end

#create_new_data_dimensionsArray (private)

method to create the entris for the x and y domain of the scaled meta data

Returns:

  • (Array)

    the meta informations for the x and y domain



73
74
75
76
77
78
79
80
81
# File 'lib/scaling/dataset_scaling.rb', line 73

def create_new_data_dimensions
  # map the meta information to the resolution
  delta_x = ((@meta_data.domain_x.upper - @meta_data.domain_x.lower) /
             @columns).round(3) * 2
  delta_y = ((@meta_data.domain_y.upper - @meta_data.domain_y.lower) /
             @lines).round(3)
  meta_string = add_domain_information(@meta_data.domain_x, delta_x)
  meta_string.concat(add_domain_information(@meta_data.domain_y, delta_y))
end

#determine_coordinatesHash (private)

method to retrieve the central coordinate of the dataset

Returns:

  • (Hash)

    a hash with the x and y coordinate



96
97
98
99
100
101
102
103
# File 'lib/scaling/dataset_scaling.rb', line 96

def determine_coordinates
  coordinates = Hash.new()
  coordinates[:x] = @scaled_meta.domain_x.lower +
                    calculated_dimension_delta(@scaled_meta.domain_x)
  coordinates[:y] = @scaled_meta.domain_y.lower +
                    calculated_dimension_delta(@scaled_meta.domain_y)
  return coordinates
end

#determine_valuesHash (private)

method to calculate the required parameter values for the interpolation

Returns:

  • (Hash)

    a hash with the required parameters



107
108
109
110
111
112
# File 'lib/scaling/dataset_scaling.rb', line 107

def determine_values
  { :inter_x => calculated_dimension_delta(@scaled_meta.domain_x),
    :delta_x => @scaled_meta.domain_x.step,
    :inter_y => calculated_dimension_delta(@scaled_meta.domain_y),
    :delta_y => @scaled_meta.domain_y.step }
end