use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class RuleEngineVariable2PortsNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected PortObjectSpec[] configure(final PortObjectSpec[] inSpecs) throws InvalidSettingsException {
String warning = RuleEngine2PortsNodeModel.autoGuessRuleColumnName(inSpecs, m_settings);
if (warning != null) {
setWarningMessage(warning);
}
DataTableSpec ruleTableSpec = (DataTableSpec) inSpecs[RuleEngine2PortsNodeModel.RULE_PORT];
// unknown table structure
if (ruleTableSpec == null) {
return null;
}
CheckUtils.checkSettingNotNull(ruleTableSpec.getColumnSpec(m_settings.getRuleColumn()), "No rule column in the rules table with name: " + m_settings.getRuleColumn());
return new PortObjectSpec[] { FlowVariablePortObjectSpec.INSTANCE };
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class MovingAverageNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inSpec = inSpecs[0];
// define column name on which to apply MA
if ((m_columnNames.getIncludeList().size() == 0) && (m_columnNames.getExcludeList().size() == 0)) {
// auto-configure
List<String> autoConfiguredInclList = new ArrayList<String>();
for (DataColumnSpec colSpec : inSpec) {
if (colSpec.getType().isCompatible(DoubleValue.class)) {
autoConfiguredInclList.add(colSpec.getName());
}
}
m_columnNames.setIncludeList(autoConfiguredInclList);
setWarningMessage("Auto-configure: selected all double columns!");
}
if (m_columnNames.getIncludeList().isEmpty()) {
setWarningMessage("No double columns selected: input will be same as output!");
}
// check for the existence of the selected columns
for (String colName : m_columnNames.getIncludeList()) {
if (!inSpecs[0].containsName(colName)) {
throw new InvalidSettingsException("Column \"" + colName + "\" not found in input data!");
}
}
// define moving average window length
int winLength = m_winLength.getIntValue();
if (winLength == -1) {
throw new InvalidSettingsException("Window length is not selected.");
}
// define weight function
String kindOfMAModelString;
try {
kindOfMAModelString = m_kindOfMAModel.getStringValue();
} catch (IllegalArgumentException e) {
throw new InvalidSettingsException(e.getMessage(), e);
}
if (kindOfMAModelString == null) {
throw new InvalidSettingsException("No weight function selected.");
} else {
// create one MA-compute engine per column (overkill, I know
// but much easier to reference later on in our DataCellFactory)
MA_METHODS method = MA_METHODS.getPolicy4Label(kindOfMAModelString);
if (MA_METHODS.getCenteredMethods().contains(method) && winLength % 2 == 0) {
throw new InvalidSettingsException("For centered methods, the window size has to be uneven");
}
m_mas = new MovingAverage[inSpecs[0].getNumColumns()];
for (int i = 0; i < inSpecs[0].getNumColumns(); i++) {
m_mas[i] = method.getMAObject(winLength);
}
}
ColumnRearranger c = createColRearranger(inSpecs[0]);
return new DataTableSpec[] { c.createSpec() };
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class DateFieldExtractorNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inSpec = inSpecs[0];
// contains timestamp?
if (!inSpec.containsCompatibleType(DateAndTimeValue.class)) {
throw new InvalidSettingsException("No timestamp found in input table!");
}
// currently selected column still there?
String selectedColName = m_selectedColumn.getStringValue();
if (selectedColName != null && !selectedColName.isEmpty()) {
if (!inSpec.containsName(selectedColName)) {
throw new InvalidSettingsException("Column " + selectedColName + " not found in input spec!");
}
} else {
// no value set: auto-configure -> choose first timeseries
for (DataColumnSpec colSpec : inSpec) {
if (colSpec.getType().isCompatible(DateAndTimeValue.class)) {
String colName = colSpec.getName();
m_selectedColumn.setStringValue(colName);
setWarningMessage("Auto-configure: selected " + colName);
break;
}
}
}
// create outputspec
ColumnRearranger colRearranger = createColumnRearranger(inSpec).getColumnRearranger();
return new DataTableSpec[] { colRearranger.createSpec() };
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class ExtractTimeWindowNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
boolean useTime = m_fromDate.useTime() || m_toDate.useTime();
BufferedDataTable in = inData[0];
DataTableSpec outs = in.getDataTableSpec();
final int colIndex = outs.findColumnIndex(m_columnName.getStringValue());
BufferedDataContainer t = exec.createDataContainer(outs);
final long totalRowCount = in.size();
int currentIteration = 0;
try {
for (DataRow r : in) {
// increment before printing to achieve a 1-based index
currentIteration++;
exec.checkCanceled();
exec.setProgress(currentIteration / (double) totalRowCount, "Processing row " + currentIteration);
DataCell cell = r.getCell(colIndex);
if (cell.isMissing()) {
// do not include missing values -> skip it
continue;
}
Calendar time = ((DateAndTimeValue) cell).getUTCCalendarClone();
// which is implemented as a real < or >
if (!useTime) {
DateAndTimeCell.resetTimeFields(time);
}
if (time.compareTo(m_fromDate.getCalendar()) >= 0 && time.compareTo(m_toDate.getCalendar()) <= 0) {
t.addRowToTable(r);
}
}
} finally {
t.close();
}
return new BufferedDataTable[] { t.getTable() };
}
use of org.knime.core.data.DataTableSpec in project knime-core by knime.
the class MaskTimeNodeModel method configure.
/**
* {@inheritDoc}
*/
@Override
protected DataTableSpec[] configure(final DataTableSpec[] inSpecs) throws InvalidSettingsException {
DataTableSpec inSpec = inSpecs[0];
// check if there is a date and tme column in niput spec
if (!inSpec.containsCompatibleType(DateAndTimeValue.class)) {
throw new InvalidSettingsException("Input table must contain at least one column " + "containing time!");
}
// do we have a selected column?
String selectedCol = m_selectedColumn.getStringValue();
if (selectedCol != null && !selectedCol.isEmpty()) {
// if yes -> exists in input spec?
if (!inSpec.containsName(selectedCol)) {
throw new InvalidSettingsException("Selected column " + selectedCol + "not found in input table!");
}
} else {
// if no -> auto-configure: select first date and time column
for (DataColumnSpec colSpec : inSpec) {
if (colSpec.getType().isCompatible(DateAndTimeValue.class)) {
String colName = colSpec.getName();
m_selectedColumn.setStringValue(colName);
setWarningMessage("Auto-configure: selected column " + colName + "!");
}
}
}
return new DataTableSpec[] { createOutputSpec(inSpec) };
}
Aggregations