use of tech.tablesaw.api.IntColumn in project symja_android_library by axkr.
the class ByteDictionaryMap method countByCategory.
/**
*/
@Override
public Table countByCategory(String columnName) {
Table t = Table.create("Column: " + columnName);
StringColumn categories = StringColumn.create("Category");
IntColumn counts = IntColumn.create("Count");
// Now uses the keyToCount map
for (Map.Entry<Byte, Integer> entry : keyToCount.byte2IntEntrySet()) {
categories.append(getValueForKey(entry.getKey()));
counts.append(entry.getValue());
}
t.addColumns(categories);
t.addColumns(counts);
return t;
}
use of tech.tablesaw.api.IntColumn in project symja_android_library by axkr.
the class IntDictionaryMap method countByCategory.
/**
*/
@Override
public Table countByCategory(String columnName) {
Table t = Table.create("Column: " + columnName);
StringColumn categories = StringColumn.create("Category");
IntColumn counts = IntColumn.create("Count");
// Now uses the keyToCount map
for (Map.Entry<Integer, Integer> entry : keyToCount.int2IntEntrySet()) {
categories.append(getValueForKey(entry.getKey()));
counts.append(entry.getValue());
}
t.addColumns(categories);
t.addColumns(counts);
return t;
}
use of tech.tablesaw.api.IntColumn in project symja_android_library by axkr.
the class TimeMapFunctions method difference.
default IntColumn difference(TimeColumn column2, ChronoUnit unit) {
IntColumn newColumn = IntColumn.create(name() + " - " + column2.name() + "[" + unit.name() + "]");
for (int r = 0; r < size(); r++) {
int c1 = this.getIntInternal(r);
int c2 = column2.getIntInternal(r);
if (TimeColumn.valueIsMissing(c1) || TimeColumn.valueIsMissing(c2)) {
newColumn.append(IntColumnType.missingValueIndicator());
} else {
LocalTime value1 = PackedLocalTime.asLocalTime(c1);
LocalTime value2 = PackedLocalTime.asLocalTime(c2);
if (value1 != null && value2 != null) {
newColumn.append((int) unit.between(value1, value2));
} else {
newColumn.appendMissing();
}
}
}
return newColumn;
}
use of tech.tablesaw.api.IntColumn in project symja_android_library by axkr.
the class SqlResultSetReader method read.
/**
* Returns a new table with the given tableName, constructed from the given result set
*
* @throws SQLException if there is a problem detected in the database
*/
public static Table read(ResultSet resultSet) throws SQLException {
ResultSetMetaData metaData = resultSet.getMetaData();
Table table = Table.create();
// Setup the columns and add to the table
for (int i = 1; i <= metaData.getColumnCount(); i++) {
ColumnType type = getColumnType(metaData.getColumnType(i), metaData.getScale(i), metaData.getPrecision(i));
Preconditions.checkState(type != null, "No column type found for %s as specified for column %s", metaData.getColumnType(i), metaData.getColumnName(i));
Column<?> newColumn = type.create(metaData.getColumnLabel(i));
table.addColumns(newColumn);
}
// Add the rows
while (resultSet.next()) {
for (int i = 1; i <= metaData.getColumnCount(); i++) {
Column<?> column = // subtract 1 because results sets originate at 1 not 0
table.column(i - 1);
if (column instanceof ShortColumn) {
appendToColumn(column, resultSet, resultSet.getShort(i));
} else if (column instanceof IntColumn) {
appendToColumn(column, resultSet, resultSet.getInt(i));
} else if (column instanceof LongColumn) {
appendToColumn(column, resultSet, resultSet.getLong(i));
} else if (column instanceof FloatColumn) {
appendToColumn(column, resultSet, resultSet.getFloat(i));
} else if (column instanceof DoubleColumn) {
appendToColumn(column, resultSet, resultSet.getDouble(i));
} else if (column instanceof BooleanColumn) {
appendToColumn(column, resultSet, resultSet.getBoolean(i));
} else {
column.appendObj(resultSet.getObject(i));
}
}
}
return table;
}
use of tech.tablesaw.api.IntColumn in project symja_android_library by axkr.
the class DateMapFunctions method timeWindow.
/**
* Returns a column containing integers representing the nth group (0-based) that a date falls
* into.
*
* <p>Example: When Unit = ChronoUnit.DAY and n = 5, we form 5 day groups. a Date that is 2 days
* after the start is assigned to the first ("0") group. A day 7 days after the start is assigned
* to the second ("1") group.
*
* @param unit A ChronoUnit greater than or equal to a day
* @param n The number of units in each group.
* @param start The starting point of the first group; group boundaries are offsets from this
* point
*/
default IntColumn timeWindow(ChronoUnit unit, int n, LocalDate start) {
String newColumnName = "" + n + " " + unit.toString() + " window [" + name() + "]";
int packedStartDate = PackedLocalDate.pack(start);
IntColumn numberColumn = IntColumn.create(newColumnName, size());
for (int i = 0; i < size(); i++) {
int packedDate = getIntInternal(i);
int result;
switch(unit) {
case DAYS:
result = PackedLocalDate.daysUntil(packedDate, packedStartDate) / n;
numberColumn.set(i, result);
break;
case WEEKS:
result = PackedLocalDate.weeksUntil(packedDate, packedStartDate) / n;
numberColumn.set(i, result);
break;
case MONTHS:
result = PackedLocalDate.monthsUntil(packedDate, packedStartDate) / n;
numberColumn.set(i, result);
break;
case YEARS:
result = PackedLocalDate.yearsUntil(packedDate, packedStartDate) / n;
numberColumn.set(i, result);
break;
default:
throw new UnsupportedTemporalTypeException("The ChronoUnit " + unit + " is not supported for timeWindows on dates");
}
}
numberColumn.setPrintFormatter(NumberColumnFormatter.ints());
return numberColumn;
}
Aggregations