Search in sources :

Example 16 with VNumberArray

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

the class VTypeHelper method formatNumberArray.

private static String formatNumberArray(FormatEnum formatEnum, VNumberArray pmArray, int precision) {
    ListNumber data = ((VNumberArray) pmArray).getData();
    if (formatEnum == FormatEnum.STRING) {
        final byte[] bytes = new byte[data.size()];
        // Copy bytes until end _or_ '\0'
        int len = 0;
        while (len < bytes.length) {
            final byte b = data.getByte(len);
            if (b == 0)
                break;
            else
                bytes[len++] = b;
        }
        return new String(bytes, 0, len);
    } else {
        if (data.size() <= 0)
            // $NON-NLS-1$
            return "[]";
        int displayPrecision = calculatePrecision(pmArray, precision);
        StringBuilder sb = new StringBuilder(data.size());
        sb.append(formatScalarNumber(formatEnum, data.getDouble(0), displayPrecision));
        for (int i = 1; i < data.size(); i++) {
            sb.append(ARRAY_ELEMENT_SEPARATOR);
            sb.append(formatScalarNumber(formatEnum, data.getDouble(i), displayPrecision));
            if (i >= MAX_FORMAT_VALUE_COUNT) {
                sb.append(ARRAY_ELEMENT_SEPARATOR);
                // $NON-NLS-1$
                sb.append("...");
                sb.append(formatScalarNumber(formatEnum, data.getDouble(data.size() - 1), displayPrecision));
                // $NON-NLS-1$
                sb.append(" ");
                // $NON-NLS-1$
                sb.append("[");
                sb.append(data.size());
                // $NON-NLS-1$
                sb.append("]");
                break;
            }
        }
        return sb.toString();
    }
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) ListNumber(org.diirt.util.array.ListNumber) VString(org.diirt.vtype.VString)

Example 17 with VNumberArray

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

the class AbstractVNumberArrayVNumberArrayToVNumberArrayFormulaFunction method calculate.

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

Example 18 with VNumberArray

use of org.diirt.vtype.VNumberArray 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 19 with VNumberArray

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

the class ArrayWithBoundariesFormulaFunction method calculate.

@Override
public Object calculate(final List<Object> args) {
    if (NullUtils.containsNull(args)) {
        return null;
    }
    VNumberArray array = (VNumberArray) args.get(0);
    if (array.getSizes().size() != args.size() - 1) {
        throw new IllegalArgumentException("Dimension of the array must match the number of ListNumberProvider");
    }
    List<ArrayDimensionDisplay> dimDisplay = new ArrayList<>();
    for (int i = 1; i < args.size(); i++) {
        ListNumberProvider numberGenerator = (ListNumberProvider) args.get(i);
        dimDisplay.add(ValueFactory.newDisplay(numberGenerator.createListNumber(array.getSizes().getInt(i - 1) + 1), ""));
    }
    return ValueFactory.newVNumberArray(array.getData(), array.getSizes(), dimDisplay, array, array, array);
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) ArrayDimensionDisplay(org.diirt.vtype.ArrayDimensionDisplay) ArrayList(java.util.ArrayList) ListNumberProvider(org.diirt.vtype.table.ListNumberProvider)

Example 20 with VNumberArray

use of org.diirt.vtype.VNumberArray 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)

Aggregations

VNumberArray (org.diirt.vtype.VNumberArray)30 ListNumber (org.diirt.util.array.ListNumber)13 VNumber (org.diirt.vtype.VNumber)10 VString (org.diirt.vtype.VString)6 ValueFactory.newVNumberArray (org.diirt.vtype.ValueFactory.newVNumberArray)6 VEnumArray (org.diirt.vtype.VEnumArray)5 VType (org.diirt.vtype.VType)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 ArrayDouble (org.diirt.util.array.ArrayDouble)4 ListInt (org.diirt.util.array.ListInt)4 VStringArray (org.diirt.vtype.VStringArray)4 VEnum (org.diirt.vtype.VEnum)3 VTable (org.diirt.vtype.VTable)3 Background (javafx.scene.layout.Background)2 BackgroundFill (javafx.scene.layout.BackgroundFill)2 ListDouble (org.diirt.util.array.ListDouble)2 ArrayDimensionDisplay (org.diirt.vtype.ArrayDimensionDisplay)2 VBoolean (org.diirt.vtype.VBoolean)2 VDoubleArray (org.diirt.vtype.VDoubleArray)2