Example #1
0
  private void intervalSave(PointValueTime pvt) {
    synchronized (intervalLoggingLock) {
      if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.MAXIMUM) {
        if (intervalValue == null) intervalValue = pvt;
        else if (pvt != null) {
          if (intervalValue.getDoubleValue() < pvt.getDoubleValue()) intervalValue = pvt;
        }
      } else if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.MINIMUM) {
        if (intervalValue == null) intervalValue = pvt;
        else if (pvt != null) {
          if (intervalValue.getDoubleValue() > pvt.getDoubleValue()) intervalValue = pvt;
        }
      } else if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.AVERAGE) {
        // Using the averaging values, ensure we keep the most recent values and pop off the old
        // ones
        if (vo.isOverrideIntervalLoggingSamples()) {
          while (averagingValues.size() >= vo.getIntervalLoggingSampleWindowSize()) {
            averagingValues.remove(0); // Size -1 for the next item we are going to add
          }
        }

        averagingValues.add(pvt);
      }
    }
  }
Example #2
0
  @Override
  public void scheduleTimeout(long fireTime) {
    synchronized (intervalLoggingLock) {
      DataValue value;
      if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.INSTANT)
        value = PointValueTime.getValue(pointValue);
      else if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.MAXIMUM
          || vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.MINIMUM) {
        value = PointValueTime.getValue(intervalValue);
        intervalValue = pointValue;
      } else if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.AVERAGE) {

        // We won't allow logging values until we have a full average window
        // If we don't have enough averaging values then we will bail and wait for more
        if (vo.isOverrideIntervalLoggingSamples()
            && (averagingValues.size() != vo.getIntervalLoggingSampleWindowSize())) return;

        IValueTime endValue = intervalValue;
        if (!averagingValues.isEmpty()) endValue = averagingValues.get(averagingValues.size() - 1);
        AnalogStatistics stats =
            new AnalogStatistics(
                intervalStartTime, fireTime, intervalValue, averagingValues, endValue);
        if (stats.getAverage() == null) value = null;
        else value = new NumericValue(stats.getAverage());
        // Compute the center point of our average data, starting by finding where our period
        // started
        long sampleWindowStartTime;
        if (vo.isOverrideIntervalLoggingSamples())
          sampleWindowStartTime = averagingValues.get(0).getTime();
        else sampleWindowStartTime = intervalStartTime;

        intervalStartTime = fireTime;
        fireTime =
            sampleWindowStartTime
                + (fireTime - sampleWindowStartTime)
                    / 2L; // Fix to simulate center tapped filter (un-shift the average)
        intervalValue = pointValue;

        if (!vo.isOverrideIntervalLoggingSamples()) averagingValues.clear();
      } else
        throw new ShouldNeverHappenException(
            "Unknown interval logging type: " + vo.getIntervalLoggingType());

      if (value != null) valueCache.logPointValueAsync(new PointValueTime(value, fireTime), null);
    }
  }