Search in sources :

Example 16 with IntColumn

use of tech.tablesaw.api.IntColumn in project symja_android_library by axkr.

the class DateTimeMapFunctions method dayOfYear.

default IntColumn dayOfYear() {
    IntColumn newColumn = IntColumn.create(this.name() + " day of year", this.size());
    for (int r = 0; r < this.size(); r++) {
        if (!isMissing(r)) {
            long c1 = this.getLongInternal(r);
            newColumn.set(r, (short) getDayOfYear(c1));
        }
    }
    return newColumn;
}
Also used : IntColumn(tech.tablesaw.api.IntColumn)

Example 17 with IntColumn

use of tech.tablesaw.api.IntColumn in project symja_android_library by axkr.

the class DateTimeMapFunctions method year.

default IntColumn year() {
    IntColumn newColumn = IntColumn.create(this.name() + " year");
    for (int r = 0; r < this.size(); r++) {
        if (isMissing(r)) {
            newColumn.appendMissing();
        } else {
            long c1 = getLongInternal(r);
            newColumn.append(PackedLocalDate.getYear(PackedLocalDateTime.date(c1)));
        }
    }
    return newColumn;
}
Also used : IntColumn(tech.tablesaw.api.IntColumn)

Example 18 with IntColumn

use of tech.tablesaw.api.IntColumn in project symja_android_library by axkr.

the class DateTimeMapFunctions method dayOfWeekValue.

default IntColumn dayOfWeekValue() {
    IntColumn newColumn = IntColumn.create(this.name() + " day of week value", this.size());
    for (int r = 0; r < this.size(); r++) {
        if (!isMissing(r)) {
            long c1 = this.getLongInternal(r);
            newColumn.set(r, (short) getDayOfWeek(c1).getValue());
        }
    }
    return newColumn;
}
Also used : IntColumn(tech.tablesaw.api.IntColumn)

Example 19 with IntColumn

use of tech.tablesaw.api.IntColumn in project symja_android_library by axkr.

the class DateTimeMapFunctions method monthValue.

default IntColumn monthValue() {
    IntColumn newColumn = IntColumn.create(this.name() + " month");
    for (int r = 0; r < this.size(); r++) {
        if (isMissing(r)) {
            newColumn.appendMissing();
        } else {
            long c1 = getLongInternal(r);
            newColumn.append((short) getMonthValue(c1));
        }
    }
    return newColumn;
}
Also used : IntColumn(tech.tablesaw.api.IntColumn)

Example 20 with IntColumn

use of tech.tablesaw.api.IntColumn in project symja_android_library by axkr.

the class DateMapFunctions method timeUntil.

/**
 * Calculates the temporal difference between each element of the receiver and the respective
 * element of the argument
 *
 * <p>Missing values in either result in a Missing Value for the new column
 */
default IntColumn timeUntil(DateColumn end, ChronoUnit unit) {
    IntColumn newColumn = IntColumn.create(name() + " - " + end.name() + "[" + unit.name() + "]");
    for (int r = 0; r < size(); r++) {
        int c1 = getIntInternal(r);
        int c2 = end.getIntInternal(r);
        if (valueIsMissing(c1) || valueIsMissing(c2)) {
            newColumn.appendMissing();
        } else {
            switch(unit) {
                case DAYS:
                    newColumn.append(PackedLocalDate.daysUntil(c2, c1));
                    break;
                case WEEKS:
                    newColumn.append(PackedLocalDate.weeksUntil(c2, c1));
                    break;
                case MONTHS:
                    newColumn.append(PackedLocalDate.monthsUntil(c2, c1));
                    break;
                case YEARS:
                    newColumn.append(PackedLocalDate.yearsUntil(c2, c1));
                    break;
                default:
                    // handle decades, etc.
                    LocalDate value1 = PackedLocalDate.asLocalDate(c1);
                    LocalDate value2 = PackedLocalDate.asLocalDate(c2);
                    if (value1 == null || value2 == null) {
                        newColumn.appendMissing();
                    } else {
                        newColumn.append((int) unit.between(value1, value2));
                    }
                    break;
            }
        }
    }
    return newColumn;
}
Also used : LocalDate(java.time.LocalDate) 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