Search in sources :

Example 6 with VNumber

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

the class ElementAtStringFormulaFunction method calculate.

@Override
public Object calculate(List<Object> args) {
    if (NullUtils.containsNull(args)) {
        return null;
    }
    VStringArray stringArray = (VStringArray) args.get(0);
    VNumber index = (VNumber) args.get(1);
    int i = index.getValue().intValue();
    return newVString(stringArray.getData().get(i), stringArray, stringArray);
}
Also used : VNumber(org.diirt.vtype.VNumber) VStringArray(org.diirt.vtype.VStringArray)

Example 7 with VNumber

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

the class RescaleArrayFormulaFunction method calculate.

@Override
public Object calculate(final List<Object> args) {
    if (NullUtils.containsNull(args)) {
        return null;
    }
    VNumberArray arg1 = (VNumberArray) args.get(0);
    VNumber arg2 = (VNumber) args.get(1);
    VNumber arg3 = (VNumber) args.get(2);
    return newVNumberArray(ListMath.rescale(arg1.getData(), arg2.getValue().doubleValue(), arg3.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 8 with VNumber

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

the class EnumFromVNumberFunction method calculate.

@Override
public Object calculate(List<Object> args) {
    if (NullUtils.containsNull(args)) {
        return null;
    }
    VNumber value = (VNumber) args.get(0);
    VNumberArray intervals = (VNumberArray) args.get(1);
    VStringArray labels = (VStringArray) args.get(2);
    int index = 0;
    while (index < intervals.getData().size() && value.getValue().doubleValue() >= intervals.getData().getDouble(index)) {
        index++;
    }
    return newVEnum(index, labels.getData(), value, latestValidTimeOrNowOf(args));
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) VNumber(org.diirt.vtype.VNumber) VStringArray(org.diirt.vtype.VStringArray)

Example 9 with VNumber

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

the class VTableFactory method valueNumberTable.

private static VTable valueNumberTable(List<String> names, List<? extends VType> values) {
    double[] data = new double[values.size()];
    List<String> severity = new ArrayList<>();
    List<String> status = new ArrayList<>();
    for (int i = 0; i < values.size(); i++) {
        VNumber vNumber = (VNumber) values.get(i);
        data[i] = vNumber.getValue().doubleValue();
        severity.add(vNumber.getAlarmSeverity().name());
        status.add(vNumber.getAlarmName());
    }
    if (names == null) {
        return newVTable(column("Value", newVDoubleArray(new ArrayDouble(data), alarmNone(), timeNow(), displayNone())), column("Severity", newVStringArray(severity, alarmNone(), timeNow())), column("Status", newVStringArray(status, alarmNone(), timeNow())));
    } else {
        return newVTable(column("Name", newVStringArray(names, alarmNone(), timeNow())), column("Value", newVDoubleArray(new ArrayDouble(data), alarmNone(), timeNow(), displayNone())), column("Severity", newVStringArray(severity, alarmNone(), timeNow())), column("Status", newVStringArray(status, alarmNone(), timeNow())));
    }
}
Also used : ArrayDouble(org.diirt.util.array.ArrayDouble) ArrayList(java.util.ArrayList) VNumber(org.diirt.vtype.VNumber) VString(org.diirt.vtype.VString)

Example 10 with VNumber

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

the class AbstractVIntNumberVIntNumberToVIntNumberFormulaFunction method calculate.

@Override
public final Object calculate(List<Object> args) {
    if (NullUtils.containsNull(args)) {
        return null;
    }
    Number arg1 = ((VNumber) args.get(0)).getValue();
    Number arg2 = ((VNumber) args.get(1)).getValue();
    if (arg1 instanceof Float || arg2 instanceof Float || arg1 instanceof Double || arg2 instanceof Double) {
        throw new IllegalArgumentException("Operator '" + getName() + "' only works with integers");
    }
    return newVInt(calculate(arg1.intValue(), arg2.intValue()), highestSeverityOf(args, false), latestValidTimeOrNowOf(args), displayNone());
}
Also used : VNumber(org.diirt.vtype.VNumber) 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