use of org.diirt.vtype.VNumber in project yamcs-studio by yamcs.
the class AbstractVNumberArrayVNumberToVNumberArrayFormulaFunction method calculate.
@Override
public final Object calculate(List<Object> args) {
if (NullUtils.containsNull(args)) {
return null;
}
VNumberArray arg1 = (VNumberArray) args.get(0);
VNumber arg2 = (VNumber) args.get(1);
return newVNumberArray(calculate(arg1.getData(), arg2.getValue().doubleValue()), highestSeverityOf(args, false), latestValidTimeOrNowOf(args), displayNone());
}
use of org.diirt.vtype.VNumber in project yamcs-studio by yamcs.
the class CaHistogramFormulaFunction method calculateImpl.
Object calculateImpl(final String newName) {
// If the name does not match, disconnect and connect
if (!Objects.equals(newName, previousName)) {
if (currentExpressions != null) {
for (DesiredRateExpression<?> desiredRateExpression : currentExpressions) {
if (desiredRateExpression != null) {
getDirector().disconnectReadExpression(desiredRateExpression);
}
}
}
List<DesiredRateExpression<?>> newExpressions = new ArrayList<>();
if (newName != null) {
newExpressions.addAll(Collections.nCopies(3, (DesiredRateExpression<?>) null));
}
// Connect new expressions
if (newName != null) {
DesiredRateExpression<?> newExpression = channel(newName, Object.class);
getDirector().disconnectReadExpression(newExpression);
newExpressions.set(0, newExpression);
newExpression = channel(newName + ".LLIM", Object.class);
getDirector().disconnectReadExpression(newExpression);
newExpressions.set(1, newExpression);
newExpression = channel(newName + ".ULIM", Object.class);
getDirector().disconnectReadExpression(newExpression);
newExpressions.set(2, newExpression);
}
previousName = newName;
currentExpressions = newExpressions;
}
// No return value
if (newName == null) {
return null;
}
// Extract values
VNumberArray array = (VNumberArray) currentExpressions.get(0).getFunction().readValue();
VNumber lowerRange = (VNumber) currentExpressions.get(1).getFunction().readValue();
VNumber upperRange = (VNumber) currentExpressions.get(2).getFunction().readValue();
if (array == null || lowerRange == null || upperRange == null) {
return null;
}
return ValueFactory.newVNumberArray(array.getData(), array.getSizes(), Arrays.asList(ValueFactory.newDisplay(VTableFactory.range(lowerRange.getValue().doubleValue(), upperRange.getValue().doubleValue()).createListNumber(array.getSizes().getInt(0) + 1), "")), array, array, array);
}
use of org.diirt.vtype.VNumber 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.VNumber in project yamcs-studio by yamcs.
the class IntegrateFormulaFunction method calculate.
@Override
public Object calculate(final List<Object> args) {
VNumber value = (VNumber) args.get(0);
if (value != null && value.getValue() != null) {
values.add(value);
}
if (values.isEmpty()) {
return null;
}
if (previousTime == null) {
Instant now = Instant.now();
if (now.compareTo(values.get(0).getTimestamp()) <= 0) {
previousTime = now;
} else {
previousTime = values.get(0).getTimestamp();
}
}
Instant currentTime = Instant.now();
integratedValue += integrate(previousTime, currentTime, values);
previousTime = currentTime;
while (values.size() > 1 && values.get(1).getTimestamp().compareTo(currentTime) <= 0) {
values.remove(0);
}
return ValueFactory.newVDouble(integratedValue);
}
use of org.diirt.vtype.VNumber in project yamcs-studio by yamcs.
the class RangeFormulaFunction method calculate.
@Override
public Object calculate(final List<Object> args) {
VNumber minValue = (VNumber) args.get(0);
VNumber maxValue = (VNumber) args.get(1);
if (minValue == null || maxValue == null) {
return null;
}
return VTableFactory.range(minValue.getValue().doubleValue(), maxValue.getValue().doubleValue());
}
Aggregations