Search in sources :

Example 11 with VNumber

use of org.diirt.vtype.VNumber in project yamcs-studio by yamcs.

the class AbstractVNumberArrayVNumberToVNumberArrayFormulaFunction method calculate.

@Override
public final Object calculate(List<Object> args) {
    if (NullUtils.containsNull(args)) {
        return null;
    }
    VNumberArray arg1 = (VNumberArray) args.get(0);
    VNumber arg2 = (VNumber) args.get(1);
    return newVNumberArray(calculate(arg1.getData(), arg2.getValue().doubleValue()), highestSeverityOf(args, false), latestValidTimeOrNowOf(args), displayNone());
}
Also used : ValueFactory.newVNumberArray(org.diirt.vtype.ValueFactory.newVNumberArray) VNumberArray(org.diirt.vtype.VNumberArray) VNumber(org.diirt.vtype.VNumber)

Example 12 with VNumber

use of org.diirt.vtype.VNumber in project yamcs-studio by yamcs.

the class CaHistogramFormulaFunction method calculateImpl.

Object calculateImpl(final String newName) {
    // If the name does not match, disconnect and connect
    if (!Objects.equals(newName, previousName)) {
        if (currentExpressions != null) {
            for (DesiredRateExpression<?> desiredRateExpression : currentExpressions) {
                if (desiredRateExpression != null) {
                    getDirector().disconnectReadExpression(desiredRateExpression);
                }
            }
        }
        List<DesiredRateExpression<?>> newExpressions = new ArrayList<>();
        if (newName != null) {
            newExpressions.addAll(Collections.nCopies(3, (DesiredRateExpression<?>) null));
        }
        // Connect new expressions
        if (newName != null) {
            DesiredRateExpression<?> newExpression = channel(newName, Object.class);
            getDirector().disconnectReadExpression(newExpression);
            newExpressions.set(0, newExpression);
            newExpression = channel(newName + ".LLIM", Object.class);
            getDirector().disconnectReadExpression(newExpression);
            newExpressions.set(1, newExpression);
            newExpression = channel(newName + ".ULIM", Object.class);
            getDirector().disconnectReadExpression(newExpression);
            newExpressions.set(2, newExpression);
        }
        previousName = newName;
        currentExpressions = newExpressions;
    }
    // No return value
    if (newName == null) {
        return null;
    }
    // Extract values
    VNumberArray array = (VNumberArray) currentExpressions.get(0).getFunction().readValue();
    VNumber lowerRange = (VNumber) currentExpressions.get(1).getFunction().readValue();
    VNumber upperRange = (VNumber) currentExpressions.get(2).getFunction().readValue();
    if (array == null || lowerRange == null || upperRange == null) {
        return null;
    }
    return ValueFactory.newVNumberArray(array.getData(), array.getSizes(), Arrays.asList(ValueFactory.newDisplay(VTableFactory.range(lowerRange.getValue().doubleValue(), upperRange.getValue().doubleValue()).createListNumber(array.getSizes().getInt(0) + 1), "")), array, array, array);
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) ArrayList(java.util.ArrayList) DesiredRateExpression(org.diirt.datasource.expression.DesiredRateExpression) VNumber(org.diirt.vtype.VNumber)

Example 13 with VNumber

use of org.diirt.vtype.VNumber in project yamcs-studio by yamcs.

the class ElementAtNumberFormulaFunction method calculate.

/*
     * (non-Javadoc)
     *
     * @see
     * org.epics.pvmanager.formula.FormulaFunction#calculate(java.util.List)
     */
@Override
public Object calculate(List<Object> args) {
    if (NullUtils.containsNull(args)) {
        return null;
    }
    VNumberArray numberArray = (VNumberArray) args.get(0);
    VNumber index = (VNumber) args.get(1);
    int i = index.getValue().intValue();
    return newVNumber(numberArray.getData().getDouble(i), numberArray, numberArray, displayNone());
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) ValueFactory.newVNumber(org.diirt.vtype.ValueFactory.newVNumber) VNumber(org.diirt.vtype.VNumber)

Example 14 with VNumber

use of org.diirt.vtype.VNumber in project yamcs-studio by yamcs.

the class IntegrateFormulaFunction method calculate.

@Override
public Object calculate(final List<Object> args) {
    VNumber value = (VNumber) args.get(0);
    if (value != null && value.getValue() != null) {
        values.add(value);
    }
    if (values.isEmpty()) {
        return null;
    }
    if (previousTime == null) {
        Instant now = Instant.now();
        if (now.compareTo(values.get(0).getTimestamp()) <= 0) {
            previousTime = now;
        } else {
            previousTime = values.get(0).getTimestamp();
        }
    }
    Instant currentTime = Instant.now();
    integratedValue += integrate(previousTime, currentTime, values);
    previousTime = currentTime;
    while (values.size() > 1 && values.get(1).getTimestamp().compareTo(currentTime) <= 0) {
        values.remove(0);
    }
    return ValueFactory.newVDouble(integratedValue);
}
Also used : Instant(java.time.Instant) VNumber(org.diirt.vtype.VNumber)

Example 15 with VNumber

use of org.diirt.vtype.VNumber in project yamcs-studio by yamcs.

the class RangeFormulaFunction method calculate.

@Override
public Object calculate(final List<Object> args) {
    VNumber minValue = (VNumber) args.get(0);
    VNumber maxValue = (VNumber) args.get(1);
    if (minValue == null || maxValue == null) {
        return null;
    }
    return VTableFactory.range(minValue.getValue().doubleValue(), maxValue.getValue().doubleValue());
}
Also used : VNumber(org.diirt.vtype.VNumber)

Aggregations

VNumber (org.diirt.vtype.VNumber)16 VNumberArray (org.diirt.vtype.VNumberArray)6 ArrayList (java.util.ArrayList)3 ValueFactory.newVNumberArray (org.diirt.vtype.ValueFactory.newVNumberArray)3 ListDouble (org.diirt.util.array.ListDouble)2 Display (org.diirt.vtype.Display)2 VStringArray (org.diirt.vtype.VStringArray)2 Instant (java.time.Instant)1 DesiredRateExpression (org.diirt.datasource.expression.DesiredRateExpression)1 Statistics (org.diirt.util.Statistics)1 ArrayDouble (org.diirt.util.array.ArrayDouble)1 VBoolean (org.diirt.vtype.VBoolean)1 VString (org.diirt.vtype.VString)1 ValueFactory.newDisplay (org.diirt.vtype.ValueFactory.newDisplay)1 ValueFactory.newVNumber (org.diirt.vtype.ValueFactory.newVNumber)1