use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.
the class TableSliceGroup method aggregate.
/**
* Applies the given aggregations to the given columns. The apply and combine steps of a
* split-apply-combine.
*
* @param functions map from column name to aggregation to apply on that function
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public Table aggregate(ListMultimap<String, AggregateFunction<?, ?>> functions) {
Table groupTable = summaryTableName(sourceTable);
StringColumn groupColumn = StringColumn.create("Group");
groupTable.addColumns(groupColumn);
boolean firstFunction = true;
for (Map.Entry<String, Collection<AggregateFunction<?, ?>>> entry : functions.asMap().entrySet()) {
String columnName = entry.getKey();
for (AggregateFunction function : entry.getValue()) {
String colName = aggregateColumnName(columnName, function.functionName());
ColumnType type = function.returnType();
Column resultColumn = type.create(colName);
for (TableSlice subTable : getSlices()) {
Object result = function.summarize(subTable.column(columnName));
if (firstFunction) {
groupColumn.append(subTable.name());
}
if (function.returnType().equals(ColumnType.DOUBLE)) {
Number number = (Number) result;
resultColumn.append(number.doubleValue());
} else {
resultColumn.append(result);
}
}
groupTable.addColumns(resultColumn);
firstFunction = false;
}
}
return splitGroupingColumn(groupTable);
}
use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.
the class DateMapFunctions method yearMonth.
/**
* Returns a StringColumn with the year and month from this column concatenated into a String that
* will sort lexicographically in temporal order.
*
* <p>This simplifies the production of plots and tables that aggregate values into standard
* temporal units (e.g., you want monthly data but your source data is more than a year long and
* you don't want months from different years aggregated together).
*/
default StringColumn yearMonth() {
StringColumn newColumn = StringColumn.create(this.name() + " year & month");
for (int r = 0; r < this.size(); r++) {
int c1 = this.getIntInternal(r);
if (DateColumn.valueIsMissing(c1)) {
newColumn.appendMissing();
} else {
String ym = String.valueOf(PackedLocalDate.getYear(c1));
ym = ym + "-" + Strings.padStart(String.valueOf(PackedLocalDate.getMonthValue(c1)), 2, '0');
newColumn.append(ym);
}
}
return newColumn;
}
use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.
the class DateMapFunctions method yearQuarter.
/**
* Returns a StringColumn with the year and quarter from this column concatenated into a String
* that will sort lexicographically in temporal order.
*
* <p>This simplifies the production of plots and tables that aggregate values into standard
* temporal units (e.g., you want monthly data but your source data is more than a year long and
* you don't want months from different years aggregated together).
*/
default StringColumn yearQuarter() {
StringColumn newColumn = StringColumn.create(this.name() + " year & quarter");
for (int r = 0; r < this.size(); r++) {
int c1 = this.getIntInternal(r);
if (DateColumn.valueIsMissing(c1)) {
newColumn.appendMissing();
} else {
String yq = String.valueOf(PackedLocalDate.getYear(c1));
yq = yq + "-" + Strings.padStart(String.valueOf(PackedLocalDate.getQuarter(c1)), 2, '0');
newColumn.append(yq);
}
}
return newColumn;
}
use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.
the class DateTimeMapFunctions method yearQuarter.
/**
* Returns a StringColumn with the year and quarter from this column concatenated into a String
* that will sort lexicographically in temporal order.
*
* <p>This simplifies the production of plots and tables that aggregate values into standard
* temporal units (e.g., you want monthly data but your source data is more than a year long and
* you don't want months from different years aggregated together).
*/
default StringColumn yearQuarter() {
StringColumn newColumn = StringColumn.create(this.name() + " year & quarter");
for (int r = 0; r < this.size(); r++) {
long c1 = this.getLongInternal(r);
if (DateTimeColumn.valueIsMissing(c1)) {
newColumn.append(StringColumnType.missingValueIndicator());
} else {
String yq = getYear(c1) + "-" + getQuarter(c1);
newColumn.append(yq);
}
}
return newColumn;
}
use of tech.tablesaw.api.StringColumn in project symja_android_library by axkr.
the class DateTimeMapFunctions method hourMinute.
/**
* Returns a StringColumn with the year and week-of-year derived from this column concatenated
* into a String that will sort lexicographically in temporal order.
*
* <p>This simplifies the production of plots and tables that aggregate values into standard
* temporal units (e.g., you want monthly data but your source data is more than a year long and
* you don't want months from different years aggregated together).
*/
default StringColumn hourMinute() {
StringColumn newColumn = StringColumn.create(this.name() + " hour & minute");
for (int r = 0; r < this.size(); r++) {
long c1 = this.getLongInternal(r);
if (DateTimeColumn.valueIsMissing(c1)) {
newColumn.append(StringColumnType.missingValueIndicator());
} else {
String hm = Strings.padStart(String.valueOf(getHour(c1)), 2, '0');
hm = hm + ":" + Strings.padStart(String.valueOf(getMinute(c1)), 2, '0');
newColumn.append(hm);
}
}
return newColumn;
}
Aggregations