use of org.knime.core.data.date.DateAndTimeCell 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.DateAndTimeCell 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.DateAndTimeCell 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.DateAndTimeCell in project knime-core by knime.
the class DateShiftConfigure method getTimeBasedCellFactory.
/**
* @param spec the output column 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 getTimeBasedCellFactory(final DataColumnSpec spec, final int col1Idx, final int g, final DateShiftConfigure conf, final Calendar time) {
return new SingleCellFactory(spec) {
/**
* 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) {
final int value;
String typeofshift = conf.gettypeofshift().getStringValue();
if (typeofshift.equals(DateShiftNodeDialog.CFG_COLUMN_SHIFT)) {
DataCell cell1 = row.getCell(col1Idx);
if ((cell1.isMissing())) {
return DataType.getMissingCell();
}
value = ((IntValue) cell1).getIntValue();
} else {
value = conf.getvalueofshift().getIntValue();
}
Calendar c = (Calendar) time.clone();
c.add(g, value);
return new DateAndTimeCell(c.getTimeInMillis(), conf.getHasDate().getBooleanValue(), conf.getHasTime().getBooleanValue(), conf.getHasMiliSeconds().getBooleanValue());
}
};
}
use of org.knime.core.data.date.DateAndTimeCell in project knime-core by knime.
the class DateShiftConfigure method getColumnValuebasedCellFactory.
/**
* @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 col2Idx the time column
* @return the cell factory
*/
public static SingleCellFactory getColumnValuebasedCellFactory(final DataTableSpec spec, final int col1Idx, final int col2Idx, final int g, final DateShiftConfigure conf) {
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);
DataCell cell2 = row.getCell(col2Idx);
if ((cell1.isMissing()) || (cell2.isMissing())) {
return DataType.getMissingCell();
}
Calendar c = ((DateAndTimeValue) cell2).getUTCCalendarClone();
c.add(g, ((IntValue) cell1).getIntValue());
return new DateAndTimeCell(c.getTimeInMillis(), conf.getHasDate().getBooleanValue(), conf.getHasTime().getBooleanValue(), conf.getHasMiliSeconds().getBooleanValue());
}
};
}
Aggregations