Search in sources :

Example 36 with DataCell

use of org.knime.core.data.DataCell in project knime-core by knime.

the class TwoSampleTTestStatistics 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 37 with DataCell

use of org.knime.core.data.DataCell in project knime-core by knime.

the class TwoSampleTTestStatistics method getGroupTable.

/**
 * Get descriptive statistics.
 * @param exec the execution context
 * @return the descriptive statistics for each group
 */
public BufferedDataTable getGroupTable(final ExecutionContext exec) {
    DataTableSpec outSpec = getGroupStatisticsSpec();
    BufferedDataContainer cont = exec.createDataContainer(outSpec);
    int r = 0;
    for (List<DataCell> cells : getGroupStatisticsCells()) {
        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 38 with DataCell

use of org.knime.core.data.DataCell 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 39 with DataCell

use of org.knime.core.data.DataCell 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 40 with DataCell

use of org.knime.core.data.DataCell 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)

Aggregations

DataCell (org.knime.core.data.DataCell)780 DataRow (org.knime.core.data.DataRow)268 DataTableSpec (org.knime.core.data.DataTableSpec)175 DataColumnSpec (org.knime.core.data.DataColumnSpec)170 DefaultRow (org.knime.core.data.def.DefaultRow)169 ArrayList (java.util.ArrayList)141 StringCell (org.knime.core.data.def.StringCell)131 DoubleCell (org.knime.core.data.def.DoubleCell)129 DoubleValue (org.knime.core.data.DoubleValue)111 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)109 DataType (org.knime.core.data.DataType)97 RowKey (org.knime.core.data.RowKey)94 BufferedDataTable (org.knime.core.node.BufferedDataTable)93 BufferedDataContainer (org.knime.core.node.BufferedDataContainer)91 DataColumnSpecCreator (org.knime.core.data.DataColumnSpecCreator)84 LinkedHashMap (java.util.LinkedHashMap)81 IntCell (org.knime.core.data.def.IntCell)79 HashMap (java.util.HashMap)60 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)57 ColumnRearranger (org.knime.core.data.container.ColumnRearranger)56