use of org.knime.core.data.def.IntCell 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.def.IntCell in project knime-core by knime.
the class RankCellFactory method getCell.
/**
* {@inheritDoc}
*/
@Override
public DataCell getCell(final DataRow row) {
// create group identification
DataCellTuple rowVals = new DataCellTuple(row, m_groupColIndices);
// get RankAssigner for corresponding group
RankAssigner rankAssigner = m_groupHashTable.get(rowVals);
DataCell rankCell = null;
// check if RankAssigner is registered for group
if (rankAssigner == null) {
// create new RankAssigner and register it for this new group
rankAssigner = createRankAssigner(m_rankMode, m_rankColIndices);
m_groupHashTable.put(rowVals, rankAssigner);
// create RankCell
if (m_rankAsLong) {
rankCell = new LongCell(rankAssigner.getRank(row));
} else {
rankCell = new IntCell((int) rankAssigner.getRank(row));
}
} else {
// create RankCell
if (m_rankAsLong) {
rankCell = new LongCell(rankAssigner.getRank(row));
} else {
rankCell = new IntCell((int) rankAssigner.getRank(row));
}
}
return rankCell;
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class DomainDialog method takeOverSettings.
/**
* @return an object with domain values set by the user. Or <code>null</code> if settings are invalid. Then, a error
* message box is displayed.
*/
private ColProperty takeOverSettings() {
ColProperty result = new ColProperty();
if (m_colProp.getColumnSpec().getType().isCompatible(StringValue.class)) {
DataColumnSpecCreator dcsc = new DataColumnSpecCreator(m_colProp.getColumnSpec().getName(), m_colProp.getColumnSpec().getType());
if (m_containsVals != null) {
result.setReadPossibleValuesFromFile(m_containsVals.isSelected());
}
if ((m_containsVals == null) || m_containsVals.isSelected()) {
// if it's null we have a string column
Set<DataCell> pVals = null;
// tranfser possible values
int valCount = m_valueList.getModel().getSize();
pVals = new LinkedHashSet<DataCell>();
for (int i = 0; i < valCount; i++) {
DataCell val = (DataCell) m_valueList.getModel().getElementAt(i);
pVals.add(val);
}
if (pVals.size() > 0) {
DataColumnDomainCreator domainCreator = new DataColumnDomainCreator(pVals);
dcsc.setDomain(domainCreator.createDomain());
}
}
result.setColumnSpec(dcsc.createSpec());
} else {
DataType type = m_colProp.getColumnSpec().getType();
DataColumnSpecCreator dcsc = new DataColumnSpecCreator(m_colProp.getColumnSpec().getName(), type);
DataColumnDomainCreator domainCreator = new DataColumnDomainCreator();
if (type.equals(IntCell.TYPE)) {
domainCreator.setLowerBound(new IntCell((int) m_lowerBoundField.getValue()));
domainCreator.setUpperBound(new IntCell((int) m_upperBoundField.getValue()));
} else if (type.equals(DoubleCell.TYPE)) {
domainCreator.setLowerBound(new DoubleCell((double) m_lowerBoundField.getValue()));
domainCreator.setUpperBound(new DoubleCell((double) m_upperBoundField.getValue()));
}
dcsc.setDomain(domainCreator.createDomain());
result.setColumnSpec(dcsc.createSpec());
}
return result;
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class DomainDialog method addIntPosValue.
/**
* Called when the user pressed the "Add" button to add an integer value to the list of possible values. Will add
* the number entered, or set the error text, if user input is invalid. It will adjust the range settings (if any)
* to include the new value.
*/
protected void addIntPosValue() {
// clear the error.
m_errorLabel.setText("");
String newVal = m_editField.getText();
if (newVal.length() < 1) {
return;
}
int newInt;
try {
newInt = Integer.parseInt(newVal);
} catch (NumberFormatException nfe) {
m_errorLabel.setText("Invalid integer! Not added!");
return;
}
IntCell newIntCell = new IntCell(newInt);
addDataCellPossValue(newIntCell);
m_editField.setText("");
}
use of org.knime.core.data.def.IntCell in project knime-core by knime.
the class NumericalAttributeModel method createDataRows.
/**
* {@inheritDoc}
*/
@Override
void createDataRows(final ExecutionMonitor exec, final BufferedDataContainer dc, final boolean ignoreMissing, final AtomicInteger rowId) throws CanceledExecutionException {
final List<String> sortedClassVal = AttributeModel.sortCollection(m_classValues.keySet());
if (sortedClassVal == null) {
return;
}
final StringCell attributeCell = new StringCell(getAttributeName());
for (final String classVal : sortedClassVal) {
final List<DataCell> cells = new LinkedList<>();
cells.add(attributeCell);
cells.add(DataType.getMissingCell());
cells.add(new StringCell(classVal));
final NumericalClassValue classValue = m_classValues.get(classVal);
cells.add(new IntCell(classValue.getNoOfNotMissingRows()));
if (!ignoreMissing) {
cells.add(new IntCell(classValue.getNoOfMissingValueRecs()));
}
cells.add(new DoubleCell(classValue.getMean()));
cells.add(new DoubleCell(classValue.getStdDeviation()));
dc.addRowToTable(new DefaultRow(RowKey.createRowKey(rowId.getAndIncrement()), cells.toArray(new DataCell[0])));
}
}
Aggregations