use of org.knime.core.data.date.DateAndTimeValue 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.date.DateAndTimeValue in project knime-core by knime.
the class MedianDateOperator method getResultInternal.
/**
* {@inheritDoc}
*/
@Override
protected DataCell getResultInternal() {
final int size = m_cells.size();
if (size == 0) {
return DataType.getMissingCell();
}
if (size == 1) {
return m_cells.get(0);
}
Collections.sort(m_cells, m_comparator);
final double middle = size / 2.0;
if (middle > (int) middle) {
return m_cells.get((int) middle);
}
// the list is even return the middle two
final DateAndTimeValue date1 = (DateAndTimeValue) m_cells.get((int) middle - 1);
final DateAndTimeValue date2 = (DateAndTimeValue) m_cells.get((int) middle);
final long millis1 = date1.getUTCTimeInMillis();
final long millis2 = date2.getUTCTimeInMillis();
return new DateAndTimeCell((millis1 + millis2) / 2, date1.hasDate() || date2.hasDate(), date1.hasTime() || date2.hasTime(), date1.hasMillis() || date2.hasMillis());
}
use of org.knime.core.data.date.DateAndTimeValue in project knime-core by knime.
the class DayRangeOperator method getResultInternal.
/**
* {@inheritDoc}
*/
@Override
protected DataCell getResultInternal() {
final DateAndTimeValue min = getMin();
final DateAndTimeValue max = getMax();
if (min == null || max == null) {
return DataType.getMissingCell();
}
final long range = max.getUTCTimeInMillis() - min.getUTCTimeInMillis();
if (range == 0) {
return new DoubleCell(0);
}
return new DoubleCell(range / MS_PER_DAY);
}
use of org.knime.core.data.date.DateAndTimeValue in project knime-core by knime.
the class AverageInterpolationStatisticMB method consumeRow.
/**
* {@inheritDoc}
*/
@Override
protected void consumeRow(final DataRow dataRow) {
DataCell cell = dataRow.getCell(m_colIdx);
if (cell.isMissing()) {
m_numMissing++;
} else {
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 + next) / 2);
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 + next) / 2;
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);
}
}
}
for (int i = 0; i < m_numMissing; i++) {
m_values.add(res);
}
m_previous = cell;
m_numMissing = 0;
}
}
use of org.knime.core.data.date.DateAndTimeValue in project knime-core by knime.
the class OldToNewTimeNodeModel method getNewIncludedColumnSpecs.
/**
* @param inSpec Current input spec
* @param row First row of the table, if called by execute, or null, if called by configure
* @return Column specs of the output (only of the included columns)
*/
private DataColumnSpec[] getNewIncludedColumnSpecs(final DataTableSpec inSpec, final DataRow row) {
final String[] includes = m_colSelect.applyTo(inSpec).getIncludes();
m_newTypes = new DateTimeType[includes.length];
final DataColumnSpec[] newSpec = new DataColumnSpec[includes.length];
/*
* if the types of the cells should determined automatically by the content of the first row
*/
if (m_autoType.getBooleanValue()) {
// row is null, if the method is called by the configure method
if (row != null) {
DataColumnSpecCreator dataColumnSpecCreator = null;
for (int i = 0; i < includes.length; i++) {
final DataCell cell = row.getCell(inSpec.findColumnIndex(includes[i]));
if (cell.isMissing()) {
m_newTypes[i] = DateTimeType.LOCAL_DATE_TIME;
dataColumnSpecCreator = new DataColumnSpecCreator(includes[i], DataType.getType(LocalDateTimeCell.class));
} else {
final DateAndTimeValue timeCell = (DateAndTimeValue) cell;
if (!timeCell.hasDate()) {
m_newTypes[i] = DateTimeType.LOCAL_TIME;
dataColumnSpecCreator = new DataColumnSpecCreator(includes[i], DataType.getType(LocalTimeCell.class));
} else {
if (!timeCell.hasTime()) {
m_newTypes[i] = DateTimeType.LOCAL_DATE;
dataColumnSpecCreator = new DataColumnSpecCreator(includes[i], DataType.getType(LocalDateCell.class));
} else {
if (m_addZone.getBooleanValue()) {
m_newTypes[i] = DateTimeType.ZONED_DATE_TIME;
dataColumnSpecCreator = new DataColumnSpecCreator(includes[i], DataType.getType(ZonedDateTimeCell.class));
} else {
m_newTypes[i] = DateTimeType.LOCAL_DATE_TIME;
dataColumnSpecCreator = new DataColumnSpecCreator(includes[i], DataType.getType(LocalDateTimeCell.class));
}
}
}
}
newSpec[i] = dataColumnSpecCreator.createSpec();
}
return newSpec;
// row is not null, if the method is called by the execute method
} else {
return null;
}
/*
* if the type of the new cells is determined by the user itself
*/
} else {
DateTimeType type = DateTimeType.valueOf(m_selectedNewType);
DataType newDataType = type.getDataType();
for (int i = 0; i < includes.length; i++) {
final DataColumnSpecCreator dataColumnSpecCreator = new DataColumnSpecCreator(includes[i], newDataType);
newSpec[i] = dataColumnSpecCreator.createSpec();
m_newTypes[i] = type;
}
return newSpec;
}
}
Aggregations