Search in sources :

Example 1 with VString

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

the class VTableFactory method union.

public static VTable union(VString extraColumnName, final VStringArray extraColumnData, final VTable... tables) {
    // Prune nulls
    final List<String> extraColumnDataPruned = new ArrayList<>();
    final List<VTable> tablesPruned = new ArrayList<>();
    for (int i = 0; i < tables.length; i++) {
        VTable table = tables[i];
        if (table != null) {
            extraColumnDataPruned.add(extraColumnData.getData().get(i));
            tablesPruned.add(table);
        }
    }
    if (tablesPruned.isEmpty()) {
        return null;
    }
    List<String> columnNames = new ArrayList<>();
    List<Class<?>> columnTypes = new ArrayList<>();
    List<Map<String, VColumn>> tableColumns = new ArrayList<>();
    if (extraColumnName != null) {
        columnNames.add(extraColumnName.getValue());
        columnTypes.add(String.class);
    }
    int[] tableOffsets = new int[tablesPruned.size()];
    int currentOffset = 0;
    for (int k = 0; k < tablesPruned.size(); k++) {
        VTable table = tablesPruned.get(k);
        if (table == null) {
            continue;
        }
        tableOffsets[k] = currentOffset;
        currentOffset += table.getRowCount();
        tableColumns.add(VColumn.columnMap(table));
        for (int i = 0; i < table.getColumnCount(); i++) {
            String name = table.getColumnName(i);
            if (!columnNames.contains(name)) {
                columnNames.add(name);
                columnTypes.add(table.getColumnType(i));
            }
        }
    }
    final int rowCount = currentOffset;
    final ListInt offsets = new ArrayInt(tableOffsets);
    List<Object> columnData = new ArrayList<>();
    if (extraColumnName != null) {
        columnData.add(new AbstractList<String>() {

            @Override
            public String get(int index) {
                int nTable = ListNumbers.binarySearchValueOrLower(offsets, index);
                return extraColumnDataPruned.get(nTable);
            }

            @Override
            public int size() {
                return rowCount;
            }
        });
    }
    for (int i = 1; i < columnNames.size(); i++) {
        String columnName = columnNames.get(i);
        List<VColumn> columns = new ArrayList<>();
        for (int j = 0; j < tableColumns.size(); j++) {
            columns.add(tableColumns.get(j).get(columnName));
        }
        columnData.add(VColumn.combineData(columnTypes.get(i), rowCount, offsets, columns));
    }
    return ValueFactory.newVTable(columnTypes, columnNames, columnData);
}
Also used : ListInt(org.diirt.util.array.ListInt) ArrayList(java.util.ArrayList) VString(org.diirt.vtype.VString) VTable(org.diirt.vtype.VTable) ArrayInt(org.diirt.util.array.ArrayInt) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with VString

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

the class CaHistogramFormulaFunction method calculate.

@Override
public Object calculate(final List<Object> args) {
    // Retrieve the new name
    VString value = (VString) args.get(0);
    String newName = null;
    if (value != null) {
        newName = value.getValue();
    }
    return calculateImpl(newName);
}
Also used : VString(org.diirt.vtype.VString) VString(org.diirt.vtype.VString)

Example 3 with VString

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

the class Histogram2DOfFormulaFunction method calculate.

