Search in sources :

Example 11 with Percent

use of de.invesdwin.util.math.decimal.scaled.Percent in project invesdwin-context-matlab by subes.

the class InputsAndResultsTestPercent method testPercent.

public void testPercent() {
    // putPercent
    final Percent putPercent = new Percent(123.123D, PercentScale.RATE);
    // putPercentVector
    final Percent[] putPercentVector = new Percent[3];
    for (int i = 0; i < putPercentVector.length; i++) {
        putPercentVector[i] = new Percent(new Decimal((i + 1) + "." + (i + 1)), PercentScale.RATE);
    }
    // putPercentVectorAsList
    final List<Percent> putPercentVectorAsList = Arrays.asList(putPercentVector);
    // putPercentMatrix
    final Percent[][] putPercentMatrix = new Percent[4][];
    for (int row = 0; row < putPercentMatrix.length; row++) {
        final Percent[] vector = new Percent[3];
        for (int col = 0; col < vector.length; col++) {
            vector[col] = new Percent(new Decimal((row + 1) + "." + (col + 1)), PercentScale.RATE);
        }
        putPercentMatrix[row] = vector;
    }
    // putPercentMatrixAsList
    final List<List<Percent>> putPercentMatrixAsList = new ArrayList<List<Percent>>(putPercentMatrix.length);
    for (final Percent[] vector : putPercentMatrix) {
        putPercentMatrixAsList.add(Arrays.asList(vector));
    }
    new AScriptTaskMatlab<Void>() {

        @Override
        public void populateInputs(final IScriptTaskInputs inputs) {
            inputs.putDecimal("putPercent", putPercent);
            inputs.putDecimalVector("putPercentVector", putPercentVector);
            inputs.putDecimalVectorAsList("putPercentVectorAsList", putPercentVectorAsList);
            inputs.putDecimalMatrix("putPercentMatrix", putPercentMatrix);
            inputs.putDecimalMatrixAsList("putPercentMatrixAsList", putPercentMatrixAsList);
        }

        @Override
        public void executeScript(final IScriptTaskEngine engine) {
            engine.eval(new ClassPathResource(InputsAndResultsTestPercent.class.getSimpleName() + ".m", InputsAndResultsTestPercent.class));
        }

        @Override
        public Void extractResults(final IScriptTaskResults results) {
            // getPercent
            final Percent getPercent = results.getDecimal("getPercent", Percent.ZERO_PERCENT);
            Assertions.assertThat(putPercent).isEqualTo(getPercent);
            // getPercentVector
            final Percent[] getPercentVector = results.getDecimalVector("getPercentVector", Percent.ZERO_PERCENT);
            Assertions.assertThat(putPercentVector).isEqualTo(getPercentVector);
            // getPercentVectorAsList
            final List<Percent> getPercentVectorAsList = results.getDecimalVectorAsList("getPercentVectorAsList", Percent.ZERO_PERCENT);
            Assertions.assertThat(putPercentVectorAsList).isEqualTo(getPercentVectorAsList);
            // getPercentMatrix
            final Percent[][] getPercentMatrix = results.getDecimalMatrix("getPercentMatrix", Percent.ZERO_PERCENT);
            Assertions.assertThat(putPercentMatrix).isEqualTo(getPercentMatrix);
            // getPercentMatrixAsList
            final List<List<Percent>> getPercentMatrixAsList = results.getDecimalMatrixAsList("getPercentMatrixAsList", Percent.ZERO_PERCENT);
            Assertions.assertThat(putPercentMatrixAsList).isEqualTo(getPercentMatrixAsList);
            return null;
        }
    }.run(runner);
}
Also used : Percent(de.invesdwin.util.math.decimal.scaled.Percent) ArrayList(java.util.ArrayList) IScriptTaskEngine(de.invesdwin.context.integration.script.IScriptTaskEngine) ClassPathResource(org.springframework.core.io.ClassPathResource) IScriptTaskInputs(de.invesdwin.context.integration.script.IScriptTaskInputs) IScriptTaskResults(de.invesdwin.context.integration.script.IScriptTaskResults) Decimal(de.invesdwin.util.math.decimal.Decimal) List(java.util.List) ArrayList(java.util.ArrayList)

Example 12 with Percent

use of de.invesdwin.util.math.decimal.scaled.Percent in project invesdwin-context-persistence by subes.

the class ALazyDataUpdater method doUpdate.

protected final FDate doUpdate(final FDate estimatedTo) throws IncompleteUpdateFoundException {
    try {
        final ALoggingTimeSeriesUpdater<K, V> updater = new ALoggingTimeSeriesUpdater<K, V>(key, getTable(), log) {

            @Override
            protected FDate extractEndTime(final V element) {
                return ALazyDataUpdater.this.extractEndTime(element);
            }

            @Override
            protected ICloseableIterable<? extends V> getSource(final FDate updateFrom) {
                final ICloseableIterable<? extends V> downloadElements = ALazyDataUpdater.this.downloadElements(getKey(), updateFrom);
                return downloadElements;
            }

            @Override
            protected String keyToString(final K key) {
                return ALazyDataUpdater.this.keyToString(key);
            }

            @Override
            protected String getElementsName() {
                return ALazyDataUpdater.this.getElementsName();
            }

            @Override
            public Percent getProgress() {
                if (estimatedTo == null) {
                    return null;
                }
                final FDate from = getMinTime();
                if (from == null) {
                    return null;
                }
                final FDate curTime = getMaxTime();
                if (curTime == null) {
                    return null;
                }
                return new Percent(new Duration(from, curTime), new Duration(from, estimatedTo)).orLower(Percent.ONE_HUNDRED_PERCENT);
            }
        };
        final Callable<FDate> task = new Callable<FDate>() {

            @Override
            public FDate call() throws Exception {
                updater.update();
                return updater.getMaxTime();
            }
        };
        final String taskName = "Loading " + getElementsName() + " for " + keyToString(getKey());
        final Callable<Percent> progress = newProgressCallable(estimatedTo, updater);
        return TaskInfoCallable.of(taskName, task, progress).call();
    } catch (final IncompleteUpdateFoundException e) {
        throw e;
    } catch (final Throwable e) {
        throw Throwables.propagate(e);
    }
}
Also used : Percent(de.invesdwin.util.math.decimal.scaled.Percent) Duration(de.invesdwin.util.time.duration.Duration) FDate(de.invesdwin.util.time.date.FDate) Callable(java.util.concurrent.Callable) TaskInfoCallable(de.invesdwin.util.concurrent.taskinfo.provider.TaskInfoCallable) IncompleteUpdateFoundException(de.invesdwin.context.persistence.timeseriesdb.IncompleteUpdateFoundException)

