Search in sources :

Example 11 with DefaultRow

use of org.knime.core.data.def.DefaultRow in project knime-core by knime.

the class CreateDateTimeNodeModel method createByVariableRowNr.

/**
 * Create date&time row with a variable number of rows depending on a given starting point, a duration/period and an
 * ending point.
 */
private void createByVariableRowNr(final BufferedDataContainer container, final Temporal startDateTime, final Temporal endDateTime, final TemporalAmount durationOrPeriod) throws InvalidSettingsException {
    Temporal start = startDateTime;
    Temporal end = endDateTime;
    // check if duration is zero
    if ((durationOrPeriod instanceof Period) && ((Period) durationOrPeriod).isZero()) {
        setWarningMessage("Interval is zero! Node created an empty table.");
        return;
    } else if ((durationOrPeriod instanceof Duration) && ((Duration) durationOrPeriod).isZero()) {
        setWarningMessage("Interval is zero! Node created an empty table.");
        return;
    }
    // === check if start date is after end ===
    boolean wasLocalTime = start instanceof LocalTime;
    final boolean isStartAfterEnd;
    if (start instanceof LocalDate) {
        isStartAfterEnd = ((LocalDate) start).isAfter((LocalDate) end);
    } else if (start instanceof LocalTime) {
        // because of the problem that 00:00 is before 23:59, a local time needs to be temporarily converted
        // to a local date time
        boolean isLocalTimeStartAfterEnd = ((LocalTime) start).isAfter((LocalTime) end);
        final boolean isDurationNegative = ((Duration) durationOrPeriod).isNegative();
        int daysAddedToEnd = 0;
        if (isLocalTimeStartAfterEnd && !isDurationNegative) {
            daysAddedToEnd = 1;
        }
        if (!isLocalTimeStartAfterEnd && isDurationNegative) {
            daysAddedToEnd = -1;
        }
        if (start.equals(end)) {
            daysAddedToEnd = 0;
        }
        final int dayOfYear = 10;
        start = LocalDateTime.of(LocalDate.ofYearDay(2010, dayOfYear), (LocalTime) start);
        end = LocalDateTime.of(LocalDate.ofYearDay(2010, dayOfYear + daysAddedToEnd), (LocalTime) end);
        isStartAfterEnd = ((LocalDateTime) start).isAfter((LocalDateTime) end);
    } else if (start instanceof LocalDateTime) {
        isStartAfterEnd = ((LocalDateTime) start).isAfter((LocalDateTime) end);
    } else {
        isStartAfterEnd = ((ZonedDateTime) start).isAfter((ZonedDateTime) end);
    }
    // === check if input is legal: duration/period needs to be positive if end is after start and vice versa ===
    final String warningMsgPos = "Interval must be positive, if end is after start date! Node created an empty table.";
    final String warningMsgNeg = "Interval must be negative, if end is before start date! Node created an empty table.";
    if (start instanceof LocalDate) {
        if ((((LocalDate) end).isAfter((LocalDate) start)) && (((LocalDate) start.plus(durationOrPeriod)).isBefore((LocalDate) start))) {
            setWarningMessage(warningMsgPos);
            return;
        }
        if ((((LocalDate) end).isBefore((LocalDate) start)) && (((LocalDate) start.plus(durationOrPeriod)).isAfter((LocalDate) start))) {
            setWarningMessage(warningMsgNeg);
            return;
        }
    } else if (start instanceof LocalDateTime) {
        if ((((LocalDateTime) end).isAfter((LocalDateTime) start)) && (((LocalDateTime) start.plus(durationOrPeriod)).isBefore((LocalDateTime) start))) {
            setWarningMessage(warningMsgPos);
            return;
        }
        if ((((LocalDateTime) end).isBefore((LocalDateTime) start)) && (((LocalDateTime) start.plus(durationOrPeriod)).isAfter((LocalDateTime) start))) {
            setWarningMessage(warningMsgNeg);
            return;
        }
    } else if (start instanceof ZonedDateTime) {
        if ((((ZonedDateTime) end).isAfter((ZonedDateTime) start)) && (((ZonedDateTime) start.plus(durationOrPeriod)).isBefore((ZonedDateTime) start))) {
            setWarningMessage(warningMsgPos);
            return;
        }
        if ((((ZonedDateTime) end).isBefore((ZonedDateTime) start)) && (((ZonedDateTime) start.plus(durationOrPeriod)).isAfter((ZonedDateTime) start))) {
            setWarningMessage(warningMsgNeg);
            return;
        }
    }
    // === create rows ===
    Temporal currentDateTime = start;
    long row_idx = 0;
    while (true) {
        final DataCell dataCell;
        final boolean isEqual = currentDateTime.equals(end);
        final boolean isCurrentAfterEnd;
        if (currentDateTime instanceof LocalDate) {
            isCurrentAfterEnd = ((LocalDate) currentDateTime).isAfter((LocalDate) end);
            dataCell = LocalDateCellFactory.create((LocalDate) currentDateTime);
        } else if (currentDateTime instanceof LocalDateTime) {
            isCurrentAfterEnd = ((LocalDateTime) currentDateTime).isAfter((LocalDateTime) end);
            if (wasLocalTime) {
                dataCell = LocalTimeCellFactory.create((((LocalDateTime) currentDateTime).truncatedTo(ChronoUnit.MILLIS)).toLocalTime());
            } else {
                dataCell = LocalDateTimeCellFactory.create(((LocalDateTime) currentDateTime).truncatedTo(ChronoUnit.MILLIS));
            }
        } else {
            isCurrentAfterEnd = ((ZonedDateTime) currentDateTime).isAfter((ZonedDateTime) end);
            dataCell = ZonedDateTimeCellFactory.create(((ZonedDateTime) currentDateTime).truncatedTo(ChronoUnit.MILLIS));
        }
        if ((isCurrentAfterEnd && !isStartAfterEnd) || (!isCurrentAfterEnd && !isEqual && isStartAfterEnd)) {
            break;
        }
        container.addRowToTable(new DefaultRow(new RowKey("Row" + row_idx++), dataCell));
        if (isEqual) {
            break;
        }
        currentDateTime = currentDateTime.plus(durationOrPeriod);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) RowKey(org.knime.core.data.RowKey) Period(java.time.Period) Duration(java.time.Duration) SettingsModelString(org.knime.core.node.defaultnodesettings.SettingsModelString) LocalDate(java.time.LocalDate) Temporal(java.time.temporal.Temporal) ZonedDateTime(java.time.ZonedDateTime) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 12 with DefaultRow

use of org.knime.core.data.def.DefaultRow in project knime-core by knime.

the class OneWayANOVANodeModel method getDescriptiveStatisticsTable.

/**
 * Get table with descriptive statistics
 * @param result test statistic
 * @param exec the exection context
 * @return a combined table of the test statistic
 */
private BufferedDataTable getDescriptiveStatisticsTable(final OneWayANOVAStatistics[] result, final ExecutionContext exec) {
    BufferedDataContainer cont = exec.createDataContainer(OneWayANOVAStatistics.getGroupStatisticsSpec());
    int r = 0;
    for (int i = 0; i < result.length; i++) {
        for (List<DataCell> cells : result[i].getGroupStatisticsCells()) {
            cont.addRowToTable(new DefaultRow(RowKey.createRowKey(r), cells));
            r++;
        }
    }
    cont.close();
    return cont.getTable();
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 13 with DefaultRow

use of org.knime.core.data.def.DefaultRow in project knime-core by knime.

the class OneWayANOVANodeModel method getTestStatisticsTable.

/**
 * Get table with test statistics
 * @param result test statistic
 * @param exec the execution context
 * @return a combined table of the test statistic
 */
private BufferedDataTable getTestStatisticsTable(final OneWayANOVAStatistics[] result, final ExecutionContext exec) {
    BufferedDataContainer cont = exec.createDataContainer(OneWayANOVAStatistics.getTableSpec());
    int r = 0;
    for (int i = 0; i < result.length; i++) {
        for (List<DataCell> cells : result[i].getTTestCells()) {
            cont.addRowToTable(new DefaultRow(RowKey.createRowKey(r), cells));
            r++;
        }
    }
    cont.close();
    return cont.getTable();
}
Also used : BufferedDataContainer(org.knime.core.node.BufferedDataContainer) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 14 with DefaultRow

use of org.knime.core.data.def.DefaultRow in project knime-core by knime.

the class LeveneTestStatistics method getTTestTable.

/**
 * Get the test result of the t-test, for the assumption of equal
 * variance and the assumption of unequal variances.
 * @param exec the execution context
 * @return the t-test results
 */
public BufferedDataTable getTTestTable(final ExecutionContext exec) {
    DataTableSpec outSpec = getTableSpec();
    BufferedDataContainer cont = exec.createDataContainer(outSpec);
    int r = 0;
    for (List<DataCell> cells : getTTestCells()) {
        cont.addRowToTable(new DefaultRow(RowKey.createRowKey(r), cells));
        r++;
    }
    cont.close();
    BufferedDataTable outTable = cont.getTable();
    return outTable;
}
Also used : DataTableSpec(org.knime.core.data.DataTableSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) BufferedDataTable(org.knime.core.node.BufferedDataTable) DataCell(org.knime.core.data.DataCell) DefaultRow(org.knime.core.data.def.DefaultRow)

Example 15 with DefaultRow

use of org.knime.core.data.def.DefaultRow in project knime-core by knime.

the class StandCronbachNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inData, final ExecutionContext exec) throws Exception {
    PMCCPortObjectAndSpec model = (PMCCPortObjectAndSpec) inData[0];
    HalfDoubleMatrix mat = model.getCorrelationMatrix();
    double sum = 0;
    double count = 0;
    for (int i = 0; i < mat.getRowCount(); i++) {
        for (int j = i + 1; j < mat.getRowCount(); j++) {
            if (Double.isNaN(mat.get(i, j))) {
                throw new IOException("No NAN values supported for the calculation, " + "try using an alternative correlation meassure");
            }
            sum += mat.get(i, j);
            count++;
        }
    }
    double mean = sum / count;
    double cronbach = (mat.getRowCount() * mean) / (1 + (mat.getRowCount() - 1) * mean);
    BufferedDataContainer out = exec.createDataContainer(getDataTableSpec());
    RowKey k = new RowKey("Cronbach");
    DataRow r = new DefaultRow(k, new DoubleCell(cronbach));
    out.addRowToTable(r);
    out.close();
    return new BufferedDataTable[] { out.getTable() };
}
Also used : PMCCPortObjectAndSpec(org.knime.base.node.preproc.correlation.pmcc.PMCCPortObjectAndSpec) BufferedDataContainer(org.knime.core.node.BufferedDataContainer) RowKey(org.knime.core.data.RowKey) DoubleCell(org.knime.core.data.def.DoubleCell) HalfDoubleMatrix(org.knime.base.util.HalfDoubleMatrix) BufferedDataTable(org.knime.core.node.BufferedDataTable) IOException(java.io.IOException) DefaultRow(org.knime.core.data.def.DefaultRow) DataRow(org.knime.core.data.DataRow)

Aggregations

DefaultRow (org.knime.core.data.def.DefaultRow)207 DataCell (org.knime.core.data.DataCell)165 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)94 DataTableSpec (org.knime.core.data.DataTableSpec)92 DataRow (org.knime.core.data.DataRow)88 RowKey (org.knime.core.data.RowKey)80 DoubleCell (org.knime.core.data.def.DoubleCell)66 StringCell (org.knime.core.data.def.StringCell)65 BufferedDataTable (org.knime.core.node.BufferedDataTable)56 IntCell (org.knime.core.data.def.IntCell)46 ArrayList (java.util.ArrayList)26 DataType (org.knime.core.data.DataType)26 DataColumnSpec (org.knime.core.data.DataColumnSpec)22 DataContainer (org.knime.core.data.container.DataContainer)21 HashSet (java.util.HashSet)18 LinkedHashMap (java.util.LinkedHashMap)17 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)16 LinkedHashSet (java.util.LinkedHashSet)14 DoubleValue (org.knime.core.data.DoubleValue)14 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)14