Search in sources :

Example 6 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)

Example 7 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)

Example 8 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() + ".sce", 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) ArrayList(java.util.ArrayList) List(java.util.List)

Example 9 with Percent

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

the class DatabasePerformanceTest 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 10 with Percent

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

the class InputsAndResultsTestEmptyMatrixValue method testEmptyMatrixValue.

// CHECKSTYLE:OFF NCSS
public void testEmptyMatrixValue() {
    // CHECKSTYLE:ON
    final boolean[][] putBooleanMatrix = new boolean[2][];
    for (int i = 0; i < putBooleanMatrix.length; i++) {
        putBooleanMatrix[i] = new boolean[0];
    }
    final List<List<Boolean>> putBooleanMatrixAsList = Booleans.asListMatrix(putBooleanMatrix);
    final byte[][] putByteMatrix = new byte[2][];
    for (int i = 0; i < putByteMatrix.length; i++) {
        putByteMatrix[i] = new byte[0];
    }
    final List<List<Byte>> putByteMatrixAsList = Bytes.asListMatrix(putByteMatrix);
    final char[][] putCharacterMatrix = new char[2][];
    for (int i = 0; i < putCharacterMatrix.length; i++) {
        putCharacterMatrix[i] = new char[0];
    }
    final List<List<Character>> putCharacterMatrixAsList = Characters.asListMatrix(putCharacterMatrix);
    final Decimal[][] putDecimalMatrix = new Decimal[2][];
    for (int i = 0; i < putDecimalMatrix.length; i++) {
        putDecimalMatrix[i] = new Decimal[0];
    }
    final List<List<Decimal>> putDecimalMatrixAsList = Decimal.asListMatrix(putDecimalMatrix);
    final double[][] putDoubleMatrix = new double[2][];
    for (int i = 0; i < putDoubleMatrix.length; i++) {
        putDoubleMatrix[i] = new double[0];
    }
    final List<List<Double>> putDoubleMatrixAsList = Doubles.asListMatrix(putDoubleMatrix);
    final float[][] putFloatMatrix = new float[2][];
    for (int i = 0; i < putFloatMatrix.length; i++) {
        putFloatMatrix[i] = new float[0];
    }
    final List<List<Float>> putFloatMatrixAsList = Floats.asListMatrix(putFloatMatrix);
    final int[][] putIntegerMatrix = new int[2][];
    for (int i = 0; i < putIntegerMatrix.length; i++) {
        putIntegerMatrix[i] = new int[0];
    }
    final List<List<Integer>> putIntegerMatrixAsList = Integers.asListMatrix(putIntegerMatrix);
    final long[][] putLongMatrix = new long[2][];
    for (int i = 0; i < putLongMatrix.length; i++) {
        putLongMatrix[i] = new long[0];
    }
    final List<List<Long>> putLongMatrixAsList = Longs.asListMatrix(putLongMatrix);
    final Percent[][] putPercentMatrix = new Percent[2][];
    for (int i = 0; i < putPercentMatrix.length; i++) {
        putPercentMatrix[i] = new Percent[0];
    }
    final List<List<Percent>> putPercentMatrixAsList = Percent.asListMatrix(putPercentMatrix);
    final short[][] putShortMatrix = new short[2][];
    for (int i = 0; i < putShortMatrix.length; i++) {
        putShortMatrix[i] = new short[0];
    }
    final List<List<Short>> putShortMatrixAsList = Shorts.asListMatrix(putShortMatrix);
    final String[][] putStringMatrix = new String[2][];
    for (int i = 0; i < putStringMatrix.length; i++) {
        putStringMatrix[i] = new String[0];
    }
    final List<List<String>> putStringMatrixAsList = Strings.asListMatrix(putStringMatrix);
    new AScriptTaskMatlab<Void>() {

        @Override
        public void populateInputs(final IScriptTaskInputs inputs) {
            inputs.putBooleanMatrix("putBooleanMatrix", putBooleanMatrix);
            inputs.putBooleanMatrixAsList("putBooleanMatrixAsList", putBooleanMatrixAsList);
            inputs.putByteMatrix("putByteMatrix", putByteMatrix);
            inputs.putByteMatrixAsList("putByteMatrixAsList", putByteMatrixAsList);
            inputs.putCharacterMatrix("putCharacterMatrix", putCharacterMatrix);
            inputs.putCharacterMatrixAsList("putCharacterMatrixAsList", putCharacterMatrixAsList);
            inputs.putDecimalMatrix("putDecimalMatrix", putDecimalMatrix);
            inputs.putDecimalMatrixAsList("putDecimalMatrixAsList", putDecimalMatrixAsList);
            inputs.putDoubleMatrix("putDoubleMatrix", putDoubleMatrix);
            inputs.putDoubleMatrixAsList("putDoubleMatrixAsList", putDoubleMatrixAsList);
            inputs.putFloatMatrix("putFloatMatrix", putFloatMatrix);
            inputs.putFloatMatrixAsList("putFloatMatrixAsList", putFloatMatrixAsList);
            inputs.putIntegerMatrix("putIntegerMatrix", putIntegerMatrix);
            inputs.putIntegerMatrixAsList("putIntegerMatrixAsList", putIntegerMatrixAsList);
            inputs.putLongMatrix("putLongMatrix", putLongMatrix);
            inputs.putLongMatrixAsList("putLongMatrixAsList", putLongMatrixAsList);
            inputs.putDecimalMatrix("putPercentMatrix", putPercentMatrix);
            inputs.putDecimalMatrixAsList("putPercentMatrixAsList", putPercentMatrixAsList);
            inputs.putShortMatrix("putShortMatrix", putShortMatrix);
            inputs.putShortMatrixAsList("putShortMatrixAsList", putShortMatrixAsList);
            inputs.putStringMatrix("putStringMatrix", putStringMatrix);
            inputs.putStringMatrixAsList("putStringMatrixAsList", putStringMatrixAsList);
        }

        @Override
        public void executeScript(final IScriptTaskEngine engine) {
            try {
                final String script = IOUtils.toString(new ClassPathResource(InputsAndResultsTestEmptyMatrixValue.class.getSimpleName() + ".m", InputsAndResultsTestNull.class).getInputStream(), Charset.defaultCharset());
                if (!engine.getResults().getBoolean("exist('OCTAVE_VERSION', 'builtin') > 0")) {
                    // workaround for matlab and isempty not counting empty cells there
                    final StringBuilder sb = new StringBuilder();
                    // we can actually create functions in scripts without separate files: http://de.mathworks.com/help/matlab/matlab_prog/anonymous-functions.html
                    sb.append("ismatlabempty = @(x) all(cellfun(@isempty, x));\n");
                    sb.append("\n");
                    sb.append(script.replace("isempty", "ismatlabempty"));
                    engine.eval(sb.toString());
                } else {
                    engine.eval(script);
                }
            } catch (final IOException e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public Void extractResults(final IScriptTaskResults results) {
            Assertions.checkEquals(putBooleanMatrix, results.getBooleanMatrix("getBooleanMatrix"));
            Assertions.checkEquals(putBooleanMatrixAsList, results.getBooleanMatrixAsList("getBooleanMatrixAsList"));
            Assertions.checkEquals(putByteMatrix, results.getByteMatrix("getByteMatrix"));
            Assertions.checkEquals(putByteMatrixAsList, results.getByteMatrixAsList("getByteMatrixAsList"));
            Assertions.checkEquals(putCharacterMatrix, results.getCharacterMatrix("getCharacterMatrix"));
            Assertions.checkEquals(putCharacterMatrixAsList, results.getCharacterMatrixAsList("getCharacterMatrixAsList"));
            Assertions.checkEquals(putDecimalMatrix, results.getDecimalMatrix("getDecimalMatrix"));
            Assertions.checkEquals(putDecimalMatrixAsList, results.getDecimalMatrixAsList("getDecimalMatrixAsList"));
            Assertions.checkEquals(putDoubleMatrix, results.getDoubleMatrix("getDoubleMatrix"));
            Assertions.checkEquals(putDoubleMatrixAsList, results.getDoubleMatrixAsList("getDoubleMatrixAsList"));
            Assertions.checkEquals(putFloatMatrix, results.getFloatMatrix("getFloatMatrix"));
            Assertions.checkEquals(putFloatMatrixAsList, results.getFloatMatrixAsList("getFloatMatrixAsList"));
            Assertions.checkEquals(putIntegerMatrix, results.getIntegerMatrix("getIntegerMatrix"));
            Assertions.checkEquals(putIntegerMatrixAsList, results.getIntegerMatrixAsList("getIntegerMatrixAsList"));
            Assertions.checkEquals(putLongMatrix, results.getLongMatrix("getLongMatrix"));
            Assertions.checkEquals(putLongMatrixAsList, results.getLongMatrixAsList("getLongMatrixAsList"));
            Assertions.checkEquals(putPercentMatrix, results.getDecimalMatrix("getPercentMatrix", Percent.ZERO_PERCENT));
            Assertions.checkEquals(putPercentMatrixAsList, results.getDecimalMatrixAsList("getPercentMatrixAsList", Percent.ZERO_PERCENT));
            Assertions.checkEquals(putShortMatrix, results.getShortMatrix("getShortMatrix"));
            Assertions.checkEquals(putShortMatrixAsList, results.getShortMatrixAsList("getShortMatrixAsList"));
            Assertions.checkEquals(putStringMatrix, results.getStringMatrix("getStringMatrix"));
            Assertions.checkEquals(putStringMatrixAsList, results.getStringMatrixAsList("getStringMatrixAsList"));
            return null;
        }
    }.run(runner);
}
Also used : IScriptTaskInputs(de.invesdwin.context.integration.script.IScriptTaskInputs) Decimal(de.invesdwin.util.math.decimal.Decimal) List(java.util.List) Percent(de.invesdwin.util.math.decimal.scaled.Percent) IOException(java.io.IOException) IScriptTaskEngine(de.invesdwin.context.integration.script.IScriptTaskEngine) ClassPathResource(org.springframework.core.io.ClassPathResource) IScriptTaskResults(de.invesdwin.context.integration.script.IScriptTaskResults)

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