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;
}
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;
}
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);
}
}
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();
}
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();
}
Aggregations