use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class YearFracFunction method columnApply.
@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
if (arguments.size() != 2) {
throw new FormulaSyntaxException("YEARFRAC() requires two arguments");
}
ColumnView startView = arguments.get(0);
ColumnView endView = arguments.get(1);
double[] result = new double[numRows];
for (int i = 0; i < numRows; i++) {
String start = startView.getString(i);
String end = endView.getString(i);
if (start == null || end == null) {
result[i] = Double.NaN;
} else {
result[i] = compute(LocalDate.parse(start), LocalDate.parse(end));
}
}
return new DoubleArrayColumnView(result);
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class AddDateFunction method columnApply.
@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
ColumnView dateView = arguments.get(0);
ColumnView daysView = arguments.get(1);
String[] result = new String[dateView.numRows()];
for (int i = 0; i < dateView.numRows(); i++) {
LocalDate date = LocalDate.parse(dateView.getString(i));
int days = (int) daysView.getDouble(i);
result[i] = date.plusDays(days).toString();
}
return new StringArrayColumnView(result);
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class DateComponentFunction method columnApply.
@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
checkArity(arguments, 1);
ColumnView view = arguments.get(0);
double[] result = new double[view.numRows()];
for (int i = 0; i < view.numRows(); i++) {
String date = view.getString(i);
if (date == null) {
result[i] = Double.NaN;
} else {
result[i] = apply(date);
}
}
return new DoubleArrayColumnView(result);
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class ComparisonOperator method columnApply.
@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
checkArity(arguments, 2);
ColumnView a = arguments.get(0);
ColumnView b = arguments.get(1);
if (a.numRows() != b.numRows()) {
throw new FormulaSyntaxException("Arguments must have the same number of rows");
}
if (a.getType() == ColumnType.NUMBER && b.getType() == ColumnType.NUMBER) {
return columnApplyNumber(a, b);
} else if (a.getType() == ColumnType.STRING && b.getType() == ColumnType.STRING) {
if (a instanceof EnumColumnView) {
return columnApplyEnum((EnumColumnView) a, b);
} else if (b instanceof EnumColumnView) {
return columnApplyEnum((EnumColumnView) b, a);
} else {
return columnApplyString(a, b);
}
} else {
throw new FormulaSyntaxException("Comparsion between incompatible types: " + a.getType() + ", " + b.getType());
}
}
use of org.activityinfo.model.query.ColumnView in project activityinfo by bedatadriven.
the class GetSitesHandler method extractSiteData.
private SiteDTO[] extractSiteData(List<FieldBinding> fieldBindings, ColumnSet columnSet) {
ColumnSet finalColumnSet;
SiteDTO[] sites;
if (offset > 0 || limit > 0) {
Map<String, ColumnView> paginatedColumns = Maps.newHashMap();
int[] index = generatePaginationIndex(columnSet.getNumRows());
sites = initialiseSites(index.length);
for (Map.Entry<String, ColumnView> column : columnSet.getColumns().entrySet()) {
paginatedColumns.put(column.getKey(), column.getValue().select(index));
}
finalColumnSet = new ColumnSet(index.length, paginatedColumns);
} else {
sites = initialiseSites(columnSet.getNumRows());
finalColumnSet = columnSet;
}
for (FieldBinding binding : fieldBindings) {
binding.extractFieldData(sites, finalColumnSet);
}
return sites;
}
Aggregations