Class NumberDatumSamplePropertyConfig<V>

java.lang.Object
net.solarnetwork.domain.datum.DatumSamplePropertyConfig<V>
net.solarnetwork.domain.datum.NumberDatumSamplePropertyConfig<V>

public class NumberDatumSamplePropertyConfig<V> extends DatumSamplePropertyConfig<V>
Extension of DatumSamplePropertyConfig specifically designed to help with number property values.

This class contains two pairs of linear equation property pairs that can be used to transform raw data values x into appropriate datum values y. ly just one pair needs to be used; sometimes it is more convenient to use one pair over the other.

First, the unitSlope M and unitIntercept B properties are calculated using the equation y = M * (x + B). Second, the slope m and intercept b properties are used with an equation like y = (m * x) + b. If both are specified, the overall equation is thus y = (m * (M * (x + B))) + b.

Since:
1.54
Version:
2.0
Author:
matt
  • Field Details

    • DEFAULT_PROPERTY_TYPE

      public static final DatumSamplesType DEFAULT_PROPERTY_TYPE
      The default value for the propertyType property.
    • DEFAULT_SLOPE

      public static final BigDecimal DEFAULT_SLOPE
      The default value for the slope and unitSlope properties.
    • DEFAULT_INTERCEPT

      public static final BigDecimal DEFAULT_INTERCEPT
      The default value for the intercept and unitIntercept properties.
    • DEFAULT_DECIMAL_SCALE

      public static final int DEFAULT_DECIMAL_SCALE
      The default value for the decimalScale property.
      See Also:
  • Constructor Details

    • NumberDatumSamplePropertyConfig

      public NumberDatumSamplePropertyConfig()
      Default constructor.
    • NumberDatumSamplePropertyConfig

      public NumberDatumSamplePropertyConfig(String propertyKey, DatumSamplesType propertyType, V config)
      Constructor.
      Parameters:
      propertyKey - the datum property name to assign
      propertyType - the datum property type
      config - the configuration value
  • Method Details

    • numberTransformSettings

      public static List<SettingSpecifier> numberTransformSettings(String prefix)
      Get the number transform settings for all transforms.
      Parameters:
      prefix - the optional prefix
      Returns:
      the settings for unit intercept, unit slope, slope, and intercept
      Since:
      2.0
    • applyTransformations

      public Number applyTransformations(Number value)
      Apply the configured slope, intercept, unit slope, unit intercept, and decimal scale to a number value.

      This executes the equation y = (m * (M * (x + B))) + b and applys getDecimalScale() to the result. The variables are:

      Parameters:
      value - the number to apply the transform properties to
      Returns:
      the result, or null if value is null
    • getSlope

      public BigDecimal getSlope()
      Get the slope multiplier.

      This value represents m in the equation y = mx + b. For example, a power meter might report power as killowatts, in which case slope can be configured as .001 to convert the value to watts.

      Returns:
      the slope multiplier, never null; defaults to DEFAULT_SLOPE
    • setSlope

      public void setSlope(BigDecimal slope)
      Set the slope multiplier.
      Parameters:
      slope - the slope multiplier to set; if null DEFAULT_SLOPE will be used instead
    • getIntercept

      public BigDecimal getIntercept()
      Get the y-intercept offset.

      This value represents b in the equation y = mx + b. For example, a sensor might report values in the range -10..10 which should be interpreted as values in the range 0..20, in which case intercept can be configured as 10 to convert the value appropriately.

      Returns:
      the y-intercept, never null; defaults to DEFAULT_INTERCEPT
    • setIntercept

      public void setIntercept(BigDecimal intercept)
      Set the y-intercept offset.
      Parameters:
      intercept - the intercept offset to set; if null DEFAULT_INTERCEPT will be used instead
    • getUnitSlope

      public BigDecimal getUnitSlope()
      Get the unit slope multiplier.

      This value represents m in the equation y = m(x + b). For example, a power meter might report power as killowatts, in which case slope can be configured as .001 to convert the value to watts.

      Returns:
      the unit slope multiplier, never null; defaults to DEFAULT_SLOPE
    • setUnitSlope

      public void setUnitSlope(BigDecimal unitSlope)
      Set the unit slope multiplier.
      Parameters:
      unitSlope - the unit slope multiplier to set; if null DEFAULT_SLOPE will be used instead
    • getUnitIntercept

      public BigDecimal getUnitIntercept()
      Get the unit y-intercept offset.

      This value represents b in the equation y = m(x + b). For example, a sensor might report values in the range -10..10 which should be interpreted as values in the range 0..20, in which case intercept can be configured as 10 to convert the value appropriately.

      Returns:
      the unit y-intercept, never null; defaults to DEFAULT_INTERCEPT
    • setUnitIntercept

      public void setUnitIntercept(BigDecimal unitIntercept)
      Set the unit y-intercept offset.
      Parameters:
      unitIntercept - the unit intercept offset to set; if null DEFAULT_INTERCEPT will be used instead
    • getDecimalScale

      public int getDecimalScale()
      Get the decimal scale to round decimal numbers to.
      Returns:
      the decimal scale; defaults to DEFAULT_DECIMAL_SCALE
    • setDecimalScale

      public void setDecimalScale(int decimalScale)
      Set the decimal scale to round decimal numbers to.

      This is a maximum scale value that decimal values should be rounded to. A scale of 0 would round all decimals to integer values.

      Parameters:
      decimalScale - the maximum scale to set, or -1 to disable rounding completely