TimeFractionDeltaEnricher extends AbstractTypeTransformingEnricher<T,Double> { @Override public void onEvent(SensorEvent<T> event) { onEvent(event, event.getTimestamp()); } TimeFractionDeltaEnricher(); @Deprecated  TimeFractionDeltaEnricher(Entity producer, Sensor<T> source, Sensor<Double> target, TimeUnit origUnits); @Deprecated  TimeFractionDeltaEnricher(Entity producer, Sensor<T> source, Sensor<Double> target, long nanosPerOrigUnit); @Override void init(); @Override void rebind(); @Override void onEvent(SensorEvent<T> event); void onEvent(SensorEvent<T> event, long eventTimestamp);  }
@Test public void testCalculatesFractions() { @SuppressWarnings("unchecked") TimeFractionDeltaEnricher<Integer> enricher = producer.enrichers().add(EnricherSpec.create(TimeFractionDeltaEnricher.class) .configure("producer", producer) .configure("source", intSensor) .configure("target", fractionSensor) .configure("durationPerOrigUnit", Duration.millis(1))); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 0, 1000000L)); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 0, 1001000L)); assertEquals(producer.getAttribute(fractionSensor), 0d); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 100, 1002000L)); assertEquals(producer.getAttribute(fractionSensor), 0.1d, PRECISION); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 300, 1003000L)); assertEquals(producer.getAttribute(fractionSensor), 0.2d, PRECISION); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 2300, 1004000L)); assertEquals(producer.getAttribute(fractionSensor), 2d, PRECISION); }
@Test public void testConvertsTimeUnits() { @SuppressWarnings("unchecked") TimeFractionDeltaEnricher<Integer> enricher = producer.enrichers().add(EnricherSpec.create(TimeFractionDeltaEnricher.class) .configure("producer", producer) .configure("source", intSensor) .configure("target", fractionSensor) .configure("durationPerOrigUnit", Duration.micros(1))); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 0, 1000000L)); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 1000000, 1001000L)); assertEquals(producer.getAttribute(fractionSensor), 1d); }
@Test public void testConverts100NanosTimeBlocks() { @SuppressWarnings("unchecked") TimeFractionDeltaEnricher<Integer> enricher = producer.enrichers().add(EnricherSpec.create(TimeFractionDeltaEnricher.class) .configure("producer", producer) .configure("source", intSensor) .configure("target", fractionSensor) .configure("durationPerOrigUnit", Duration.nanos(100))); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 0, 1000000L)); enricher.onEvent(new BasicSensorEvent<Integer>(intSensor, producer, 10000000, 1001000L)); assertEquals(producer.getAttribute(fractionSensor), 1d); }