Class: DataOutput::BaseOutput

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

Overview

This class provides basic methods for the other color legends to work with. The children need to define the method print_meta_information which will print the desired meta information for the chosen output. If the child class does not implement this method BaseOutput raises a NotImplementedError.

Direct Known Subclasses

DatasetOutput, RegionOutput

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#data_setDataSet (readonly, private)

Returns the used dataset.

Returns:

  • (DataSet)

    the used dataset



21
22
23
# File 'lib/output/data_output/base_output.rb', line 21

def data_set
  @data_set
end

#legendColorLegend::BaseLegend (readonly, private)

Returns the color legend for the data.

Returns:



17
18
19
# File 'lib/output/data_output/base_output.rb', line 17

def legend
  @legend
end

#with_extreme_valuesboolean (readonly, private)

Returns if the output should highlight the extreme values.

Returns:

  • (boolean)

    if the output should highlight the extreme values



19
20
21
# File 'lib/output/data_output/base_output.rb', line 19

def with_extreme_values
  @with_extreme_values
end

Instance Method Details

#determine_output_type_and_print_value(value) ⇒ Symbol (private)

in case of extreme values this method checks, if the current value is equal one of the two extreme values, if true denote the special markings

Parameters:

  • value (Float)

    the data value which should be visualized

Returns:

  • (Symbol)

    symbol to determine which kind of output was printed



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/output/data_output/base_output.rb', line 37

def determine_output_type_and_print_value(value)
  # create output for maximum
  if (value == @data_set.max_value && @with_extreme_values)
    print '++'.light_gray.bright.black_bg
    return :maximum
  # create output for minimum
  elsif (value == @data_set.min_value && @with_extreme_values)
    print '--'.light_gray.bright.black_bg
    return :minimum
  # create normal output
  else
    print @legend.create_output_string_for(value,'  ')
    return :normal
  end
end

prints the data and the additional informations

Parameters:

  • with_legend (boolean)

    boolean which determines if the extended legend options should be printed



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/output/data_output/base_output.rb', line 80

def print_data(with_legend, domain_x, domain_y)
  data_axis = DataAxis.new()
  extreme_coordinates = print_data_and_get_extrema(domain_y, data_axis)
  data_axis.print_x_axis_values(domain_x)

  puts
  @legend.print_color_legend(with_legend)

  print_extreme_information(extreme_coordinates) if (@with_extreme_values)

  print_meta_information

  puts "\n"
  nil
end

reverses the data to print it in the correct occurence

Returns:

  • (Hash)

    coordinate indices of the extreme values



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/output/data_output/base_output.rb', line 98

def print_data_and_get_extrema(domain_y, data_axis)
  extreme_coordinates = {
    :maximum => Array.new(),
    :minimum => Array.new()
  }

  # reverse the data to start with the highest y-value as the first
  # output line
  reversed_data = @data_set.data.to_a.reverse.to_h

  reversed_data.each_pair { |key, row|
    data_axis.print_y_line_beginning(domain_y, key)
    row.each_index { |index|
      output = determine_output_type_and_print_value(row[index])
      extreme_coordinates[output] << [index, key] if (output != :normal)
    }
    puts
  }

  extreme_coordinates
end

prints the domain information for the given domain

Parameters:

  • domain (DataDomain)

    the domain which information should be printed

  • dim_string (String)

    the string with the domain identifier



123
124
125
126
127
# File 'lib/output/data_output/base_output.rb', line 123

def print_domain_information(domain, dim_string)
  puts "%s-axis with %s from %.1f up to %.1f and steprange %.2f." %
    [dim_string, domain.name, domain.lower, domain.upper, domain.step]
  nil
end

prints the coordinates and values of the extreme values

Parameters:

  • extreme_coordinates (Hash)

    Hash with positions of extrema



55
56
57
58
59
60
61
62
# File 'lib/output/data_output/base_output.rb', line 55

def print_extreme_information(extreme_coordinates)
  puts 'Dataset extreme values:'
  print_extreme_values_for(extreme_coordinates[:maximum],
                           'Maximum (++):', @data_set.max_value)
  print_extreme_values_for(extreme_coordinates[:minimum],
                           'Minimum (--):', @data_set.min_value)
  nil
end

prints all the coordinates of the given extreme value

Parameters:

  • coordinates (Array)

    coordinates of the eytreme values

  • type (String)

    name of the extreme value

  • value (Float)

    the extreme value



68
69
70
71
72
73
74
75
# File 'lib/output/data_output/base_output.rb', line 68

def print_extreme_values_for(coordinates, type, value)
  while (coordinates.size > 0)
      coordinate = coordinates.shift
      color = @legend.create_output_string_for(value,'  ')
      puts "  %s %.3f at %s [%s]." % [type, value, coordinate, color]
  end
  nil
end
This method is abstract.

subclasses need to implement this method

abstract method to print the used meta information

Raises:

  • (NotImplementedError)

    if the subclass does not have this method



132
133
134
135
136
# File 'lib/output/data_output/base_output.rb', line 132

def print_meta_information
  fail NotImplementedError, " Error: the subclass #{self.class} needs " \
       "to implement the method: print_meta_information " \
       "from its base class".red
end

#set_attributes(data_set, with_extreme_values) ⇒ Object (private)

method to set the attributes

Parameters:

  • data_set (DataSet)

    the used dataset

  • with_extreme_values (boolean)

    boolean to determine if extreme values should be marked



27
28
29
30
# File 'lib/output/data_output/base_output.rb', line 27

def set_attributes(data_set, with_extreme_values)
  @data_set = data_set
  @with_extreme_values = with_extreme_values
end