use of org.knime.core.data.date.DateAndTimeValue in project knime-core by knime.
the class TSAverageHandler method getMean.
private DataCell getMean() {
if (m_previous instanceof IntValue) {
// get an int, create an int
double mean = (((DoubleValue) m_previous).getDoubleValue() + ((DoubleValue) m_next).getDoubleValue()) * 0.5;
return new IntCell((int) Math.round(mean));
}
if (m_previous instanceof LongValue) {
// get an int, create an int
double mean = (((DoubleValue) m_previous).getDoubleValue() + ((DoubleValue) m_next).getDoubleValue()) * 0.5;
return new LongCell(Math.round(mean));
}
if (m_previous instanceof DoubleValue) {
// get an double, create an double
double mean = (((DoubleValue) m_previous).getDoubleValue() + ((DoubleValue) m_next).getDoubleValue()) * 0.5;
return new DoubleCell(mean);
}
if (m_previous instanceof DateAndTimeValue) {
// get an int, create an int
DateAndTimeValue dataCell1 = (DateAndTimeValue) m_previous;
DateAndTimeValue dataCell2 = ((DateAndTimeValue) m_next);
boolean hasDate = dataCell1.hasDate() | dataCell2.hasDate();
boolean hasTime = dataCell1.hasTime() | dataCell2.hasTime();
boolean hasMilis = dataCell1.hasMillis() | dataCell2.hasMillis();
double d = dataCell1.getUTCTimeInMillis() + dataCell2.getUTCTimeInMillis();
d *= 0.5;
return new DateAndTimeCell((long) d, hasDate, hasTime, hasMilis);
}
return DataType.getMissingCell();
}
use of org.knime.core.data.date.DateAndTimeValue in project knime-core by knime.
the class TSLinearHandler method getLinearInterpolation.
private DataCell getLinearInterpolation(final double stepnumber, final double stepcount) {
if (m_previous instanceof DoubleValue || m_previous instanceof IntValue || m_previous instanceof LongValue) {
double prev = ((DoubleValue) m_previous).getDoubleValue();
double next = ((DoubleValue) m_next).getDoubleValue();
double lin = prev + 1.0 * stepnumber / (1.0 * stepcount) * (next - prev);
if (m_previous instanceof IntValue) {
// get an int, create an int
return new IntCell((int) Math.round(lin));
}
if (m_previous instanceof LongValue) {
// get an long, create an long
return new LongCell(Math.round(lin));
}
return new DoubleCell(lin);
}
if (m_previous instanceof DateAndTimeValue) {
// get an int, create an int
DateAndTimeValue dataCell1 = (DateAndTimeValue) m_previous;
DateAndTimeValue dataCell2 = ((DateAndTimeValue) m_next);
boolean hasDate = dataCell1.hasDate() | dataCell2.hasDate();
boolean hasTime = dataCell1.hasTime() | dataCell2.hasTime();
boolean hasMilis = dataCell1.hasMillis() | dataCell2.hasMillis();
double prev = dataCell1.getUTCTimeInMillis();
double next = dataCell2.getUTCTimeInMillis();
double d = prev + stepnumber / stepcount * (next - prev);
return new DateAndTimeCell((long) d, hasDate, hasTime, hasMilis);
}
return DataType.getMissingCell();
}
use of org.knime.core.data.date.DateAndTimeValue in project knime-core by knime.
the class DateShiftConfigure method getColumnbasedCellFactory.
/**
* @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 col2Idx the time column
* @return the cell factory
*/
public static SingleCellFactory getColumnbasedCellFactory(final DataColumnSpec spec, final int col1Idx, final int col2Idx, final int g, final DateShiftConfigure conf) {
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;
DataCell cell2 = row.getCell(col2Idx);
if (cell2.isMissing()) {
return DataType.getMissingCell();
}
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 = ((DateAndTimeValue) cell2).getUTCCalendarClone();
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.DateAndTimeValue in project knime-core by knime.
the class LinearInterpolationStatisticTB method consumeRow.
/**
* {@inheritDoc}
*/
@Override
protected void consumeRow(final DataRow dataRow) {
DataCell cell = dataRow.getCell(getColumnIndex());
if (cell.isMissing()) {
incMissing();
} else {
for (int i = 0; i < getNumMissing(); i++) {
DataCell res;
if (getPrevious().isMissing()) {
res = cell;
} else {
if (m_isDateColumn) {
DateAndTimeValue val = (DateAndTimeValue) cell;
DateAndTimeValue prevVal = (DateAndTimeValue) getPrevious();
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 * (getNumMissing() + 1)) * (next - prev));
res = new DateAndTimeCell(lin, hasDate, hasTime, hasMilis);
} else {
DoubleValue val = (DoubleValue) cell;
double prev = ((DoubleValue) getPrevious()).getDoubleValue();
double next = val.getDoubleValue();
double lin = prev + 1.0 * (i + 1) / (1.0 * (getNumMissing() + 1)) * (next - prev);
if (getPrevious() instanceof IntValue) {
// get an int, create an int
res = new IntCell((int) Math.round(lin));
} else if (getPrevious() instanceof LongValue) {
// get an long, create an long
res = new LongCell(Math.round(lin));
} else {
res = new DoubleCell(lin);
}
}
}
addMapping(res);
}
resetMissing(cell);
}
}
use of org.knime.core.data.date.DateAndTimeValue in project knime-core by knime.
the class AverageInterpolationStatisticTB method consumeRow.
/**
* {@inheritDoc}
*/
@Override
protected void consumeRow(final DataRow dataRow) {
DataCell cell = dataRow.getCell(getColumnIndex());
if (cell.isMissing()) {
incMissing();
} else {
for (int i = 0; i < getNumMissing(); i++) {
DataCell res;
if (getPrevious().isMissing()) {
res = cell;
} else {
if (m_isDateColumn) {
DateAndTimeValue val = (DateAndTimeValue) cell;
DateAndTimeValue prevVal = (DateAndTimeValue) getPrevious();
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) getPrevious()).getDoubleValue();
double next = val.getDoubleValue();
double lin = (prev + next) / 2;
if (getPrevious() instanceof IntValue) {
// get an int, create an int
res = new IntCell((int) Math.round(lin));
} else if (getPrevious() instanceof LongValue) {
// get an long, create an long
res = new LongCell(Math.round(lin));
} else {
res = new DoubleCell(lin);
}
}
}
addMapping(res);
}
resetMissing(cell);
}
}
Aggregations