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);
}
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);
}
}
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;
}
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);
}
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);
}
Aggregations