Search in sources :

Example 21 with VNumberArray

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

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

the class HistogramOfFormulaFunction method calculate.

@Override
public Object calculate(List<Object> args) {
    VNumberArray numberArray = (VNumberArray) args.get(0);
    if (numberArray == null) {
        return null;
    }
    // If no change, return previous
    if (previousValue == numberArray) {
        return previousResult;
    }
    Statistics stats = StatisticsUtil.statisticsOf(numberArray.getData());
    int nBins = 100;
    Range aggregatedRange = Ranges.aggregateRange(stats.getRange(), previousXRange);
    Range xRange;
    if (Ranges.overlap(aggregatedRange, stats.getRange()) >= 0.75) {
        xRange = aggregatedRange;
    } else {
        xRange = stats.getRange();
    }
    IteratorNumber newValues = numberArray.getData().iterator();
    double minValueRange = xRange.getMinimum();
    double maxValueRange = xRange.getMaximum();
    ListNumber xBoundaries = ListNumbers.linearListFromRange(minValueRange, maxValueRange, nBins + 1);
    String unit = numberArray.getUnits();
    int[] binData = new int[nBins];
    double maxCount = 0;
    while (newValues.hasNext()) {
        double value = newValues.nextDouble();
        // Check value in range
        if (xRange.contains(value)) {
            int bin = (int) Math.floor(xRange.normalize(value) * nBins);
            if (bin == nBins) {
                bin--;
            }
            binData[bin]++;
            if (binData[bin] > maxCount) {
                maxCount = binData[bin];
            }
        }
    }
    if (previousMaxCount > maxCount && previousMaxCount < maxCount * 2.0) {
        maxCount = previousMaxCount;
    }
    previousMaxCount = maxCount;
    previousXRange = xRange;
    previousValue = numberArray;
    previousResult = newVNumberArray(new ArrayInt(binData), new ArrayInt(nBins), Arrays.asList(newDisplay(xBoundaries, unit)), numberArray, numberArray, newDisplay(0.0, 0.0, 0.0, "count", NumberFormats.format(0), maxCount, maxCount, maxCount, Double.NaN, Double.NaN));
    return previousResult;
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) ListNumber(org.diirt.util.array.ListNumber) Range(org.diirt.util.Range) ArrayInt(org.diirt.util.array.ArrayInt) Statistics(org.diirt.util.Statistics) IteratorNumber(org.diirt.util.array.IteratorNumber)

Example 23 with VNumberArray

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

the class NdArrayFormulaFunction method calculate.

@Override
public Object calculate(final List<Object> args) {
    if (NullUtils.containsNull(args)) {
        return null;
    }
    VNumberArray data = (VNumberArray) args.get(0);
    ArrayDimensionDisplay[] displays = new ArrayDimensionDisplay[args.size() - 1];
    for (int i = 0; i < displays.length; i++) {
        displays[i] = (ArrayDimensionDisplay) args.get(i + 1);
    }
    return ValueFactory.ndArray(data, displays);
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) ArrayDimensionDisplay(org.diirt.vtype.ArrayDimensionDisplay)

Example 24 with VNumberArray

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

the class ColumnFromVNumberArrayFunction method calculate.

@Override
public Object calculate(final List<Object> args) {
    VString name = (VString) args.get(0);
    VNumberArray data = (VNumberArray) args.get(1);
    if (name == null || data == null) {
        return null;
    }
    return VTableFactory.column(name.getValue(), data);
}
Also used : VNumberArray(org.diirt.vtype.VNumberArray) VString(org.diirt.vtype.VString)

Example 25 with VNumberArray

use of org.diirt.vtype.VNumberArray in project org.csstudio.display.builder by kasemir.

the class ValueUtil method getStringArray.

/**
 * Get string array from pv.
 *  @param value Value of a PV
 *  @return String array.
 *          For string array, it's the actual strings.
 *          For numeric arrays, the numbers are formatted as strings.
 *          For enum array, the labels are returned.
 *          For scalar PVs, an array with a single string is returned.
 */
public static final String[] getStringArray(final VType value) {
    if (value instanceof VStringArray) {
        final List<String> list = ((VStringArray) value).getData();
        return list.toArray(new String[list.size()]);
    } else if (value instanceof VDoubleArray) {
        final ListNumber list = ((VNumberArray) value).getData();
        final String[] text = new String[list.size()];
        for (int i = 0; i < text.length; ++i) text[i] = Double.toString(list.getDouble(i));
        return text;
    } else if (value instanceof VNumberArray) {
        final ListNumber list = ((VNumberArray) value).getData();
        final String[] text = new String[list.size()];
        for (int i = 0; i < text.length; ++i) text[i] = Long.toString(list.getLong(i));
        return text;
    } else if (value instanceof VEnumArray) {
        final List<String> labels = ((VEnumArray) value).getLabels();
        final ListInt list = ((VEnumArray) value).getIndexes();
        final String[] text = new String[list.size()];
        for (int i = 0; i < text.length; ++i) {
            final int index = list.getInt(i);
            if (index >= 0 && index <= labels.size())
                text[i] = labels.get(index);
            else
                text[i] = "<" + index + ">";
        }
        return text;
    }
    return new String[] { getString(value) };
}
Also used : VDoubleArray(org.diirt.vtype.VDoubleArray) VNumberArray(org.diirt.vtype.VNumberArray) VEnumArray(org.diirt.vtype.VEnumArray) ListNumber(org.diirt.util.array.ListNumber) ListInt(org.diirt.util.array.ListInt) ArrayList(java.util.ArrayList) List(java.util.List) VStringArray(org.diirt.vtype.VStringArray)

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