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