use of org.knime.core.data.DoubleValue in project knime-core by knime.
the class LinePlotter method calculateCoordinates.
/**
* Determines the overall minimum and maximum value of all selected columns.
*
* @param array
* the data to visualize
*/
private void calculateCoordinates(final DataArray array) {
Set<DataCell> rowKeys = new LinkedHashSet<DataCell>(array.size());
double minY = Double.POSITIVE_INFINITY;
double maxY = Double.NEGATIVE_INFINITY;
for (DataRow row : array) {
rowKeys.add(new StringCell(row.getKey().getString()));
for (String column : m_columnNames) {
int colIdx = array.getDataTableSpec().findColumnIndex(column);
if (colIdx == -1) {
initColumnNames(array);
calculateCoordinates(array);
break;
}
DataCell cell = row.getCell(colIdx);
if (cell.isMissing()) {
continue;
}
double value = ((DoubleValue) cell).getDoubleValue();
minY = Math.min(minY, value);
maxY = Math.max(maxY, value);
}
}
createNominalXCoordinate(rowKeys);
setPreserve(false);
createYCoordinate(minY, maxY);
// setPreserve(true);
}
use of org.knime.core.data.DoubleValue in project knime-core by knime.
the class LinearInterpolationStatisticTB method consumeRow.
/**
* {@inheritDoc}
*/
@Override
protected void consumeRow(final DataRow dataRow) {
DataCell cell = dataRow.getCell(getColumnIndex());
if (cell.isMissing()) {
incMissing();
} else {
for (int i = 0; i < getNumMissing(); i++) {
DataCell res;
if (getPrevious().isMissing()) {
res = cell;
} else {
if (m_isDateColumn) {
DateAndTimeValue val = (DateAndTimeValue) cell;
DateAndTimeValue prevVal = (DateAndTimeValue) getPrevious();
boolean hasDate = val.hasDate() | prevVal.hasDate();
boolean hasTime = val.hasTime() | prevVal.hasTime();
boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
long prev = prevVal.getUTCTimeInMillis();
long next = val.getUTCTimeInMillis();
long lin = Math.round(prev + 1.0 * (i + 1) / (1.0 * (getNumMissing() + 1)) * (next - prev));
res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
} else {
DoubleValue val = (DoubleValue) cell;
double prev = ((DoubleValue) getPrevious()).getDoubleValue();
double next = val.getDoubleValue();
double lin = prev + 1.0 * (i + 1) / (1.0 * (getNumMissing() + 1)) * (next - prev);
if (getPrevious() instanceof IntValue) {
// get an int, create an int
res = new IntCell((int) Math.round(lin));
} else if (getPrevious() instanceof LongValue) {
// get an long, create an long
res = new LongCell(Math.round(lin));
} else {
res = new DoubleCell(lin);
}
}
}
addMapping(res);
}
resetMissing(cell);
}
}
use of org.knime.core.data.DoubleValue in project knime-core by knime.
the class AverageInterpolationStatisticTB method consumeRow.
/**
* {@inheritDoc}
*/
@Override
protected void consumeRow(final DataRow dataRow) {
DataCell cell = dataRow.getCell(getColumnIndex());
if (cell.isMissing()) {
incMissing();
} else {
for (int i = 0; i < getNumMissing(); i++) {
DataCell res;
if (getPrevious().isMissing()) {
res = cell;
} else {
if (m_isDateColumn) {
DateAndTimeValue val = (DateAndTimeValue) cell;
DateAndTimeValue prevVal = (DateAndTimeValue) getPrevious();
boolean hasDate = val.hasDate() | prevVal.hasDate();
boolean hasTime = val.hasTime() | prevVal.hasTime();
boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
long prev = prevVal.getUTCTimeInMillis();
long next = val.getUTCTimeInMillis();
long lin = Math.round((prev + next) / 2);
res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
} else {
DoubleValue val = (DoubleValue) cell;
double prev = ((DoubleValue) getPrevious()).getDoubleValue();
double next = val.getDoubleValue();
double lin = (prev + next) / 2;
if (getPrevious() instanceof IntValue) {
// get an int, create an int
res = new IntCell((int) Math.round(lin));
} else if (getPrevious() instanceof LongValue) {
// get an long, create an long
res = new LongCell(Math.round(lin));
} else {
res = new DoubleCell(lin);
}
}
}
addMapping(res);
}
resetMissing(cell);
}
}
use of org.knime.core.data.DoubleValue in project knime-core by knime.
the class LinearInterpolationStatisticMB method consumeRow.
/**
* {@inheritDoc}
*/
@Override
protected void consumeRow(final DataRow dataRow) {
DataCell cell = dataRow.getCell(m_colIdx);
if (cell.isMissing()) {
m_numMissing++;
} else {
for (int i = 0; i < m_numMissing; i++) {
DataCell res;
if (m_previous.isMissing()) {
res = cell;
} else {
if (m_isDateColumn) {
DateAndTimeValue val = (DateAndTimeValue) cell;
DateAndTimeValue prevVal = (DateAndTimeValue) m_previous;
boolean hasDate = val.hasDate() | prevVal.hasDate();
boolean hasTime = val.hasTime() | prevVal.hasTime();
boolean hasMilis = val.hasMillis() | prevVal.hasMillis();
long prev = prevVal.getUTCTimeInMillis();
long next = val.getUTCTimeInMillis();
long lin = Math.round(prev + 1.0 * (i + 1) / (1.0 * (m_numMissing + 1)) * (next - prev));
res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
} else {
DoubleValue val = (DoubleValue) cell;
double prev = ((DoubleValue) m_previous).getDoubleValue();
double next = val.getDoubleValue();
double lin = prev + 1.0 * (i + 1) / (1.0 * (m_numMissing + 1)) * (next - prev);
if (m_previous instanceof IntValue) {
// get an int, create an int
res = new IntCell((int) Math.round(lin));
} else if (m_previous instanceof LongValue) {
// get an long, create an long
res = new LongCell(Math.round(lin));
} else {
res = new DoubleCell(lin);
}
}
}
m_values.add(res);
}
m_numMissing = 0;
m_previous = cell;
}
}
use of org.knime.core.data.DoubleValue in project knime-core by knime.
the class RoundDoubleCellFactory method getCells.
/**
* {@inheritDoc}
*/
@Override
public DataCell[] getCells(final DataRow row) {
DataCell[] newCells = new DataCell[m_colIndexToRound.length];
int noCols = row.getNumCells();
int nextIndexToRound = 0;
int currIndexToRound = -1;
// walk through all columns and round if specified
for (int i = 0; i < noCols; i++) {
// are available).
if (nextIndexToRound < m_colIndexToRound.length) {
currIndexToRound = m_colIndexToRound[nextIndexToRound];
}
// if value needs to be rounded
if (i == currIndexToRound) {
final DataCell outCell;
if (row.getCell(i).isMissing()) {
outCell = DataType.getMissingCell();
} else {
double value = ((DoubleValue) row.getCell(i)).getDoubleValue();
// check for infinity or nan
if (Double.isInfinite(value) || Double.isNaN(value)) {
switch(m_outputType) {
case Double:
// this isn't nice as we shouldn't have NaN and Inf in the input ...
// but that's a problem somewhere else
outCell = new DoubleCell(value);
break;
default:
outCell = new StringCell(new Double(value).toString());
}
} else {
// do not use constructor, see AP-7016
BigDecimal bd = BigDecimal.valueOf(value).stripTrailingZeros();
switch(m_numberMode) {
case DECIMAL_PLACES:
bd = bd.setScale(m_precision, m_roundingMode);
break;
case SIGNIFICANT_FIGURES:
bd = bd.round(new MathContext(m_precision, m_roundingMode));
break;
default:
throw new IllegalStateException();
}
outCell = m_outputType.createCell(bd);
}
}
// increment index of included column indices
newCells[nextIndexToRound++] = outCell;
}
}
return newCells;
}
Aggregations