Class: Ecu::Kennfeld

Inherits:
Label
  • Object
show all
Defined in:
lib/ecu/labels/kennfeld.rb,
lib/ecu/interfaces/dcm/kennfeld.rb,
lib/ecu/interfaces/mfile/kennfeld.rb

Direct Known Subclasses

Festkennfeld, Gruppenkennfeld

Constant Summary

Constants inherited from Label

Label::BYTESIZE

Instance Attribute Summary collapse

Attributes inherited from Label

#description, #function, #name

Instance Method Summary collapse

Methods inherited from Label

#<=>, #==, #===, #hash, #init_error, #inspect_instance_vars, #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

#unitObject (readonly)

Returns the value of attribute unit.



7
8
9
# File 'lib/ecu/labels/kennfeld.rb', line 7

def unit
  @unit
end

#valueObject (readonly)

Returns the value of attribute value.



7
8
9
# File 'lib/ecu/labels/kennfeld.rb', line 7

def value
  @value
end

#xdimObject (readonly)

Returns the value of attribute xdim.



8
9
10
# File 'lib/ecu/labels/kennfeld.rb', line 8

def xdim
  @xdim
end

#xunitObject (readonly)

Returns the value of attribute xunit.



8
9
10
# File 'lib/ecu/labels/kennfeld.rb', line 8

def xunit
  @xunit
end

#xvalueObject (readonly)

Returns the value of attribute xvalue.



8
9
10
# File 'lib/ecu/labels/kennfeld.rb', line 8

def xvalue
  @xvalue
end

#ydimObject (readonly)

Returns the value of attribute ydim.



9
10
11
# File 'lib/ecu/labels/kennfeld.rb', line 9

def ydim
  @ydim
end

#yunitObject (readonly)

Returns the value of attribute yunit.



9
10
11
# File 'lib/ecu/labels/kennfeld.rb', line 9

def yunit
  @yunit
end

#yvalueObject (readonly)

Returns the value of attribute yvalue.



9
10
11
# File 'lib/ecu/labels/kennfeld.rb', line 9

def yvalue
  @yvalue
end

Instance Method Details

#bytesizeObject



69
70
71
# File 'lib/ecu/labels/kennfeld.rb', line 69

def bytesize
  (xdim + 1) * (ydim + 1) * BYTESIZE[:number]
end

#equality_propertiesObject



104
105
106
# File 'lib/ecu/labels/kennfeld.rb', line 104

def equality_properties
  [:name, :xvalue, :yvalue, :value]
end

#propertiesObject



100
101
102
# File 'lib/ecu/labels/kennfeld.rb', line 100

def properties
  [:name, :xdim, :ydim, :xvalue, :yvalue, :value, :xunit, :yunit, :unit, :function, :description]
end

#reinterpx(new_xvalue) ⇒ Object



55
56
57
58
59
60
# File 'lib/ecu/labels/kennfeld.rb', line 55

def reinterpx(new_xvalue)
  self.with \
    xvalue: new_xvalue,
    xdim: new_xvalue.length,
    value: yvalue.map { |y| new_xvalue.map { |x| value_at(x, y) } }
end

#reinterpy(new_yvalue) ⇒ Object



62
63
64
65
66
67
# File 'lib/ecu/labels/kennfeld.rb', line 62

def reinterpy(new_yvalue)
  self.with \
    yvalue: new_yvalue,
    ydim: new_yvalue.length,
    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(indented = false) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ecu/interfaces/dcm/kennfeld.rb', line 3

def to_dcm(indented=false)
  fmtstr = indented ? "%-25s%s %s %s\n" : "%s %s %d %d\n"

  sprintf(fmtstr, type.upcase, name, xdim, ydim).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_mfileObject



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



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/ecu/labels/kennfeld.rb', line 73

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