Class: TimelineOutput

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

Overview

This class holds methods to print a previously created timelime into the terminal providing simple axis for the z dimension on the abscissa and the data values on the ordinate.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mapped_values, meta_data, values) ⇒ TimelineOutput

initialization

Parameters:

  • mapped_values (Hash)

    the output hash from Timeline mapping boundary values to z values

  • meta_data (VisMetaData)

    the meta information of the regarded data series

  • values (Hash)

    the mapping of the required start values



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/output/timeline_output.rb', line 19

def initialize(mapped_values, , values)
  @extrema = {
    :maximum => Array.new(),
    :minimum => Array.new()
  }
  output = create_output_array(mapped_values, )

  print_output_head(values[:x],values[:y])

  output.reverse.each { |value|
    puts value
  }
end

Instance Attribute Details

#extremaObject (readonly)

Returns the value of attribute extrema.



33
34
35
# File 'lib/output/timeline_output.rb', line 33

def extrema
  @extrema
end

Instance Method Details

#append_legend_output(output, meta_data, max_size) ⇒ Array (private)

method to append the axis and legend information below the timeline

Parameters:

  • output (Array)

    the String array containing the output

  • meta_data (VisMetaData)

    the used meta data

  • max_size (Integer)

    the number ob padding white spaces

Returns:

  • (Array)

    the String array containing the output appended by the legend output



75
76
77
78
79
80
# File 'lib/output/timeline_output.rb', line 75

def append_legend_output(output, , max_size)
  data_size = .domain_z.number_of_values
  output.unshift(create_axis_string(data_size, max_size))
  output.unshift(create_axis_legend(data_size, max_size, ))
  output.unshift(create_extreme_output(max_size))
end

#check_and_append_values(values, line_string) ⇒ String (private)

method to finish the creation of a line of timeline output

Parameters:

  • values (Array)

    values for one line of the output

  • line_string (String)

    the started string that serves as output for one line

Returns:

  • (String)

    the extended line string



87
88
89
90
91
92
93
94
95
96
# File 'lib/output/timeline_output.rb', line 87

def check_and_append_values(values, line_string)
  values.each { |value|
      if (value[0] == :miss)
        line_string.concat(' ')
      else
        line_string.concat(check_type_and_print(value))
      end
  }
  return line_string
end

#check_type_and_print(value) ⇒ String (private)

method to check the type of hit

Parameters:

  • value (Array)

    an array containing information of the hit and the value if it is an extreme value

Returns:

  • (String)

    the corresponding output string



163
164
165
166
167
168
169
170
171
172
173
# File 'lib/output/timeline_output.rb', line 163

def check_type_and_print(value)
  if (value[0] == :maximum)
    @extrema[:maximum] = value[1]
    return 'x'.red.bright
  elsif (value[0] == :minimum)
    @extrema[:minimum] = value[1]
    return 'x'.cyan.bright
  end

  'x'.green
end

#create_axis_legend(data_size, max_size, meta_data) ⇒ String (private)

method to create value informations for the abscissa

Parameters:

  • data_size (Integer)

    the number of values in the z dimension

  • max_size (Integer)

    length of the greates number on the ordinate

  • meta_data (VisMetaData)

    the meta information of the regarded data series

Returns:

  • (String)

    the value informations for the abscissa



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/output/timeline_output.rb', line 121

def create_axis_legend(data_size, max_size, )
  str = String.new()
  max_size.times {str.concat(' ')}
  position = 1
  start = Integer(.domain_z.lower)

  while (data_size - position >= 10)
    str.concat("%-10s" % start.to_s)
    position += 10
    start += Integer((10 * .domain_z.step).round(1))
  end
  str.concat(finish_axis_legend(data_size - position, start, ))
end

#create_axis_string(data_size, max_size) ⇒ String (private)

method to create the axis of the abscissa

Parameters:

  • data_size (Integer)

    the number of values in the z dimension

  • max_size (Integer)

    length of the greates number on the ordinate

Returns:

  • (String)

    the output string for the abscissa



102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/output/timeline_output.rb', line 102

def create_axis_string(data_size, max_size)
  str = String.new()
  max_size.times {str.concat(' ')}
  str.concat('--|')
  position = 1

  while (data_size - position >= 10)
    str.concat('---------|')
    position += 10
  end
  (data_size - position).times {str.concat('-')}
  str.concat('|')
end

#create_extreme_output(max_size) ⇒ String (private)

method to create the output of the extreme values

Parameters:

  • max_size (Integer)

    the number of padding white strings

Returns:

  • (String)

    the output string for the extreme values



151
152
153
154
155
156
157
# File 'lib/output/timeline_output.rb', line 151

def create_extreme_output(max_size)
  str = String.new()
  max_size.times {str.concat(' ')}
  str.concat("Maximum: #{@extrema[:maximum].round(3)}\n")
  max_size.times {str.concat(' ')}
  str.concat("Minimum: #{@extrema[:minimum].round(3)}")
end

#create_output_array(mapped_values, meta_data) ⇒ Array (private)

method to create the output array, consisting of a string for each line holding ordinate values and markings for the values and two additional lines for the abscissa

Parameters:

  • mapped_values (Hash)

    the output hash from Timeline mapping boundary values to z values

  • meta_data (VisMetaData)

    the meta information of the regarded data series

Returns:

  • (Array)

    array with the strings for each line



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/output/timeline_output.rb', line 53

def create_output_array(mapped_values, )
  output = Array.new()
  max_size = ("%.2f" % mapped_values.keys.last).length

  mapped_values.each_pair { |key, values|
    line_string = "%.2f" % (key)
    if (line_string.length <= max_size)
      (max_size - line_string.length).times { line_string.concat(' ')}
    end
    line_string.concat('| ')
    output << check_and_append_values(values, line_string)
  }

  append_legend_output(output, , max_size)
end

#finish_axis_legend(puffer, start, meta_data) ⇒ String (private)

method to finish the axis legend string

Parameters:

  • puffer (Integer)

    the number of rest characters

  • start (Integer)

    the current number of the axis

  • meta_data (VisMetaData)

    the meta information of the regarded data series

Returns:

  • (String)

    the ending of the axis legend



140
141
142
143
144
145
146
# File 'lib/output/timeline_output.rb', line 140

def finish_axis_legend(puffer, start, )
  str = ("%-#{puffer}s" % start.to_s)
  if (puffer > 5)
    str.concat(Integer(.domain_z.upper).to_s)
  end
  str
end

simple method for printing an output haeder

Parameters:

  • x (Float)

    x-coordinate of the regarded point

  • y (Float)

    y-coordinate of the regarded point



40
41
42
43
44
# File 'lib/output/timeline_output.rb', line 40

def print_output_head(x,y)
  puts "\nPrinting timeline for Coordinate (%.2f, %.2f)" % [x, y]
  puts "\n"
  nil
end