use of org.activityinfo.model.query.DoubleArrayColumnView 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.DoubleArrayColumnView 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.DoubleArrayColumnView in project activityinfo by bedatadriven.
the class RealValuedFunction method binaryFunctionColumnCall.
private ColumnView binaryFunctionColumnCall(int numRows, List<ColumnView> arguments) {
ColumnView x = arguments.get(0);
ColumnView y = arguments.get(1);
double[] result = new double[x.numRows()];
for (int i = 0; i < result.length; i++) {
double xd = x.getDouble(i);
double yd = y.getDouble(i);
if (Double.isNaN(xd) && Double.isNaN(yd)) {
result[i] = Double.NaN;
} else {
if (Double.isNaN(xd)) {
xd = 0;
}
if (Double.isNaN(yd)) {
yd = 0;
}
result[i] = apply(xd, yd);
}
}
return new DoubleArrayColumnView(result);
}
use of org.activityinfo.model.query.DoubleArrayColumnView in project activityinfo by bedatadriven.
the class SearchFunction method columnApply.
@Override
public ColumnView columnApply(int numRows, List<ColumnView> arguments) {
ColumnView substring = arguments.get(0);
ColumnView string = arguments.get(1);
ColumnView startIndex;
if (arguments.size() == 3) {
startIndex = arguments.get(3);
} else {
startIndex = new ConstantColumnView(numRows, 1d);
}
double[] result = new double[numRows];
for (int i = 0; i < numRows; i++) {
result[i] = apply(substring.getString(i), string.getString(i), startIndex.getDouble(i));
}
return new DoubleArrayColumnView(result);
}
use of org.activityinfo.model.query.DoubleArrayColumnView in project activityinfo by bedatadriven.
the class CoalesceFunctionTest method combineDouble.
@Test
public void combineDouble() {
DoubleArrayColumnView x = new DoubleArrayColumnView(new double[] { 80, NaN, 82, NaN, 84 });
DoubleArrayColumnView y = new DoubleArrayColumnView(new double[] { 90, NaN, 92, 93, NaN });
ColumnView z = CoalesceFunction.combineDouble(new ColumnView[] { x, y });
assertThat(z.getDouble(0), equalTo(80.0));
assertThat(z.getDouble(1), equalTo(NaN));
assertThat(z.getDouble(2), equalTo(82.0));
assertThat(z.getDouble(3), equalTo(93.0));
assertThat(z.getDouble(4), equalTo(84.0));
}
Aggregations