use of com.ibm.streams.operator.OutputTuple in project streamsx.health by IBMStreams.
the class QRSDetector method process.
/**
* Process an incoming tuple that arrived on the specified port.
* <P>
* Copy the incoming tuple to a new output tuple and submit to the output
* port.
* </P>
*
* @param inputStream
* Port the tuple is arriving on.
* @param tuple
* Object representing the incoming tuple.
* @throws Exception
* Operator failure, will cause the enclosing PE to terminate.
*/
@Override
public final void process(StreamingInput<Tuple> inputStream, Tuple tuple) throws Exception {
int sample = getInputDataAttr().getValue(tuple);
double timestamp = getInputTimestampAttr().getValue(tuple);
timeBuffer.add(timestamp);
BeatDetectAndClassifyResult result = detector.BeatDetectAndClassify(sample);
logger.trace("tuple=" + tuple.toString());
logger.trace("result=" + result);
if (!isOutputDetectionOnly() || (isOutputDetectionOnly() && result.samplesSinceRWaveIfSuccess != 0)) {
StreamingOutput<OutputTuple> outStream = getOutput(0);
OutputTuple outTuple = outStream.newTuple();
outTuple.assign(tuple);
Double qrsTimestamp = Double.NaN;
int qrsPosition = -1;
Double rrInterval = Double.NaN;
Double rrMinusOneInterval = Double.NaN;
if (result.samplesSinceRWaveIfSuccess != 0) {
// calculate timestamp for detected QRS
qrsPosition = result.samplesSinceRWaveIfSuccess;
if (qrsPosition <= timeBuffer.size()) {
qrsTimestamp = calculateTimestampFromQrsPosition(qrsPosition);
} else {
logger.error("Detected position larger than available historical data points: qrsPosition=" + qrsPosition);
}
// calculate RR interval
if (qrsTimestamp != Double.NaN) {
if (previousQrsTimestamp != Double.NaN) {
rrMinusOneInterval = previousRRInterval;
rrInterval = calculateRRInterval(qrsTimestamp);
previousRRInterval = rrInterval;
}
previousQrsTimestamp = qrsTimestamp;
}
}
outTuple.setLong(getQrsTimestampAttrName(), Math.round(qrsTimestamp));
outTuple.setInt(getQrsDelayAttrName(), qrsPosition);
outTuple.setString(getQrsClassificationAttrName(), BeatType.getByCode(result.beatType).toString());
outTuple.setDouble(getRRIntervalAttrName(), rrInterval);
outTuple.setDouble(getPrevRRIntervalAttrName(), rrMinusOneInterval);
outStream.submit(outTuple);
}
}
use of com.ibm.streams.operator.OutputTuple in project streamsx.topology by IBMStreams.
the class HashAdder method process.
@Override
public void process(StreamingInput<Tuple> stream, Tuple tuple) throws Exception {
// Take the hash code, add it to the tuple, and submit.
Object value = mapping.convertFrom(tuple);
OutputTuple ot = output.newTuple();
ot.setObject(0, tuple.getObject(0));
ot.setInt(1, hasher.applyAsInt(value));
output.submit(ot);
}
use of com.ibm.streams.operator.OutputTuple in project streamsx.topology by IBMStreams.
the class HashRemover method process.
/**
* Removes the __spl_hash attribute at the start of a parallel region.
*/
public void process(StreamingInput<Tuple> stream, Tuple tuple) throws Exception {
OutputTuple out_t = output.newTuple();
out_t.setObject(0, tuple.getObject(0));
output.submit(out_t);
}
use of com.ibm.streams.operator.OutputTuple in project streamsx.topology by IBMStreams.
the class FunctionConvertToSPL method process.
@Override
public void process(StreamingInput<Tuple> stream, Tuple tuple) throws Exception {
Object value = inputMapping.convertFrom(tuple);
final BiFunction<Object, OutputTuple, OutputTuple> convert = convertHandler.getLogic();
OutputTuple outTuple = output.newTuple();
synchronized (convert) {
outTuple = convert.apply(value, outTuple);
}
if (outTuple != null)
output.submit(outTuple);
}
use of com.ibm.streams.operator.OutputTuple in project streamsx.topology by IBMStreams.
the class SPLStreamsTest method createSPLFlowFromStream.
@SuppressWarnings("serial")
private static SPLStream createSPLFlowFromStream(final Topology topology, final boolean skipSecond) {
TStream<String> source = topology.strings("325", "457", "9325");
TStream<IntAndString> iands = source.transform(new Function<String, IntAndString>() {
@Override
public IntAndString apply(String v1) {
IntAndString is = new IntAndString();
is.s = v1;
is.n = Integer.valueOf(v1) + 93;
return is;
}
});
StreamSchema schema = Type.Factory.getStreamSchema("tuple<int32 ii, rstring ss>");
SPLStream splStream = SPLStreams.convertStream(iands, new BiFunction<IntAndString, OutputTuple, OutputTuple>() {
@Override
public OutputTuple apply(IntAndString v1, OutputTuple v2) {
if (skipSecond & v1.n == 550)
return null;
v2.setString("ss", v1.s);
v2.setInt("ii", v1.n);
return v2;
}
}, schema);
assertSPLStream(splStream, schema);
return splStream;
}
Aggregations