use of org.knime.core.data.DataCell in project knime-core by knime.
the class TwoSampleTTestNodeModel method getTestStatisticsTable.
/**
* Get table with test statistics
* @param result test statistic
* @param exec the execution context
* @return a combined table of the test statistic
*/
private BufferedDataTable getTestStatisticsTable(final TwoSampleTTestStatistics[] result, final ExecutionContext exec) {
BufferedDataContainer cont = exec.createDataContainer(TwoSampleTTestStatistics.getTableSpec());
int r = 0;
for (int i = 0; i < result.length; i++) {
for (List<DataCell> cells : result[i].getTTestCells()) {
cont.addRowToTable(new DefaultRow(RowKey.createRowKey(r), cells));
r++;
}
}
cont.close();
return cont.getTable();
}
use of org.knime.core.data.DataCell in project knime-core by knime.
the class TwoSampleTTestNodeView method renderDescriptiveStatistics.
/**
* Create HTML for the descriptive statistics.
*/
private String renderDescriptiveStatistics() {
StringBuilder buffer = NodeViewUtil.createHtmlHeader();
buffer.append("<body>\n");
buffer.append("<h3>Group Statistics</h3>");
NodeViewUtil.renderDataTable(getNodeModel().getDescritiveStatistics(), TwoSampleTTestStatistics.TEST_COLUMN, Arrays.asList(new String[] { TwoSampleTTestStatistics.TEST_COLUMN, TwoSampleTTestStatistics.IGNORED_COUNT_GROUP_COL }), new HashMap<String, String>(), buffer);
BufferedDataTable descStats = getNodeModel().getDescritiveStatistics();
if (descStats.getRowCount() > 0) {
CloseableRowIterator iter = descStats.iteratorFailProve();
int ignoredIndex = descStats.getSpec().findColumnIndex(TwoSampleTTestStatistics.IGNORED_COUNT_GROUP_COL);
DataCell ignoredCell = iter.next().getCell(ignoredIndex);
if (!ignoredCell.isMissing()) {
int ignoredCount = ((IntValue) ignoredCell).getIntValue();
if (ignoredCount > 0) {
buffer.append("<p>");
buffer.append(ignoredCount);
buffer.append(ignoredCount > 1 ? " rows have been ignored. Their " : " row has been ignored. Its ");
buffer.append("value in the grouping column is neither \"");
buffer.append(getNodeModel().getSettings().getGroupOne());
buffer.append("\" nor \"");
buffer.append(getNodeModel().getSettings().getGroupTwo());
buffer.append("\".");
buffer.append("</p>");
}
}
iter.close();
}
buffer.append("</body>\n");
buffer.append("</html>\n");
return buffer.toString();
}
use of org.knime.core.data.DataCell in project knime-core by knime.
the class DateTimeToStringNodeModel method createStreamableOperator.
/**
* {@inheritDoc}
*/
@Override
public StreamableOperator createStreamableOperator(final PartitionInfo partitionInfo, final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
return new StreamableOperator() {
@Override
public void runFinal(final PortInput[] inputs, final PortOutput[] outputs, final ExecutionContext exec) throws Exception {
final RowInput in = (RowInput) inputs[0];
final RowOutput out = (RowOutput) outputs[0];
final DataTableSpec inSpec = in.getDataTableSpec();
final String[] includeList = m_colSelect.applyTo(inSpec).getIncludes();
final int[] includeIndeces = Arrays.stream(m_colSelect.applyTo(inSpec).getIncludes()).mapToInt(s -> inSpec.findColumnIndex(s)).toArray();
final boolean isReplace = m_isReplaceOrAppend.getStringValue().equals(OPTION_REPLACE);
DataRow row;
while ((row = in.poll()) != null) {
exec.checkCanceled();
DataCell[] datacells = new DataCell[includeIndeces.length];
for (int i = 0; i < includeIndeces.length; i++) {
if (isReplace) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includeList[i], StringCell.TYPE);
final TimeToStringCellFactory cellFac = new TimeToStringCellFactory(dataColumnSpecCreator.createSpec(), includeIndeces[i]);
datacells[i] = cellFac.getCell(row);
} else {
final DataColumnSpec dataColSpec = new UniqueNameGenerator(inSpec).newColumn(includeList[i] + m_suffix.getStringValue(), StringCell.TYPE);
final TimeToStringCellFactory cellFac = new TimeToStringCellFactory(dataColSpec, includeIndeces[i]);
datacells[i] = cellFac.getCell(row);
}
}
if (isReplace) {
out.push(new ReplacedColumnsDataRow(row, datacells, includeIndeces));
} else {
out.push(new AppendedColumnRow(row, datacells));
}
}
in.close();
out.close();
}
};
}
use of org.knime.core.data.DataCell in project knime-core by knime.
the class DateTimeBasedRowFilterNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
final BufferedDataTable dataTable = inData[0];
final BufferedDataContainer container = exec.createDataContainer(dataTable.getDataTableSpec());
// read input
final int colIdx = dataTable.getDataTableSpec().findColumnIndex(m_colSelect.getStringValue());
final ZonedDateTime executionStartTime = m_startAlwaysNow.getBooleanValue() ? ZonedDateTime.now() : null;
final ZonedDateTime executionEndTime = m_endAlwaysNow.getBooleanValue() ? ZonedDateTime.now() : null;
// filter rows
for (final DataRow row : dataTable) {
exec.checkCanceled();
final DataCell cell = row.getCell(colIdx);
if (!cell.isMissing()) {
if (cell instanceof LocalDateValue && filterRowLocalDate(((LocalDateValue) cell).getLocalDate(), executionStartTime, executionEndTime)) {
container.addRowToTable(row);
} else if (cell instanceof LocalTimeValue && filterRowLocalTime(((LocalTimeValue) cell).getLocalTime(), executionStartTime, executionEndTime)) {
container.addRowToTable(row);
} else if (cell instanceof LocalDateTimeValue && filterRowLocalDateTime(((LocalDateTimeValue) cell).getLocalDateTime(), executionStartTime, executionEndTime)) {
container.addRowToTable(row);
} else if (cell instanceof ZonedDateTimeValue && filterRowZonedDateTime(((ZonedDateTimeValue) cell).getZonedDateTime(), executionStartTime, executionEndTime)) {
container.addRowToTable(row);
}
}
}
container.close();
return new BufferedDataTable[] { container.getTable() };
}
use of org.knime.core.data.DataCell in project knime-core by knime.
the class DateShiftConfigure method getTimeBasedValueCellFactory.
/**
* @param spec the previous data table spec
* @param col1Idx the column index of the numerical column to add
* @param g the time field to modify (as defined by calendar constants)
* @param conf the configuration object
* @param time the configured time as Calendar
* @return the cell factory
*/
public static SingleCellFactory getTimeBasedValueCellFactory(final DataTableSpec spec, final int col1Idx, final int g, final DateShiftConfigure conf, final Calendar time) {
return new SingleCellFactory(createOutputColumnSpec(spec, conf.getNewColumnName().getStringValue())) {
/**
* Value for the new column is based on the values of two column of the row (first and second date column),
* the selected granularity, and the fraction digits for rounding.
*
* @param row the current row
* @return the difference between the two date values with the given granularity and rounding
*/
@Override
public DataCell getCell(final DataRow row) {
DataCell cell1 = row.getCell(col1Idx);
if ((cell1.isMissing())) {
return DataType.getMissingCell();
}
Calendar c = (Calendar) time.clone();
c.add(g, ((IntValue) cell1).getIntValue());
return new DateAndTimeCell(c.getTimeInMillis(), conf.getHasDate().getBooleanValue(), conf.getHasTime().getBooleanValue(), conf.getHasMiliSeconds().getBooleanValue());
}
};
}
Aggregations