Class: Ecu::Kennlinie

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

Direct Known Subclasses

Festkennlinie, Gruppenkennlinie

Constant Summary

Constants inherited from Label

Label::BYTESIZE

Instance Attribute Summary collapse

Attributes inherited from Label

#description, #function, #name

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Label

#<=>, #==, #===, from_dcm, from_lab, #hash, #init_error, #match, #to_h, #to_lab, #type, #valuestats, #with

Constructor Details

#initialize(name:, xdim:, xvalue:, value:, xunit: nil, unit: nil, function: nil, description: nil) ⇒ Kennlinie

Returns a new instance of Kennlinie.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ecu/labels/kennlinie.rb', line 10

def initialize(name:,
               xdim:,
               xvalue:,
               value:,
               xunit: nil,
               unit: nil,
               function: nil,
               description: nil)
  @name        = name
  @xdim        = xdim
  @xvalue      = xvalue
  @value       = value
  @xunit       = xunit
  @unit        = unit
  @function    = function
  @description = description

  init_error "Dimensions for value don't match xdim" if value.size != xdim
  init_error "Dimensions for xvalue don't match xdim" if xvalue.size != xdim
end

Instance Attribute Details

#unitObject (readonly)

Returns the value of attribute unit.



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

def unit
  @unit
end

#valueObject (readonly)

Returns the value of attribute value.



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

def value
  @value
end

#xdimObject (readonly)

Returns the value of attribute xdim.



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

def xdim
  @xdim
end

#xunitObject (readonly)

Returns the value of attribute xunit.



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

def xunit
  @xunit
end

#xvalueObject (readonly)

Returns the value of attribute xvalue.



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

def xvalue
  @xvalue
end

Class Method Details

.dcm_headerObject



3
4
5
# File 'lib/ecu/interfaces/dcm/kennlinie.rb', line 3

def self.dcm_header
  %r{^KENNLINIE\s+(?<name>[A-Za-z0-9\._]+)\s+(?<xdim>\d+)}
end

Instance Method Details

#bytesizeObject



48
49
50
# File 'lib/ecu/labels/kennlinie.rb', line 48

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

#equality_propertiesObject



79
80
81
# File 'lib/ecu/labels/kennlinie.rb', line 79

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

#propertiesObject



75
76
77
# File 'lib/ecu/labels/kennlinie.rb', line 75

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

#reinterp(new_xvalue) ⇒ Object



42
43
44
45
46
# File 'lib/ecu/labels/kennlinie.rb', line 42

def reinterp(new_xvalue)
  self.with \
    xvalue: new_xvalue,
    value: new_xvalue.map { |x| value_at(x) }
end

#round_to(n) ⇒ Object



35
36
37
38
39
40
# File 'lib/ecu/labels/kennlinie.rb', line 35

def round_to(n)
  hsh = Hash.new
  hsh[:xvalue] = xvalue.map { |x| x.round(n) } if xvalue.all? { |x| x.is_a?(Numeric) }
  hsh[:value]  = value.map  { |x| x.round(n) } if value.all?  { |x| x.is_a?(Numeric) }
  self.with hsh
end

#to_dcmObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ecu/interfaces/dcm/kennlinie.rb', line 7

def to_dcm
  "#{type.upcase} #{name} #{xdim}\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_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
    str << case value.first
          when Numeric then "  WERT #{value.join(" ")}\n"
          when String  then "  TEXT #{value.map(&:enquote).join(" ")}\n"
          end
    str << "END\n"
  end
end

#to_mfileObject



3
4
5
# File 'lib/ecu/interfaces/mfile/kennlinie.rb', line 3

def to_mfile
  "#{name} = [#{value.join("  ")}];\n"
end

#to_s(detail: false) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ecu/labels/kennlinie.rb', line 52

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}x1) X: #{valuestats(xvalue)}, Z: #{valuestats(value, show_avg: true)}"
  else
    "#{name}: #{@xdim}x1 #{type}".tap do |str|
      if detail
        str << "\n"
        str << "  x-Unit: \"#{xunit}\"\n"
        str << "  y-Unit: \"#{unit}\"\n"
        str << "  Value:\n"
        str << ValuePrinter.call(self).indent(4)
        str << "\n"
      end
    end
  end
end

#value_at(x) ⇒ Object



31
32
33
# File 'lib/ecu/labels/kennlinie.rb', line 31

def value_at(x)
  Interpolator.interp1(xvalue, value, x)
end