Example 13 with Percent

use of de.invesdwin.util.math.decimal.scaled.Percent in project invesdwin-context-persistence by subes.

the class ALoggingTimeSeriesUpdater method logFlush.

private void logFlush() {
    Assertions.assertThat(lastFlushIndex).isNotNull();
    // if we are too fast, only print status once a second
    if (lastFlushTime == null || lastFlushTime.isGreaterThan(Duration.ONE_SECOND)) {
        final Duration flushDuration = updateStart.toDuration();
        final Percent progress = getProgress();
        if (progress != null) {
            log.info("Persisted %s. %s batch for [%s]. Reached [%s] at time [%s]. Processed [%s] during %s", lastFlushIndex, getElementsName(), keyToString(getKey()), progress.asScale(PercentScale.PERCENT), lastFlushMaxTime, new ProcessedEventsRateString(flushElementCount, flushDuration), flushDuration);
        } else {
            log.info("Persisted %s. %s batch for [%s]. Reached time [%s]. Processed [%s] during %s", lastFlushIndex, getElementsName(), keyToString(getKey()), lastFlushMaxTime, new ProcessedEventsRateString(flushElementCount, flushDuration), flushDuration);
        }
        lastFlushTime = new Instant();
    }
    lastFlushIndex = null;
    lastFlushMaxTime = null;
}
Also used : ProcessedEventsRateString(de.invesdwin.util.lang.ProcessedEventsRateString) Percent(de.invesdwin.util.math.decimal.scaled.Percent) Instant(de.invesdwin.util.time.Instant) Duration(de.invesdwin.util.time.duration.Duration)

Example 14 with Percent

use of de.invesdwin.util.math.decimal.scaled.Percent in project invesdwin-context-persistence by subes.

the class InfluxDBPerformanceTest method printProgress.

private void printProgress(final String action, final Instant start, final long count, final int maxCount) {
    final Duration duration = start.toDuration();
    log.info("%s: %s/%s (%s) %s during %s", action, count, maxCount, new Percent(count, maxCount).toString(PercentScale.PERCENT), new ProcessedEventsRateString(count, duration), duration);
}
Also used : ProcessedEventsRateString(de.invesdwin.util.lang.ProcessedEventsRateString) Percent(de.invesdwin.util.math.decimal.scaled.Percent) Duration(de.invesdwin.util.time.duration.Duration)

Example 15 with Percent

use of de.invesdwin.util.math.decimal.scaled.Percent in project invesdwin-context-persistence by subes.

the class ADatabasePerformanceTest method printProgress.

protected void printProgress(final String action, final Instant start, final long count, final int maxCount) {
    final Duration duration = start.toDuration();
    log.info("%s: %s/%s (%s) %s during %s", action, count, maxCount, new Percent(count, maxCount).toString(PercentScale.PERCENT), new ProcessedEventsRateString(count, duration), duration);
}
Also used : ProcessedEventsRateString(de.invesdwin.util.lang.ProcessedEventsRateString) Percent(de.invesdwin.util.math.decimal.scaled.Percent) Duration(de.invesdwin.util.time.duration.Duration)

Aggregations

Percent (de.invesdwin.util.math.decimal.scaled.Percent)20 Duration (de.invesdwin.util.time.duration.Duration)14 ProcessedEventsRateString (de.invesdwin.util.lang.ProcessedEventsRateString)13 FDate (de.invesdwin.util.time.date.FDate)4 ArrayList (java.util.ArrayList)4 IScriptTaskEngine (de.invesdwin.context.integration.script.IScriptTaskEngine)3 IScriptTaskInputs (de.invesdwin.context.integration.script.IScriptTaskInputs)3 IScriptTaskResults (de.invesdwin.context.integration.script.IScriptTaskResults)3 Decimal (de.invesdwin.util.math.decimal.Decimal)3 Instant (de.invesdwin.util.time.Instant)3 List (java.util.List)3 ClassPathResource (org.springframework.core.io.ClassPathResource)3 IncompleteUpdateFoundException (de.invesdwin.context.persistence.timeseriesdb.IncompleteUpdateFoundException)2 ATimeSeriesUpdater (de.invesdwin.context.persistence.timeseriesdb.updater.ATimeSeriesUpdater)2 ATest (de.invesdwin.context.test.ATest)2 ICloseableIterable (de.invesdwin.util.collections.iterable.ICloseableIterable)2 TaskInfoCallable (de.invesdwin.util.concurrent.taskinfo.provider.TaskInfoCallable)2 TypeDelegateSerde (de.invesdwin.util.marshallers.serde.TypeDelegateSerde)2 Callable (java.util.concurrent.Callable)2 Test (org.junit.jupiter.api.Test)2