Search in sources :

Example 1 with DoubleArrayColumnView

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);
}
Also used : FormulaSyntaxException(org.activityinfo.model.formula.diagnostic.FormulaSyntaxException) ColumnView(org.activityinfo.model.query.ColumnView) DoubleArrayColumnView(org.activityinfo.model.query.DoubleArrayColumnView) DoubleArrayColumnView(org.activityinfo.model.query.DoubleArrayColumnView)

Example 2 with DoubleArrayColumnView

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);
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) DoubleArrayColumnView(org.activityinfo.model.query.DoubleArrayColumnView) DoubleArrayColumnView(org.activityinfo.model.query.DoubleArrayColumnView)

Example 3 with DoubleArrayColumnView

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);
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) DoubleArrayColumnView(org.activityinfo.model.query.DoubleArrayColumnView) DoubleArrayColumnView(org.activityinfo.model.query.DoubleArrayColumnView)

Example 4 with DoubleArrayColumnView

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);
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) DoubleArrayColumnView(org.activityinfo.model.query.DoubleArrayColumnView) ConstantColumnView(org.activityinfo.model.query.ConstantColumnView) DoubleArrayColumnView(org.activityinfo.model.query.DoubleArrayColumnView) ConstantColumnView(org.activityinfo.model.query.ConstantColumnView)

Example 5 with DoubleArrayColumnView

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));
}
Also used : ColumnView(org.activityinfo.model.query.ColumnView) DoubleArrayColumnView(org.activityinfo.model.query.DoubleArrayColumnView) DoubleArrayColumnView(org.activityinfo.model.query.DoubleArrayColumnView) Test(org.junit.Test)

Aggregations

DoubleArrayColumnView (org.activityinfo.model.query.DoubleArrayColumnView)7 ColumnView (org.activityinfo.model.query.ColumnView)6 FormulaSyntaxException (org.activityinfo.model.formula.diagnostic.FormulaSyntaxException)1 ConstantColumnView (org.activityinfo.model.query.ConstantColumnView)1 Test (org.junit.Test)1