Class: Ecu::Kennfeld
- Defined in:
- lib/ecu/labels/kennfeld.rb,
lib/ecu/interfaces/dcm/kennfeld.rb,
lib/ecu/interfaces/mfile/kennfeld.rb
Direct Known Subclasses
Constant Summary
Constants inherited from Label
Instance Attribute Summary collapse
-
#unit ⇒ Object
readonly
Returns the value of attribute unit.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
-
#xdim ⇒ Object
readonly
Returns the value of attribute xdim.
-
#xunit ⇒ Object
readonly
Returns the value of attribute xunit.
-
#xvalue ⇒ Object
readonly
Returns the value of attribute xvalue.
-
#ydim ⇒ Object
readonly
Returns the value of attribute ydim.
-
#yunit ⇒ Object
readonly
Returns the value of attribute yunit.
-
#yvalue ⇒ Object
readonly
Returns the value of attribute yvalue.
Attributes inherited from Label
#description, #function, #name
Class Method Summary collapse
Instance Method Summary collapse
- #bytesize ⇒ Object
- #equality_properties ⇒ Object
-
#initialize(name:, xdim:, ydim:, xvalue:, yvalue:, value:, xunit: nil, yunit: nil, unit: nil, function: nil, description: nil) ⇒ Kennfeld
constructor
A new instance of Kennfeld.
- #properties ⇒ Object
- #reinterpx(new_xvalue) ⇒ Object
- #reinterpy(new_yvalue) ⇒ Object
- #round_to(n) ⇒ Object
- #to_dcm ⇒ Object
- #to_mfile ⇒ Object
- #to_s(detail: false) ⇒ Object
- #value_at(x, y) ⇒ Object
Methods inherited from Label
#<=>, #==, #===, from_dcm, from_lab, #hash, #init_error, #match, #to_h, #to_lab, #type, #valuestats, #with
Constructor Details
#initialize(name:, xdim:, ydim:, xvalue:, yvalue:, value:, xunit: nil, yunit: nil, unit: nil, function: nil, description: nil) ⇒ Kennfeld
Returns a new instance of Kennfeld.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/ecu/labels/kennfeld.rb', line 11 def initialize(name:, xdim:, ydim:, xvalue:, yvalue:, value:, xunit: nil, yunit: nil, unit: nil, function: nil, description: nil) value = value.size > ydim ? value.each_slice(xdim).to_a : value @name = name @xdim = xdim @ydim = ydim @xvalue = xvalue @yvalue = yvalue @value = value @xunit = xunit @yunit = yunit @unit = unit @function = function @description = description init_error "Dimension mismatch: xvalue=#{xvalue.size} xdim=#{xdim}" if xvalue.size != xdim init_error "Dimension mismatch: yvalue=#{yvalue.size} ydim=#{ydim}" if yvalue.size != ydim init_error "Dimension mismatch: value.x=#{value.size} ydim=#{ydim}" if value.size != ydim init_error "Dimension mismatch: value.y=XXX xdim=#{xdim}" if value.any? { |r| r.size != xdim } end |
Instance Attribute Details
#unit ⇒ Object (readonly)
Returns the value of attribute unit.
7 8 9 |
# File 'lib/ecu/labels/kennfeld.rb', line 7 def unit @unit end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
7 8 9 |
# File 'lib/ecu/labels/kennfeld.rb', line 7 def value @value end |
#xdim ⇒ Object (readonly)
Returns the value of attribute xdim.
8 9 10 |
# File 'lib/ecu/labels/kennfeld.rb', line 8 def xdim @xdim end |
#xunit ⇒ Object (readonly)
Returns the value of attribute xunit.
8 9 10 |
# File 'lib/ecu/labels/kennfeld.rb', line 8 def xunit @xunit end |
#xvalue ⇒ Object (readonly)
Returns the value of attribute xvalue.
8 9 10 |
# File 'lib/ecu/labels/kennfeld.rb', line 8 def xvalue @xvalue end |
#ydim ⇒ Object (readonly)
Returns the value of attribute ydim.
9 10 11 |
# File 'lib/ecu/labels/kennfeld.rb', line 9 def ydim @ydim end |
#yunit ⇒ Object (readonly)
Returns the value of attribute yunit.
9 10 11 |
# File 'lib/ecu/labels/kennfeld.rb', line 9 def yunit @yunit end |
#yvalue ⇒ Object (readonly)
Returns the value of attribute yvalue.
9 10 11 |
# File 'lib/ecu/labels/kennfeld.rb', line 9 def yvalue @yvalue end |
Class Method Details
.dcm_header ⇒ Object
3 4 5 |
# File 'lib/ecu/interfaces/dcm/kennfeld.rb', line 3 def self.dcm_header %r{^KENNFELD\s+(?<name>[A-Za-z0-9\._]+)\s+(?<xdim>\d+)\s+(?<ydim>\d+)} end |
Instance Method Details
#bytesize ⇒ Object
67 68 69 |
# File 'lib/ecu/labels/kennfeld.rb', line 67 def bytesize (xdim + 1) * (ydim + 1) * BYTESIZE[:number] end |
#equality_properties ⇒ Object
102 103 104 |
# File 'lib/ecu/labels/kennfeld.rb', line 102 def equality_properties [:name, :xvalue, :yvalue, :value] end |
#properties ⇒ Object
98 99 100 |
# File 'lib/ecu/labels/kennfeld.rb', line 98 def properties [:name, :xdim, :ydim, :xvalue, :yvalue, :value, :xunit, :yunit, :unit, :function, :description] end |
#reinterpx(new_xvalue) ⇒ Object
55 56 57 58 59 |
# File 'lib/ecu/labels/kennfeld.rb', line 55 def reinterpx(new_xvalue) self.with \ xvalue: new_xvalue, value: yvalue.map { |y| new_xvalue.map { |x| value_at(x, y) } } end |
#reinterpy(new_yvalue) ⇒ Object
61 62 63 64 65 |
# File 'lib/ecu/labels/kennfeld.rb', line 61 def reinterpy(new_yvalue) self.with \ yvalue: new_yvalue, value: new_yvalue.map { |y| xvalue.map { |x| value_at(x, y) } } end |
#round_to(n) ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/ecu/labels/kennfeld.rb', line 45 def round_to(n) hsh = Hash.new hsh[:xvalue] = xvalue.map { |x| x.round(n) } if xvalue.all? { |x| x.is_a?(Numeric) } hsh[:yvalue] = yvalue.map { |x| x.round(n) } if yvalue.all? { |x| x.is_a?(Numeric) } if value.all? { |row| row.all? { |x| x.is_a?(Numeric) }} hsh[:value] = value.map { |row| row.map { |x| x.round(n) }} end self.with hsh end |
#to_dcm ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ecu/interfaces/dcm/kennfeld.rb', line 7 def to_dcm "#{type.upcase} #{name} #{xdim} #{ydim}\n".tap do |str| str << " LANGNAME #{description.enquote}\n" if description str << " FUNKTION #{function}\n" if function str << " EINHEIT_X #{xunit.enquote}\n" if xunit str << " EINHEIT_Y #{yunit.enquote}\n" if yunit str << " EINHEIT_W #{unit.enquote}\n" if unit str << case xvalue.first when Numeric then " ST/X #{xvalue.join(" ")}\n" when String then " ST_TX/X #{xvalue.map(&:enquote).join(" ")}\n" end yvalue.each_with_index do |entry, idx| str << case entry when Numeric then " ST/Y #{entry}\n" when String then " ST_TX/Y #{entry.enquote}\n" end str << case value[idx].first when Numeric then " WERT #{value[idx].join(" ")}\n" when String then " TEXT #{value[idx].map(&:enquote).join(" ")}\n" end end str << "END\n" end end |
#to_mfile ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'lib/ecu/interfaces/mfile/kennfeld.rb', line 3 def to_mfile "#{name} = [\n".tap do |str| value.each do |row| str << row.join(" ").indent << "\n" end str << "];\n" end end |
#to_s(detail: false) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/ecu/labels/kennfeld.rb', line 71 def to_s(detail: false) if detail == :value "#{name}:\n#{to_s(detail: :justvalue)}" elsif detail == :justvalue ValuePrinter.call(self) elsif detail == :onelinefull "#{name} #{to_s(detail: :oneline)}" elsif detail == :oneline "(#{xdim}x#{ydim}) " + "X: #{valuestats(xvalue)}, " + "Y: #{valuestats(yvalue)}, " + "Z: #{valuestats(value, show_avg: true)}" else "#{name}: #{@xdim}x#{@ydim} #{type}".tap do |str| if detail str << "\n" str << " x-Unit: \"#{xunit}\"\n" str << " y-Unit: \"#{yunit}\"\n" str << " z-Unit: \"#{unit}\"\n" str << " Value:\n" str << ValuePrinter.call(self).indent(4) str << "\n" end end end end |
#value_at(x, y) ⇒ Object
41 42 43 |
# File 'lib/ecu/labels/kennfeld.rb', line 41 def value_at(x, y) Interpolator.interp2(xvalue, yvalue, value, x, y) end |