Search in sources :

Example 11 with DateAndTimeValue

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;
    }
}
Also used : DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell) LongCell(org.knime.core.data.def.LongCell) DoubleValue(org.knime.core.data.DoubleValue) LongValue(org.knime.core.data.LongValue) DataCell(org.knime.core.data.DataCell) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell) IntValue(org.knime.core.data.IntValue)

Example 12 with DateAndTimeValue

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());
}
Also used : DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell)

Example 13 with DateAndTimeValue

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);
}
Also used : DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) DoubleCell(org.knime.core.data.def.DoubleCell)

Example 14 with DateAndTimeValue

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;
    }
}
Also used : DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) DoubleCell(org.knime.core.data.def.DoubleCell) IntCell(org.knime.core.data.def.IntCell) LongCell(org.knime.core.data.def.LongCell) DoubleValue(org.knime.core.data.DoubleValue) LongValue(org.knime.core.data.LongValue) DataCell(org.knime.core.data.DataCell) DateAndTimeCell(org.knime.core.data.date.DateAndTimeCell) IntValue(org.knime.core.data.IntValue)

Example 15 with DateAndTimeValue

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;
    }
}
Also used : DateTimeType(org.knime.time.util.DateTimeType) DataColumnSpec(org.knime.core.data.DataColumnSpec) DataColumnSpecCreator(org.knime.core.data.DataColumnSpecCreator) DateAndTimeValue(org.knime.core.data.date.DateAndTimeValue) DataCell(org.knime.core.data.DataCell) DataType(org.knime.core.data.DataType) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString)

Aggregations

DateAndTimeValue (org.knime.core.data.date.DateAndTimeValue)24 DataCell (org.knime.core.data.DataCell)16 DateAndTimeCell (org.knime.core.data.date.DateAndTimeCell)11 DataRow (org.knime.core.data.DataRow)8 DoubleValue (org.knime.core.data.DoubleValue)8 IntValue (org.knime.core.data.IntValue)8 LongValue (org.knime.core.data.LongValue)8 IntCell (org.knime.core.data.def.IntCell)8 DoubleCell (org.knime.core.data.def.DoubleCell)7 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)7 Calendar (java.util.Calendar)6 SingleCellFactory (org.knime.core.data.container.SingleCellFactory)6 LongCell (org.knime.core.data.def.LongCell)6 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)5 SettingsModelCalendar (org.knime.timeseries.util.SettingsModelCalendar)5 DataColumnSpec (org.knime.core.data.DataColumnSpec)3 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)3 BufferedDataTable (org.knime.core.node.BufferedDataTable)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2