@Override
public Object calculate(List<Object> args) {
    if (NullUtils.containsNull(args)) {
        return null;
    }
    VTable table = (VTable) args.get(0);
    VString yColumnName = (VString) args.get(1);
    VString xColumnName = (VString) args.get(2);
    ListNumber yData = ValueUtil.numericColumnOf(table, yColumnName.getValue());
    ListNumber xData = ValueUtil.numericColumnOf(table, xColumnName.getValue());
    int nPoints = Math.min(yData.size(), xData.size());
    Statistics xStats = StatisticsUtil.statisticsOf(xData);
    Statistics yStats = StatisticsUtil.statisticsOf(yData);
    int nXBins = 20;
    int nYBins = 20;
    Range aggregatedXRange = Ranges.aggregateRange(xStats.getRange(), previousXRange);
    Range aggregatedYRange = Ranges.aggregateRange(yStats.getRange(), previousYRange);
    Range xRange;
    Range yRange;
    if (Ranges.overlap(aggregatedXRange, xStats.getRange()) >= 0.90) {
        xRange = aggregatedXRange;
    } else {
        xRange = xStats.getRange();
    }
    if (Ranges.overlap(aggregatedYRange, yStats.getRange()) >= 0.90) {
        yRange = aggregatedYRange;
    } else {
        yRange = yStats.getRange();
    }
    double minXValueRange = xRange.getMinimum();
    double maxXValueRange = xRange.getMaximum();
    double minYValueRange = yRange.getMinimum();
    double maxYValueRange = yRange.getMaximum();
    ListNumber xBoundaries = ListNumbers.linearListFromRange(minXValueRange, maxXValueRange, nXBins + 1);
    ListNumber yBoundaries = ListNumbers.linearListFromRange(minYValueRange, maxYValueRange, nYBins + 1);
    int[] binData = new int[nXBins * nYBins];
    double maxCount = 0;
    for (int i = 0; i < nPoints; i++) {
        double xValue = xData.getDouble(i);
        double yValue = yData.getDouble(i);
        // Check value in range
        if (xRange.contains(xValue)) {
            if (yRange.contains(yValue)) {
                int xBin = (int) Math.floor(xRange.normalize(xValue) * nXBins);
                int yBin = (int) Math.floor(yRange.normalize(yValue) * nYBins);
                if (xBin == nXBins) {
                    xBin--;
                }
                if (yBin == nYBins) {
                    yBin--;
                }
                int binIndex = yBin * nXBins + xBin;
                binData[binIndex]++;
                if (binData[binIndex] > maxCount) {
                    maxCount = binData[binIndex];
                }
            }
        }
    }
    // time based "forget"
    if (previousMaxCount > maxCount && (previousMaxCount < maxCount * 2.0 || maxCount < 9)) {
        maxCount = previousMaxCount;
    }
    previousMaxCount = maxCount;
    previousXRange = xRange;
    previousXData = xData;
    previousYData = yData;
    previousResult = newVNumberArray(new ArrayInt(binData), new ArrayInt(nYBins, nXBins), Arrays.asList(newDisplay(yBoundaries, ""), newDisplay(xBoundaries, "")), alarmNone(), timeNow(), newDisplay(0.0, 0.0, 0.0, "count", NumberFormats.format(0), maxCount, maxCount, maxCount, Double.NaN, Double.NaN));
    return previousResult;
}
Also used : ListNumber(org.diirt.util.array.ListNumber) VString(org.diirt.vtype.VString) VTable(org.diirt.vtype.VTable) Range(org.diirt.util.Range) ArrayInt(org.diirt.util.array.ArrayInt) Statistics(org.diirt.util.Statistics)

Example 4 with VString

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

the class ChannelFormulaFunction method calculate.

@Override
public Object calculate(final List<Object> args) {
    // Retrieve the new name
    VString value = (VString) args.get(0);
    String newName = null;
    if (value != null) {
        newName = value.getValue();
    }
    // If the name does not match, disconnect and connect
    if (!Objects.equals(newName, previousName)) {
        // Disconnect previous
        if (currentExpression != null) {
            getDirector().disconnectReadExpression(currentExpression);
            currentExpression = null;
        }
        // Connect new
        if (newName != null) {
            currentExpression = channel(newName, Object.class);
            getDirector().connectReadExpression(currentExpression);
        }
        previousName = newName;
    }
    // Return value
    if (newName == null) {
        return null;
    }
    return currentExpression.getFunction().readValue();
}
Also used : VString(org.diirt.vtype.VString) VString(org.diirt.vtype.VString)

Example 5 with VString

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

the class ColumnFromListNumberGeneratorFunction method calculate.

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

Aggregations

VString (org.diirt.vtype.VString)20 VTable (org.diirt.vtype.VTable)9 VNumberArray (org.diirt.vtype.VNumberArray)5 ListInt (org.diirt.util.array.ListInt)4 ListNumber (org.diirt.util.array.ListNumber)4 VNumber (org.diirt.vtype.VNumber)4 VStringArray (org.diirt.vtype.VStringArray)4 VType (org.diirt.vtype.VType)4 VEnum (org.diirt.vtype.VEnum)3 VEnumArray (org.diirt.vtype.VEnumArray)3 ArrayList (java.util.ArrayList)2 Background (javafx.scene.layout.Background)2 BackgroundFill (javafx.scene.layout.BackgroundFill)2 ArrayInt (org.diirt.util.array.ArrayInt)2 VBoolean (org.diirt.vtype.VBoolean)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Rotate (javafx.scene.transform.Rotate)1 Translate (javafx.scene.transform.Translate)1