@Override public Void run() throws Exception { lock.writeLock().lock(); try { if (configuration != null) { for (SampledValue value : values) { recorder.getProxy().appendValue(idEncoded, value.getValue().getDoubleValue(), value.getTimestamp(), (byte) value.getQuality().getQuality(), configuration); } } } catch (IOException e) { logger.error("", e); } catch (IllegalConversionException e) { logger.error("", e); } finally { lock.writeLock().unlock(); } return null; }
@Override public Void run() throws Exception { lock.writeLock().lock(); try { if (configuration != null) { for (SampledValue value : values) { recorder.getProxy().appendValue(id, value.getValue().getDoubleValue(), value.getTimestamp(), (byte) value.getQuality().getQuality(), configuration); } } } catch (IOException e) { logger.error("", e); } catch (IllegalConversionException e) { logger.error("", e); } finally { lock.writeLock().unlock(); } return null; }
@Override public Void run() throws Exception { lock.writeLock().lock(); try { if (configuration != null) { recorder.getProxy().appendValue(id, value.getValue().getDoubleValue(), value.getTimestamp(), (byte) value.getQuality().getQuality(), configuration); } } catch (IOException e) { logger.error("", e); } catch (IllegalConversionException e) { logger.error("", e); } catch (NullPointerException e) { logger.error("NPE in SlotsdbStorage - recorder: {}, proxy: {}, id: {}, config: {}, value: {}", recorder, (recorder!=null? recorder.getProxy(): null), id, configuration, value,e); } finally { lock.writeLock().unlock(); } return null; }
@Override public List<SampledValue> performReduction(List<SampledValue> subIntervalValues, long timestamp) { List<SampledValue> toReturn = new ArrayList<SampledValue>(); if (subIntervalValues.isEmpty()) { toReturn.add(new SampledValue(DoubleValues.of(0.f), timestamp, Quality.BAD)); } else { double minValue = Double.MAX_VALUE; for (SampledValue value : subIntervalValues) { if (value.getValue().getDoubleValue() < minValue) { minValue = value.getValue().getDoubleValue(); } } toReturn.add(new SampledValue(new SampledValue(DoubleValues.of(minValue), timestamp, Quality.GOOD))); } return toReturn; }
@Override public List<SampledValue> performReduction(List<SampledValue> subIntervalValues, long timestamp) { List<SampledValue> toReturn = new ArrayList<SampledValue>(); if (subIntervalValues.isEmpty()) { toReturn.add(new SampledValue(DoubleValues.of(0.f), timestamp, Quality.BAD)); } else { double minValue = Double.MAX_VALUE; for (SampledValue value : subIntervalValues) { if (value.getValue().getDoubleValue() < minValue) { minValue = value.getValue().getDoubleValue(); } } toReturn.add(new SampledValue(new SampledValue(DoubleValues.of(minValue), timestamp, Quality.GOOD))); } return toReturn; }
@Override public List<SampledValue> performReduction(List<SampledValue> subIntervalValues, long timestamp) { List<SampledValue> toReturn = new ArrayList<SampledValue>(); if (subIntervalValues.isEmpty()) { toReturn.add(new SampledValue(DoubleValues.of(0.f), timestamp, Quality.BAD)); } else { double maxValue = Double.NEGATIVE_INFINITY; for (SampledValue value : subIntervalValues) { if (value.getValue().getDoubleValue() > maxValue) { maxValue = value.getValue().getDoubleValue(); } } toReturn.add(new SampledValue(new SampledValue(DoubleValues.of(maxValue), timestamp, Quality.GOOD))); } return toReturn; }
@Override public List<SampledValue> performReduction(List<SampledValue> subIntervalValues, long timestamp) { List<SampledValue> toReturn = new ArrayList<SampledValue>(); if (subIntervalValues.isEmpty()) { toReturn.add(new SampledValue(DoubleValues.of(0.f), timestamp, Quality.BAD)); } else { double maxValue = Double.NEGATIVE_INFINITY; for (SampledValue value : subIntervalValues) { if (value.getValue().getDoubleValue() > maxValue) { maxValue = value.getValue().getDoubleValue(); } } toReturn.add(new SampledValue(new SampledValue(DoubleValues.of(maxValue), timestamp, Quality.GOOD))); } return toReturn; }
@Override public List<SampledValue> performReduction(List<SampledValue> subIntervalValues, long timestamp) { List<SampledValue> toReturn = new ArrayList<SampledValue>(); if (subIntervalValues.isEmpty()) { toReturn.add(new SampledValue(DoubleValues.of(0.f), timestamp, Quality.BAD)); } else { double sum = 0; for (SampledValue value : subIntervalValues) { sum += value.getValue().getDoubleValue(); } double average = sum / subIntervalValues.size(); toReturn.add(new SampledValue(new SampledValue(DoubleValues.of(average), timestamp, Quality.GOOD))); } return toReturn; }
@Override public Void run() throws Exception { lock.writeLock().lock(); try { if (configuration != null) { recorder.getProxy().appendValue(idEncoded, value.getValue().getDoubleValue(), value.getTimestamp(), (byte) value.getQuality().getQuality(), configuration); } } catch (IOException e) { logger.error("", e); } catch (IllegalConversionException e) { logger.error("", e); } catch (NullPointerException e) { logger.error("NPE in SlotsdbStorage - recorder: {}, proxy: {}, id: {}, config: {}, value: {}", recorder, (recorder!=null? recorder.getProxy(): null), id, configuration, value,e); } finally { lock.writeLock().unlock(); } return null; }
@Override public List<SampledValue> performReduction(List<SampledValue> subIntervalValues, long timestamp) { List<SampledValue> toReturn = new ArrayList<SampledValue>(); if (subIntervalValues.isEmpty()) { toReturn.add(new SampledValue(DoubleValues.of(0.f), timestamp, Quality.BAD)); } else { double sum = 0; for (SampledValue value : subIntervalValues) { sum += value.getValue().getDoubleValue(); } double average = sum / subIntervalValues.size(); toReturn.add(new SampledValue(new SampledValue(DoubleValues.of(average), timestamp, Quality.GOOD))); } return toReturn; }
@Override public List<SampledValue> performReduction(List<SampledValue> subIntervalValues, long timestamp) { List<SampledValue> toReturn = new ArrayList<SampledValue>(); if (subIntervalValues.isEmpty()) { toReturn.add(new SampledValue(DoubleValues.of(0.f), timestamp, Quality.BAD)); // for minimum toReturn.add(new SampledValue(DoubleValues.of(0.f), timestamp, Quality.BAD)); // for maximum } else { double minValue = Double.MAX_VALUE; double maxValue = Double.NEGATIVE_INFINITY; for (SampledValue value : subIntervalValues) { if (value.getValue().getDoubleValue() < minValue) { minValue = value.getValue().getDoubleValue(); } if (value.getValue().getDoubleValue() > maxValue) { maxValue = value.getValue().getDoubleValue(); } } toReturn.add(new SampledValue(new SampledValue(DoubleValues.of(minValue), timestamp, Quality.GOOD))); toReturn.add(new SampledValue(new SampledValue(DoubleValues.of(maxValue), timestamp, Quality.GOOD))); } return toReturn; }
@Override public List<SampledValue> performReduction(List<SampledValue> subIntervalValues, long timestamp) { List<SampledValue> toReturn = new ArrayList<SampledValue>(); if (subIntervalValues.isEmpty()) { toReturn.add(new SampledValue(DoubleValues.of(0.f), timestamp, Quality.BAD)); // for minimum toReturn.add(new SampledValue(DoubleValues.of(0.f), timestamp, Quality.BAD)); // for maximum } else { double minValue = Double.MAX_VALUE; double maxValue = Double.NEGATIVE_INFINITY; for (SampledValue value : subIntervalValues) { if (value.getValue().getDoubleValue() < minValue) { minValue = value.getValue().getDoubleValue(); } if (value.getValue().getDoubleValue() > maxValue) { maxValue = value.getValue().getDoubleValue(); } } toReturn.add(new SampledValue(new SampledValue(DoubleValues.of(minValue), timestamp, Quality.GOOD))); toReturn.add(new SampledValue(new SampledValue(DoubleValues.of(maxValue), timestamp, Quality.GOOD))); } return toReturn; }
continue; vals.put(sv.getTimestamp(), sv.getValue().getDoubleValue() + offset);
@Override public synchronized float integrate(long t0, long t1) { // react to zero range or t1<t0. if (t1 == t0) { return 0.f; } if (t1 < t0) { return -integrate(t1, t0); } final InterpolationFunction function = getInterpolationFunction(); double result = 0; SampledValue left = getValueSecure(t0); for (SampledValue right : getSubset(t0, t1)) { result += function.integrate(left, right, getValueType()).getDoubleValue(); left = right; } SampledValue right = getValueSecure(t1); result += function.integrate(left, right, getValueType()).getDoubleValue(); return (float) result; }
logger.debug(Double.toString(value.getDoubleValue()));
/** * @param iterator * @param mode * @return * integral, with time measured in ms */ public static double integrate2(Iterator<SampledValue> iterator, InterpolationMode mode) { Objects.requireNonNull(mode); final MultiTimeSeriesIterator multiI = MultiTimeSeriesIteratorBuilder.newBuilder(Collections.singletonList(iterator)) .setGlobalInterpolationMode(mode) .doIntegrate(true) .build(); double sum = 0; while (multiI.hasNext()) { final SampledValue svdp = multiI.next().getElement(0); if (svdp.getQuality() == Quality.GOOD) sum = svdp.getValue().getDoubleValue(); } return sum; }
/** * * @param iterator * @param mode * @param lowerBoundary * @param upperBoundary * @return * integral, with time measured in ms */ public static double integrate2(Iterator<SampledValue> iterator, InterpolationMode mode, SampledValue lowerBoundary, SampledValue upperBoundary) { final MultiTimeSeriesIteratorBuilder builder = MultiTimeSeriesIteratorBuilder.newBuilder(Collections.singletonList(iterator)) .setGlobalInterpolationMode(null) .doIntegrate(true); if (lowerBoundary != null) builder.setLowerBoundaryValues(Collections.singletonMap(0, lowerBoundary)); if (upperBoundary != null) builder.setUpperBoundaryValues(Collections.singletonMap(0, upperBoundary)); final MultiTimeSeriesIterator multiI = builder.build(); double sum = 0; while (multiI.hasNext()) { final SampledValue svdp = multiI.next().getElement(0); if (svdp.getQuality() == Quality.GOOD) sum += svdp.getValue().getDoubleValue(); } return sum; }