示例#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);
      }
    }
  }
示例#2
0
  //
  // / Interval logging
  //
  private void initializeIntervalLogging() {
    synchronized (intervalLoggingLock) {
      if (vo.getLoggingType() != DataPointVO.LoggingTypes.INTERVAL) return;

      // Are we using a custom timer?
      if (this.timer == null)
        intervalLoggingTask =
            new TimeoutTask(
                new FixedRateTrigger(
                    0,
                    Common.getMillis(
                        vo.getIntervalLoggingPeriodType(), vo.getIntervalLoggingPeriod())),
                this);
      else
        intervalLoggingTask =
            new TimeoutTask(
                new FixedRateTrigger(
                    0,
                    Common.getMillis(
                        vo.getIntervalLoggingPeriodType(), vo.getIntervalLoggingPeriod())),
                this,
                this.timer);

      intervalValue = pointValue;
      if (vo.getIntervalLoggingType() == DataPointVO.IntervalLoggingTypes.AVERAGE) {
        intervalStartTime = System.currentTimeMillis();
        averagingValues = new ArrayList<IValueTime>();
      }
    }
  }
示例#3
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);
    }
  }
示例#4
0
  private void updatePoints() {
    // Get the points
    List<DataPointVO> dps =
        query(
            "select dp.id, dp.xid, dp.dataSourceId, dp.data, ds.name, " //
                + "ds.xid, ds.dataSourceType " //
                + "from dataPoints dp join dataSources ds on ds.id = dp.dataSourceId ",
            new DataPointRowMapper());

    // Resave
    for (DataPointVO dp : dps)
      ejt.update(
          "update dataPoints set xid=?, name=?, deviceName=?, enabled=?, loggingType=?, " //
              + "intervalLoggingPeriodType=?, intervalLoggingPeriod=?, intervalLoggingType=?, " //
              + "tolerance=?, purgeType=?, purgePeriod=?, defaultCacheSize=?, discardExtremeValues=?, " //
              + "engineeringUnits=?, data=? where id=?", //
          new Object[] {
            dp.getXid(),
            dp.getName(),
            dp.getDeviceName(),
            boolToChar(dp.isEnabled()),
            dp.getLoggingType(),
            dp.getIntervalLoggingPeriodType(),
            dp.getIntervalLoggingPeriod(),
            dp.getIntervalLoggingType(),
            dp.getTolerance(),
            dp.getPurgeType(),
            dp.getPurgePeriod(),
            dp.getDefaultCacheSize(),
            boolToChar(dp.isDiscardExtremeValues()),
            dp.getEngineeringUnits(),
            SerializationHelper.writeObject(dp),
            dp.getId()
          }, //
          new int[] {
            Types.VARCHAR,
            Types.VARCHAR,
            Types.VARCHAR,
            Types.CHAR,
            Types.INTEGER,
            Types.INTEGER,
            Types.INTEGER,
            Types.INTEGER,
            Types.DOUBLE,
            Types.INTEGER,
            Types.INTEGER,
            Types.INTEGER,
            Types.CHAR,
            Types.INTEGER,
            Types.BLOB,
            Types.INTEGER
          });
  }