Search in sources :

Example 6 with Quantity

use of org.activityinfo.model.type.number.Quantity in project activityinfo by bedatadriven.

the class RealValuedFunction method unaryFunctionCall.

private FieldValue unaryFunctionCall(FieldValue argument) {
    Quantity q = Casting.toQuantity(argument);
    if (Double.isNaN(q.getValue())) {
        return new Quantity(Double.NaN);
    }
    double d = toDouble(q);
    double value = apply(d);
    if (Double.isNaN(value)) {
        return new Quantity(Double.NaN);
    } else {
        return new Quantity(value);
    }
}
Also used : Quantity(org.activityinfo.model.type.number.Quantity)

Example 7 with Quantity

use of org.activityinfo.model.type.number.Quantity in project activityinfo by bedatadriven.

the class StatFunction method apply.

@Override
public final FieldValue apply(List<FieldValue> arguments) {
    double[] argumentValues = new double[arguments.size()];
    for (int i = 0; i < arguments.size(); i++) {
        FieldValue argument = arguments.get(i);
        if (argument instanceof Quantity) {
            Quantity quantity = (Quantity) argument;
            argumentValues[i] = quantity.getValue();
        } else {
            argumentValues[i] = Double.NaN;
        }
    }
    double result = compute(argumentValues, 0, argumentValues.length);
    return new Quantity(result);
}
Also used : Quantity(org.activityinfo.model.type.number.Quantity) FieldValue(org.activityinfo.model.type.FieldValue)

Example 8 with Quantity

use of org.activityinfo.model.type.number.Quantity in project activityinfo by bedatadriven.

the class CeilingFunctionTest method test.

@Test
public void test() {
    assertThat(CeilingFunction.INSTANCE.apply(1.6), Matchers.equalTo(2.0));
    assertThat(CeilingFunction.INSTANCE.apply(1.5), Matchers.equalTo(2.0));
    assertThat(CeilingFunction.INSTANCE.apply(1.4), Matchers.equalTo(2.0));
    assertThat(CeilingFunction.INSTANCE.apply(-1.6), Matchers.equalTo(-1.0));
    assertThat(CeilingFunction.INSTANCE.apply(-1.5), Matchers.equalTo(-1.0));
    assertThat(CeilingFunction.INSTANCE.apply(-1.4), Matchers.equalTo(-1.0));
    assertThat(CeilingFunction.INSTANCE.apply(Collections.<FieldValue>singletonList(new Quantity(1.5))), Matchers.<FieldValue>equalTo(new Quantity(2.0)));
    assertThat(CeilingFunction.INSTANCE.apply(Collections.<FieldValue>singletonList(new Quantity(-1.5))), Matchers.<FieldValue>equalTo(new Quantity(-1.0)));
}
Also used : Quantity(org.activityinfo.model.type.number.Quantity) FieldValue(org.activityinfo.model.type.FieldValue) Test(org.junit.Test)

Example 9 with Quantity

use of org.activityinfo.model.type.number.Quantity in project activityinfo by bedatadriven.

the class FloorFunctionTest method test.

@Test
public void test() {
    assertThat(FloorFunction.INSTANCE.apply(1.6), Matchers.equalTo(1.0));
    assertThat(FloorFunction.INSTANCE.apply(1.5), Matchers.equalTo(1.0));
    assertThat(FloorFunction.INSTANCE.apply(1.4), Matchers.equalTo(1.0));
    assertThat(FloorFunction.INSTANCE.apply(-1.6), Matchers.equalTo(-2.0));
    assertThat(FloorFunction.INSTANCE.apply(-1.5), Matchers.equalTo(-2.0));
    assertThat(FloorFunction.INSTANCE.apply(-1.4), Matchers.equalTo(-2.0));
    assertThat(FloorFunction.INSTANCE.apply(Collections.<FieldValue>singletonList(new Quantity(1.5))), Matchers.<FieldValue>equalTo(new Quantity(1.0)));
    assertThat(FloorFunction.INSTANCE.apply(Collections.<FieldValue>singletonList(new Quantity(-1.5))), Matchers.<FieldValue>equalTo(new Quantity(-2.0)));
}
Also used : Quantity(org.activityinfo.model.type.number.Quantity) FieldValue(org.activityinfo.model.type.FieldValue) Test(org.junit.Test)

Example 10 with Quantity

use of org.activityinfo.model.type.number.Quantity in project activityinfo by bedatadriven.

the class YearFracFunctionTest method evaluation.

@Test
public void evaluation() {
    LocalDate x = new LocalDate(2016, 1, 1);
    LocalDate y = new LocalDate(2017, 1, 1);
    Quantity z = (Quantity) YearFracFunction.INSTANCE.apply(Arrays.<FieldValue>asList(x, y));
    assertThat(z, equalTo(new Quantity(1.0)));
}
Also used : Quantity(org.activityinfo.model.type.number.Quantity) FieldValue(org.activityinfo.model.type.FieldValue) LocalDate(org.activityinfo.model.type.time.LocalDate) Test(org.junit.Test)

Aggregations

Quantity (org.activityinfo.model.type.number.Quantity)23 Test (org.junit.Test)13 FieldValue (org.activityinfo.model.type.FieldValue)9 LocalDate (org.activityinfo.model.type.time.LocalDate)8 FormClass (org.activityinfo.model.form.FormClass)6 ResourceId (org.activityinfo.model.resource.ResourceId)6 QuantityType (org.activityinfo.model.type.number.QuantityType)6 FormField (org.activityinfo.model.form.FormField)5 TypedRecordUpdate (org.activityinfo.store.spi.TypedRecordUpdate)5 QueryModel (org.activityinfo.model.query.QueryModel)4 GeoPoint (org.activityinfo.model.type.geo.GeoPoint)4 ColumnSet (org.activityinfo.model.query.ColumnSet)3 EnumValue (org.activityinfo.model.type.enumerated.EnumValue)3 ColumnSetBuilder (org.activityinfo.store.query.server.ColumnSetBuilder)3 NullFormSupervisor (org.activityinfo.store.query.shared.NullFormSupervisor)3 JsonValue (org.activityinfo.json.JsonValue)2 FormulaSyntaxException (org.activityinfo.model.formula.diagnostic.FormulaSyntaxException)2 KeyGenerator (org.activityinfo.model.legacy.KeyGenerator)2 RecordRef (org.activityinfo.model.type.RecordRef)2 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)2