Class: InterpolationOutput

Inherits:
Object
  • Object
show all
Defined in:
lib/output/interpolation_output.rb

Overview

Output class to vizualize results issued within the scope of interpolation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value, index, coordinates, data_series) ⇒ InterpolationOutput

initialization

Parameters:

  • value (Float)

    the interpolation value

  • index (Integer)

    the indes of the used dataset

  • coordinates (Hash)

    the coordinates for the interpolation

  • data_series (DataSeries)

    the data series that contains dataset used in the interpolation



18
19
20
21
22
23
24
25
26
27
# File 'lib/output/interpolation_output.rb', line 18

def initialize(value, index, coordinates, data_series)
  boundary_points = TerminalVis::Interpolation::BilinearInterpolation.
                    get_boundary_points(coordinates[:x], coordinates[:y])

  print_result(value, boundary_points, data_series)

  puts "\nInterpolated value for coordinate (#{coordinates[:x]}, " \
         "#{coordinates[:y]}) of dataset #{index} with result: " \
         "#{value.round(3)}."
end

Instance Attribute Details

#color_legendColorData (readonly, private)

Returns the color legend used for the dataset.

Returns:

  • (ColorData)

    the color legend used for the dataset



31
32
33
# File 'lib/output/interpolation_output.rb', line 31

def color_legend
  @color_legend
end

Instance Method Details

#create_colored_substrings(value) ⇒ String (private)

method the visualize the values for the output

Parameters:

  • value (Float)

    a data value or an interpolation value

Returns:

  • (String)

    the colored string for the given value



79
80
81
82
83
84
85
# File 'lib/output/interpolation_output.rb', line 79

def create_colored_substrings(value)
  if (value != nil)
    @color_legend.create_output_string_for(value, '  ')
  else
    print '  '
  end
end

method to print the line for two boundary points

Parameters:

  • point1 (DataPoint)

    the point with x_min and y = const.

  • point2 (DataPoint)

    the point with x_max and y = const.



51
52
53
54
55
56
57
# File 'lib/output/interpolation_output.rb', line 51

def print_boundary_line(point1, point2)
  print_times_blank(4)
  print "#{create_colored_substrings(point1.value)}"
  print_times_blank(10)
  puts "#{create_colored_substrings(point2.value)}"
  nil
end

method to print the line with the interpolation value

Parameters:

  • value (Float)

    the interpolated value



61
62
63
64
65
66
67
# File 'lib/output/interpolation_output.rb', line 61

def print_interpolation_line(value)
  print_times_blank(10)
  print "#{create_colored_substrings(value)}"
  print_times_blank(8)
  puts "(#{value.round(3)})"
  nil
end

method to print the colored result of the interpolation

Parameters:

  • value (Float)

    the interpolated value

  • boundary_points (Hash)

    a hash containing the four used boundary points of the interpolation

  • data_series (DataSeries)

    the data series that contains dataset used in the interpolation



39
40
41
42
43
44
45
46
# File 'lib/output/interpolation_output.rb', line 39

def print_result(value, boundary_points, data_series)
  @color_legend = ColorLegend::ColorData.new(data_series.min_value,
                                             data_series.max_value)
  print_boundary_line(boundary_points[:d_xy1], boundary_points[:d_x1y1])
  print_interpolation_line(value)
  print_boundary_line(boundary_points[:d_xy], boundary_points[:d_x1y])
  nil
end

method to print the required white spaces

Parameters:

  • amount (Integer)

    the number of required white spaces



71
72
73
74
# File 'lib/output/interpolation_output.rb', line 71

def print_times_blank(amount)
  amount.times { print ' '}
  nil
end