Search in sources :

Example 11 with IntColumn

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StringColumn(tech.tablesaw.api.StringColumn) Table(tech.tablesaw.api.Table) Byte2ObjectOpenHashMap(it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap) Map(java.util.Map) Byte2ObjectMap(it.unimi.dsi.fastutil.bytes.Byte2ObjectMap) Byte2IntOpenHashMap(it.unimi.dsi.fastutil.bytes.Byte2IntOpenHashMap) Byte2IntMap(it.unimi.dsi.fastutil.bytes.Byte2IntMap) Object2ByteOpenHashMap(it.unimi.dsi.fastutil.objects.Object2ByteOpenHashMap) IntColumn(tech.tablesaw.api.IntColumn)

Example 12 with IntColumn

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;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StringColumn(tech.tablesaw.api.StringColumn) Table(tech.tablesaw.api.Table) Int2IntMap(it.unimi.dsi.fastutil.ints.Int2IntMap) Map(java.util.Map) Object2IntOpenHashMap(it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap) Int2ObjectOpenHashMap(it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap) Int2IntOpenHashMap(it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap) Int2ObjectMap(it.unimi.dsi.fastutil.ints.Int2ObjectMap) IntColumn(tech.tablesaw.api.IntColumn)

Example 13 with IntColumn

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;
}
Also used : LocalTime(java.time.LocalTime) IntColumn(tech.tablesaw.api.IntColumn)

Example 14 with IntColumn

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;
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) LongColumn(tech.tablesaw.api.LongColumn) Table(tech.tablesaw.api.Table) ColumnType(tech.tablesaw.api.ColumnType) DoubleColumn(tech.tablesaw.api.DoubleColumn) ShortColumn(tech.tablesaw.api.ShortColumn) BooleanColumn(tech.tablesaw.api.BooleanColumn) FloatColumn(tech.tablesaw.api.FloatColumn) IntColumn(tech.tablesaw.api.IntColumn)

Example 15 with IntColumn

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;
}
Also used : UnsupportedTemporalTypeException(java.time.temporal.UnsupportedTemporalTypeException) IntColumn(tech.tablesaw.api.IntColumn)

Aggregations

IntColumn (tech.tablesaw.api.IntColumn)22 Table (tech.tablesaw.api.Table)7 StringColumn (tech.tablesaw.api.StringColumn)4 Map (java.util.Map)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 DoubleColumn (tech.tablesaw.api.DoubleColumn)2 TreeBasedTable (com.google.common.collect.TreeBasedTable)1 Byte2IntMap (it.unimi.dsi.fastutil.bytes.Byte2IntMap)1 Byte2IntOpenHashMap (it.unimi.dsi.fastutil.bytes.Byte2IntOpenHashMap)1 Byte2ObjectMap (it.unimi.dsi.fastutil.bytes.Byte2ObjectMap)1 Byte2ObjectOpenHashMap (it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap)1 Int2IntMap (it.unimi.dsi.fastutil.ints.Int2IntMap)1 Int2IntOpenHashMap (it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap)1 Int2ObjectMap (it.unimi.dsi.fastutil.ints.Int2ObjectMap)1 Int2ObjectOpenHashMap (it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap)1 Object2ByteOpenHashMap (it.unimi.dsi.fastutil.objects.Object2ByteOpenHashMap)1 Object2IntOpenHashMap (it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap)1 Object2ShortOpenHashMap (it.unimi.dsi.fastutil.objects.Object2ShortOpenHashMap)1 Short2IntMap (it.unimi.dsi.fastutil.shorts.Short2IntMap)1 Short2IntOpenHashMap (it.unimi.dsi.fastutil.shorts.Short2IntOpenHashMap)1