Module: TerminalVis::Output

Defined in:
lib/output/output.rb

Overview

This module takes care about the output in the terminal and serves several methods to create the desired output:

* visual output
* help output

Class Method Summary collapse

Class Method Details

.check_data_range(data_indices) ⇒ Object

checks if the first argument of -d is less than 1

Parameters:

  • data_indices (Hash)

    the indices of the required datasets



171
172
173
174
175
# File 'lib/output/output.rb', line 171

def self.check_data_range(data_indices)
  if (data_indices[:first] < 0)
    raise IndexError, ' Error: first index of -d is less than 1'.red
  end
end

.create_animation(meta_data) ⇒ Object (private)

creates animated output of the whole data series depending on the animation parameter

Parameters:

  • meta_data (VisMetaData)

    the meta data of the data series which should be visualized



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/output/output.rb', line 39

private_class_method def self.create_animation()
  data_series = TerminalVis.data_repo.repository[]
  animation_speed = Integer(TerminalVis.parameter_handler.
                                        repository.parameters[:all])
  data_series.series.each_index { |index|
      create_single_output_at_index(, index)
      if (animation_speed > 0)
        sleep(animation_speed)
      else
        print 'press Enter to continue ...'.green
        # STDIN to read from console when providing parameters in ARGV
        STDIN.gets.chomp
      end
  }
end

.create_delta_output(meta_data) ⇒ Object

creates output when using the parameter -d

Parameters:

  • meta_data (VisMetaData)

    the meta data of the data series which should be visualized



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/output/output.rb', line 58

def self.create_delta_output()
  data_indices = ParameterCollector::determine_indices_for_delta
  data = get_data_for_indices(data_indices, )

  result = DatasetStatistics.subtract_datasets(data[:first_data],
                                               data[:second_data])

  options = get_output_options
  if (!options[:auto_scale])
    DataOutput::DeltaOutput.new(result, , data_indices, options)
  else
    DataOutput::ScaledDeltaOutput.new(result, , data_indices,
                                      options)
  end
end

.create_interpolation_output(meta_data) ⇒ Object

creates output when using the parameter -c interpolation should be applied

Parameters:

  • meta_data (VisMetaData)

    the meta data of the data series where the



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

def self.create_interpolation_output()
  coordinates = ParameterCollector::determine_interpolation_values
  index = TerminalVis.get_and_check_index()
  value = TerminalVis::Interpolation.
          interpolate_for_coordinate(, coordinates,
                                     get_and_check_data(index, ))
  InterpolationOutput.new(value, index, coordinates,
                      TerminalVis.data_repo.repository[])
end

.create_output(meta_data) ⇒ Object

creates output based on MetaData::VisMetaData and parameters

Parameters:

  • meta_data (VisMetaData)

    the meta data of the data series which should be visualized



25
26
27
28
29
30
31
32
33
# File 'lib/output/output.rb', line 25

def self.create_output()
  if (TerminalVis.parameter_handler.repository.parameters[:all])
    create_animation()
  else
    index = TerminalVis.get_and_check_index()
    create_single_output_at_index(, index)
  end
  TerminalVis.data_repo.data_complete?()
end

.create_range_output(meta_data) ⇒ Object

creates output when using the parameter -r

Parameters:

  • meta_data (VisMetaData)

    the meta data of the data series which should be visualized



105
106
107
108
109
110
111
# File 'lib/output/output.rb', line 105

def self.create_range_output()
  data_series = TerminalVis.data_repo.repository[]
  parameters = ParameterCollector::determine_range_parameters

  options = get_output_options
  RangeOutput.new(, data_series, parameters, options)
end

.create_region_interpolation_output(meta_data) ⇒ Object

creates output when using the parameter -s

Parameters:

  • meta_data (VisMetaData)

    the meta data of the data series which should be used for the interpolation



90
91
92
93
94
95
96
97
98
99
100
# File 'lib/output/output.rb', line 90

def self.create_region_interpolation_output()
  coordinates = ParameterCollector::determine_interpolation_values
  values = ParameterCollector::determine_region_parameters
  values[:index] = TerminalVis.get_and_check_index()
  values = values.merge(get_output_options)
  output = TerminalVis::Interpolation.region_interpolation(,
                        get_and_check_data(values[:index], ),
                        coordinates, values)
  DataOutput::RegionOutput.new(output, coordinates,
              TerminalVis.data_repo.repository[], values)
end

.create_single_output_at_index(meta_data, index) ⇒ Object (private)

creates default output or output with an index using -i

Parameters:

  • meta_data (VisMetaData)

    the meta data of the data series which should be visualized

  • index (Integer)

    the index of the dataset which should be visualized



133
134
135
136
137
138
139
140
141
142
# File 'lib/output/output.rb', line 133

private_class_method def self.create_single_output_at_index(, index)
  options = get_output_options
  options[:index] = index
  data_series = TerminalVis.data_repo.repository[]
  if (!options[:auto_scale])
    DataOutput::SingleOutput.new(data_series, , options)
  else
    DataOutput::ScaledDatasetOutput.new(data_series, , options)
  end
end

.create_timeline(meta_data) ⇒ Object

creates a time line for the parameter -t

Parameters:

  • meta_data (VisMetaData)

    the meta data of the data series from which the timeline should be created



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/output/output.rb', line 116

def self.create_timeline()
  data_series = TerminalVis.data_repo.repository[]
  values = ParameterCollector::determine_timeline_values
  options = get_output_options
  if (!options[:auto_scale])
    timeline = Timeline.new(, data_series, values)
  else
    timeline = TimelineScaling.new(, data_series, values)
     = timeline.scaled_meta
  end
  TimelineOutput.new(timeline.mapped_values, , values)
end

.get_and_check_data(index, meta_data) ⇒ DataSet (private)

checks if the returned data exists, nil means data access outside the boundaries of the data

Parameters:

  • index (Integer)

    the provided index

  • meta_data (VisMetaData)

    the corresponding meta data

Returns:

  • (DataSet)

    the dataset for the given index and meta data

Raises:

  • (IndexError)

    if no data was selected which means the index is not within the bounds of the provided meta data



184
185
186
187
188
189
190
191
# File 'lib/output/output.rb', line 184

private_class_method def self.get_and_check_data(index, )
  data = TerminalVis.data_repo.repository[].series[index]
  if (data == nil)
    raise IndexError,
          " Error: argument #{index + 1} from -d is out of bounds".red
  end
  return data
end

.get_data_for_indices(data_indices, meta_data) ⇒ Hash (private)

method to check the datasets specified by the data indices and return the data

Parameters:

  • data_indices (Hash)

    the indices of the required datasets

  • meta_data (VisMetaData)

    the corresponding meta data

Returns:

  • (Hash)

    a hash containing the selected datasets



161
162
163
164
165
166
167
# File 'lib/output/output.rb', line 161

private_class_method def self.get_data_for_indices(data_indices, )
  data = Hash.new()
  check_data_range(data_indices)
  data[:first_data] = get_and_check_data(data_indices[:first], )
  data[:second_data] = get_and_check_data(data_indices[:second], )
  return data
end

.get_output_optionsHash (private)

method to determine output options for the extreme values and the extended legend

Returns:

  • (Hash)

    the hash with the boolean parameters for the options



147
148
149
150
151
152
153
154
# File 'lib/output/output.rb', line 147

private_class_method def self.get_output_options
  { :extreme_values =>
    TerminalVis.parameter_handler.repository.parameters[:extreme],
    :legend =>
    TerminalVis.option_handler.options.repository[:legend_extend],
    :auto_scale =>
    TerminalVis::option_handler.options.repository[:auto_scale] }
end