コード例 #1
0
 /**
  * @return Numeric meta data information for the channel or <code>null</code>
  * @throws Exception on error
  */
 private Display determineDisplay() throws Exception {
   // Try numeric meta data
   final PreparedStatement statement =
       reader
           .getRDB()
           .getConnection()
           .prepareStatement(reader.getSQL().numeric_meta_sel_by_channel);
   try {
     statement.setInt(1, channel_id);
     final ResultSet result = statement.executeQuery();
     if (result.next()) {
       final NumberFormat format = NumberFormats.format(result.getInt(7)); // prec
       return ValueFactory.newDisplay(
           result.getDouble(1), // lowerDisplayLimit
           result.getDouble(5), // lowerAlarmLimit
           result.getDouble(3), // lowerWarningLimit
           result.getString(8), // units
           format, // numberFormat
           result.getDouble(4), // upperWarningLimit
           result.getDouble(6), // upperAlarmLimit
           result.getDouble(2), // upperDisplayLimit
           result.getDouble(1), // lowerCtrlLimit
           result.getDouble(2)); // upperCtrlLimit
     }
   } finally {
     statement.close();
   }
   // No numeric display meta data
   return null;
 }
コード例 #2
0
 /**
  * @param reader RDBArchiveReader
  * @param channel_id ID of channel
  * @throws Exception on error
  */
 AbstractRDBValueIterator(final RDBArchiveReader reader, final int channel_id) throws Exception {
   this.reader = reader;
   this.channel_id = channel_id;
   try {
     this.display = determineDisplay();
     this.labels = determineLabels();
   } catch (final Exception ex) {
     // Set iterator to empty
     close();
     if (!RDBArchiveReader.isCancellation(ex)) throw ex;
     // Else: Not a real error, return empty iterator
   }
   if (labels == null && display == null)
     display =
         ValueFactory.newDisplay(
             0.0, 0.0, 0.0, "", NumberFormats.format(0), 0.0, 0.0, 10.0, 0.0, 10.0);
 }
コード例 #3
0
  @Override
  public Object calculate(List<Object> args) {
    VNumberArray numberArray = (VNumberArray) args.get(0);
    if (numberArray == null) {
      return null;
    }

    // If no change, return previous
    if (previousValue == numberArray) {
      return previousResult;
    }

    Statistics stats = StatisticsUtil.statisticsOf(numberArray.getData());
    int nBins = 100;
    Range aggregatedRange = Ranges.aggregateRange(stats, previousXRange);
    Range xRange;
    if (Ranges.overlap(stats, aggregatedRange) >= 0.75) {
      xRange = aggregatedRange;
    } else {
      xRange = stats;
    }

    IteratorNumber newValues = numberArray.getData().iterator();
    double minValueRange = xRange.getMinimum().doubleValue();
    double maxValueRange = xRange.getMaximum().doubleValue();

    ListNumber xBoundaries =
        ListNumbers.linearListFromRange(minValueRange, maxValueRange, nBins + 1);
    String unit = numberArray.getUnits();
    int[] binData = new int[nBins];
    double maxCount = 0;
    while (newValues.hasNext()) {
      double value = newValues.nextDouble();
      // Check value in range
      if (Ranges.contains(xRange, value)) {

        int bin = (int) Math.floor(Ranges.normalize(xRange, value) * nBins);
        if (bin == nBins) {
          bin--;
        }

        binData[bin]++;
        if (binData[bin] > maxCount) {
          maxCount = binData[bin];
        }
      }
    }

    if (previousMaxCount > maxCount && previousMaxCount < maxCount * 2.0) {
      maxCount = previousMaxCount;
    }

    previousMaxCount = maxCount;
    previousXRange = xRange;
    previousValue = numberArray;
    previousResult =
        newVNumberArray(
            new ArrayInt(binData),
            new ArrayInt(nBins),
            Arrays.asList(newDisplay(xBoundaries, unit)),
            numberArray,
            numberArray,
            newDisplay(
                0.0,
                0.0,
                0.0,
                "count",
                NumberFormats.format(0),
                maxCount,
                maxCount,
                maxCount,
                Double.NaN,
                Double.NaN));

    return previousResult;
  }
コード例 #4
0
 static {
   format.setNumberFormat(NumberFormats.toStringFormat());
 }