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);
}
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);
}
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;
}
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();
}
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);
}
Aggregations