use of org.knime.timeseries.node.extract.SingleCellFactoryCompound in project knime-core by knime.
the class DateFieldExtractorNodeModel method createColumnRearranger.
private SingleCellFactoryCompound createColumnRearranger(final DataTableSpec inSpec) {
final int colIdx = inSpec.findColumnIndex(m_selectedColumn.getStringValue());
ColumnRearranger rearranger = new ColumnRearranger(inSpec);
List<AbstractTimeExtractorCellFactory> cellFactories = new ArrayList<AbstractTimeExtractorCellFactory>();
// year
if (m_useYear.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_yearColName.getStringValue());
AbstractTimeExtractorCellFactory yearFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, false) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getYear();
}
};
rearranger.append(yearFactory);
cellFactories.add(yearFactory);
}
// quarter
if (m_useQuarter.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_quarterColName.getStringValue());
AbstractTimeExtractorCellFactory quarterFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, false) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
int month = value.getMonth();
// hence we add 1
return month / 3 + 1;
}
};
rearranger.append(quarterFactory);
cellFactories.add(quarterFactory);
}
// month
AbstractTimeExtractorCellFactory monthFactory = null;
if (m_useMonth.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_monthColName.getStringValue());
if (m_monthRepresentation.getStringValue().equals(AbstractFieldExtractorNodeDialog.AS_INT)) {
monthFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, false) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
// to java.util.Calendar#MONTH
return value.getMonth() + 1;
}
};
} else {
// extract the display name of the month
monthFactory = new AbstractTimeExtractorStringCellFactory(colName, colIdx, false) {
@Override
protected String extractTimeField(final DateAndTimeValue value) {
return value.getUTCCalendarClone().getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault());
}
};
}
rearranger.append(monthFactory);
cellFactories.add(monthFactory);
}
// day of month
if (m_useDay.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_dayColName.getStringValue());
AbstractTimeExtractorCellFactory dayFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, false) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getDayOfMonth();
}
};
rearranger.append(dayFactory);
cellFactories.add(dayFactory);
}
// day of week
AbstractTimeExtractorCellFactory dayOfWeekFactory = null;
if (m_useDayOfWeek.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_dayOfWeekColName.getStringValue());
if (m_dayOfWeekRepresentationModel.getStringValue().equals(AbstractFieldExtractorNodeDialog.AS_INT)) {
dayOfWeekFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, false) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getUTCCalendarClone().get(Calendar.DAY_OF_WEEK);
}
};
} else {
dayOfWeekFactory = new AbstractTimeExtractorStringCellFactory(colName, colIdx, false) {
@Override
protected String extractTimeField(final DateAndTimeValue value) {
return value.getUTCCalendarClone().getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, Locale.getDefault());
}
};
// extract the display name of the day of week
}
rearranger.append(dayOfWeekFactory);
cellFactories.add(dayOfWeekFactory);
}
// day of year
if (m_useDayOfYear.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_dayOfYearColName.getStringValue());
AbstractTimeExtractorCellFactory dayofYearFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, false) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getUTCCalendarClone().get(Calendar.DAY_OF_YEAR);
}
};
rearranger.append(dayofYearFactory);
cellFactories.add(dayofYearFactory);
}
// week of year
if (m_useWeekOfYear.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_weekOfYearColName.getStringValue());
AbstractTimeExtractorCellFactory weekofYearFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, false) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getUTCCalendarClone().get(Calendar.WEEK_OF_YEAR);
}
};
rearranger.append(weekofYearFactory);
cellFactories.add(weekofYearFactory);
}
return new SingleCellFactoryCompound(rearranger, cellFactories);
}
use of org.knime.timeseries.node.extract.SingleCellFactoryCompound in project knime-core by knime.
the class TimeFieldExtractorNodeModel method createColumnRearranger.
private SingleCellFactoryCompound createColumnRearranger(final DataTableSpec inSpec) {
final int colIdx = inSpec.findColumnIndex(m_selectedColumn.getStringValue());
ColumnRearranger rearranger = new ColumnRearranger(inSpec);
List<AbstractTimeExtractorCellFactory> cellFactories = new ArrayList<AbstractTimeExtractorCellFactory>();
// ************************* TIME fields factories *******************/
// hour
AbstractTimeExtractorCellFactory hourFactory = null;
if (m_useHour.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_hourColName.getStringValue());
hourFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, true) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getHourOfDay();
}
};
rearranger.append(hourFactory);
cellFactories.add(hourFactory);
}
// minute
AbstractTimeExtractorCellFactory minuteFactory = null;
if (m_useMinute.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_minuteColName.getStringValue());
minuteFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, true) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getMinute();
}
};
rearranger.append(minuteFactory);
cellFactories.add(minuteFactory);
}
// second
AbstractTimeExtractorCellFactory secondFactory = null;
if (m_useSecond.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_secondColName.getStringValue());
secondFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, true) {
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getSecond();
}
};
rearranger.append(secondFactory);
cellFactories.add(secondFactory);
}
// millisecond
AbstractTimeExtractorCellFactory milliFactory = null;
if (m_useMillis.getBooleanValue()) {
String colName = DataTableSpec.getUniqueColumnName(inSpec, m_milliColName.getStringValue());
milliFactory = new AbstractTimeExtractorIntCellFactory(colName, colIdx, true) {
// here we also have to check if the value has millis
@Override
protected int extractTimeField(final DateAndTimeValue value) {
return value.getMillis();
}
@Override
public DataCell getCell(final DataRow row) {
DataCell cell = row.getCell(colIdx);
if (cell.isMissing()) {
return DataType.getMissingCell();
}
DateAndTimeValue value = (DateAndTimeValue) cell;
if (value.hasMillis()) {
producedValidValue();
return new IntCell(extractTimeField(value));
}
// no date set
increaseMissingValueCount();
return DataType.getMissingCell();
}
};
rearranger.append(milliFactory);
cellFactories.add(milliFactory);
}
return new SingleCellFactoryCompound(rearranger, cellFactories);
}
use of org.knime.timeseries.node.extract.SingleCellFactoryCompound in project knime-core by knime.
the class TimeFieldExtractorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
if (!checkSelection()) {
setWarningMessage(AbstractFieldExtractorNodeDialog.NOTHING_SELECTED_MESSAGE);
}
SingleCellFactoryCompound compound = createColumnRearranger(inData[0].getDataTableSpec());
ColumnRearranger rearranger = compound.getColumnRearranger();
BufferedDataTable out = exec.createColumnRearrangeTable(inData[0], rearranger, exec);
int nrMissingValues = 0;
for (AbstractTimeExtractorCellFactory cellFactory : compound.getUsedCellFactories()) {
nrMissingValues += cellFactory.getNumberMissingValues();
}
if (nrMissingValues > 0) {
setWarningMessage("Produced " + nrMissingValues + " missing values due to missing time" + " information in input date/time!");
}
return new BufferedDataTable[] { out };
}
use of org.knime.timeseries.node.extract.SingleCellFactoryCompound in project knime-core by knime.
the class DateFieldExtractorNodeModel method execute.
/**
* {@inheritDoc}
*/
@Override
protected BufferedDataTable[] execute(final BufferedDataTable[] inData, final ExecutionContext exec) throws Exception {
if (!checkSelection()) {
setWarningMessage(AbstractFieldExtractorNodeDialog.NOTHING_SELECTED_MESSAGE);
}
SingleCellFactoryCompound compound = createColumnRearranger(inData[0].getDataTableSpec());
ColumnRearranger rearranger = compound.getColumnRearranger();
BufferedDataTable out = exec.createColumnRearrangeTable(inData[0], rearranger, exec);
int nrMissingValues = 0;
for (AbstractTimeExtractorCellFactory cellFactory : compound.getUsedCellFactories()) {
nrMissingValues += cellFactory.getNumberMissingValues();
}
if (nrMissingValues > 0) {
setWarningMessage("Produced " + nrMissingValues + " missing values due to missing date" + " information in input date/time!");
}
return new BufferedDataTable[] { out };
}
Aggregations